-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: mediainfo module #16
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from animepipeline.mediainfo.mediainfomini import gen_file_name, FileNameInfo, rename_file, get_media_info # noqa | ||
from animepipeline.mediainfo.mediainfo import get_media_info # noqa | ||
from animepipeline.mediainfo.name import gen_file_name, rename_file # noqa | ||
from animepipeline.mediainfo.type import FileNameInfo, MediaInfo # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
from loguru import logger | ||
|
||
from animepipeline.mediainfo.mediainfo import get_media_info | ||
from animepipeline.mediainfo.type import FileNameInfo | ||
|
||
|
||
def gen_file_name(anime_info: FileNameInfo) -> str: | ||
""" | ||
Auto generate the file name, based on the media info of the file | ||
|
||
anime_info: FileNameInfo (path: xx.mkv, episode: 1, name: Fate/Kaleid Liner Prisma Illya, uploader: TensoRaws, type: WEBRip) | ||
|
||
-> [TensoRaws] Fate/Kaleid Liner Prisma Illya [01] [WEBRip 1080p HEVC-10bit FLAC].mkv | ||
|
||
:param anime_info: FileNameInfo | ||
:return: | ||
""" | ||
media_info = get_media_info(anime_info.path) | ||
resolution_heigh = str(media_info.resolution[1]) + "p" | ||
bit_depth = str(media_info.bit_depth) + "bit" | ||
|
||
video_format = media_info.format | ||
|
||
audio_format_list = [audio[2] for audio in media_info.audios] | ||
audio_format = "FLAC" if "FLAC" in audio_format_list else audio_format_list[0] | ||
|
||
file_format = Path(anime_info.path).suffix | ||
|
||
return f"[{anime_info.uploader}] {anime_info.name} [{str(anime_info.episode).zfill(2)}] [{anime_info.type} {resolution_heigh} {video_format}-{bit_depth} {audio_format}]{file_format}" | ||
|
||
|
||
def rename_file(anime_info: FileNameInfo) -> Path: | ||
""" | ||
Rename the file name, based on the media info of the file | ||
|
||
:param anime_info: FileNameInfo | ||
:return: | ||
""" | ||
anime_path = Path(anime_info.path) | ||
|
||
gen_name = gen_file_name(anime_info) | ||
gen_path = anime_path.parent / gen_name | ||
|
||
if gen_path.exists(): | ||
gen_path.unlink() | ||
logger.warning(f"Encode File already exists, remove it: {gen_path}") | ||
|
||
anime_path.rename(gen_path) | ||
|
||
return gen_path |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Consider safer handling of existing files instead of automatic deletion
Automatically deleting existing files could lead to data loss. Consider either adding a numeric suffix to create a unique filename or raising an exception to let the caller decide how to handle conflicts.