From 3a37138ce68f5cd5cb663ae3d49021548c1b6266 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Tue, 27 Sep 2022 18:40:40 -0700 Subject: [PATCH] merge --- src/ytdl_sub/entries/entry.py | 12 ++++ src/ytdl_sub/entries/soundcloud.py | 11 --- .../entries/variables/entry_variables.py | 22 +++++- src/ytdl_sub/entries/variables/kwargs.py | 1 + .../entries/variables/soundcloud_variables.py | 69 ------------------- .../entries/variables/youtube_variables.py | 29 -------- src/ytdl_sub/entries/youtube.py | 23 ------- 7 files changed, 34 insertions(+), 133 deletions(-) delete mode 100644 src/ytdl_sub/entries/soundcloud.py delete mode 100644 src/ytdl_sub/entries/variables/soundcloud_variables.py delete mode 100644 src/ytdl_sub/entries/variables/youtube_variables.py delete mode 100644 src/ytdl_sub/entries/youtube.py diff --git a/src/ytdl_sub/entries/entry.py b/src/ytdl_sub/entries/entry.py index 12d44367..705bf299 100644 --- a/src/ytdl_sub/entries/entry.py +++ b/src/ytdl_sub/entries/entry.py @@ -15,6 +15,18 @@ class Entry(EntryVariables, BaseEntry): Entry object to represent a single media object returned from yt-dlp. """ + @property + def ext(self) -> str: + """ + With ffmpeg installed, yt-dlp will sometimes merge the file into an mkv file. + This is not reflected in the entry. See if the mkv file exists and return "mkv" if so, + otherwise, return the original extension. + """ + mkv_file_path = str(Path(self.working_directory()) / f"{self.uid}.mkv") + if os.path.isfile(mkv_file_path): + return "mkv" + return super().ext + def get_download_file_name(self) -> str: """ Returns diff --git a/src/ytdl_sub/entries/soundcloud.py b/src/ytdl_sub/entries/soundcloud.py deleted file mode 100644 index 1ab9f74b..00000000 --- a/src/ytdl_sub/entries/soundcloud.py +++ /dev/null @@ -1,11 +0,0 @@ -from ytdl_sub.entries.entry import Entry -from ytdl_sub.entries.variables.soundcloud_variables import SoundcloudVariables - -# TODO: Delete since not used - - -class SoundcloudTrack(SoundcloudVariables, Entry): - """ - Entry object to represent a Soundcloud track yt-dlp that is a single, which implies - it does not belong to an album. - """ diff --git a/src/ytdl_sub/entries/variables/entry_variables.py b/src/ytdl_sub/entries/variables/entry_variables.py index 683850cb..6c5c0720 100644 --- a/src/ytdl_sub/entries/variables/entry_variables.py +++ b/src/ytdl_sub/entries/variables/entry_variables.py @@ -4,7 +4,7 @@ from yt_dlp.utils import sanitize_filename from ytdl_sub.entries.base_entry import BaseEntry from ytdl_sub.entries.base_entry import BaseEntryVariables -from ytdl_sub.entries.variables.kwargs import EXT +from ytdl_sub.entries.variables.kwargs import EXT, CHANNEL from ytdl_sub.entries.variables.kwargs import PLAYLIST_COUNT from ytdl_sub.entries.variables.kwargs import PLAYLIST_DESCRIPTION from ytdl_sub.entries.variables.kwargs import PLAYLIST_INDEX @@ -304,6 +304,26 @@ class EntryVariables(BaseEntryVariables): """ return self.kwargs_get(SOURCE_UPLOADER_URL, self.source_webpage_url) + @property + def channel(self: Self) -> str: + """ + Returns + ------- + str + The channel name if it exists, otherwise returns the uploader. + """ + return self.kwargs_get(CHANNEL, self.uploader) + + @property + def channel_sanitized(self: Self) -> str: + """ + Returns + ------- + str + The channel name, sanitized. + """ + return sanitize_filename(self.channel) + @property def ext(self: Self) -> str: """ diff --git a/src/ytdl_sub/entries/variables/kwargs.py b/src/ytdl_sub/entries/variables/kwargs.py index 91c6edc6..d222606f 100644 --- a/src/ytdl_sub/entries/variables/kwargs.py +++ b/src/ytdl_sub/entries/variables/kwargs.py @@ -41,6 +41,7 @@ PLAYLIST_UPLOADER_ID = _("playlist_uploader_id") PLAYLIST_UPLOADER_URL = _("playlist_uploader_url") UID = _("id") +CHANNEL = _("channel") EXT = _("ext") TITLE = _("title") DESCRIPTION = _("description") diff --git a/src/ytdl_sub/entries/variables/soundcloud_variables.py b/src/ytdl_sub/entries/variables/soundcloud_variables.py deleted file mode 100644 index 349fafb5..00000000 --- a/src/ytdl_sub/entries/variables/soundcloud_variables.py +++ /dev/null @@ -1,69 +0,0 @@ -from yt_dlp.utils import sanitize_filename - -from ytdl_sub.entries.variables.entry_variables import EntryVariables - -# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion -# pylint: disable=no-member - - -class SoundcloudVariables(EntryVariables): - @property - def track_number(self) -> int: - """ - Returns - ------- - int - The entry's track number within an album. For singles, it will always be 1. - """ - return 1 - - @property - def track_number_padded(self) -> str: - """ - Returns - ------- - str - The entry's track number, padded two digits. - """ - return f"{self.track_number:02d}" - - @property - def track_count(self) -> int: - """ - Returns - ------- - int - The total tracks in album. For singles, it will always be 1. - """ - return 1 - - @property - def album(self) -> str: - """ - Returns - ------- - str - The entry's album name. For singles, it will be the same as the title. - """ - return self.title - - @property - def album_sanitized(self) -> str: - """ - Returns - ------- - str - The entry's sanitized album name, which is safe to use for Unix and Windows file names. - """ - return sanitize_filename(self.album) - - @property - def album_year(self) -> int: - """ - Returns - ------- - int - The entry's album year, which is determined by the latest year amongst all tracks in the - album. - """ - return self.upload_year diff --git a/src/ytdl_sub/entries/variables/youtube_variables.py b/src/ytdl_sub/entries/variables/youtube_variables.py deleted file mode 100644 index d2753b28..00000000 --- a/src/ytdl_sub/entries/variables/youtube_variables.py +++ /dev/null @@ -1,29 +0,0 @@ -from yt_dlp.utils import sanitize_filename - -from ytdl_sub.entries.base_entry import BaseEntry -from ytdl_sub.entries.variables.entry_variables import EntryVariables - -# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion -# pylint: disable=no-member - - -class YoutubeVideoVariables(EntryVariables): - @property - def channel(self: BaseEntry) -> str: - """ - Returns - ------- - str - The channel name. - """ - return self.kwargs("channel") - - @property - def channel_sanitized(self) -> str: - """ - Returns - ------- - str - The channel name, sanitized. - """ - return sanitize_filename(self.channel) diff --git a/src/ytdl_sub/entries/youtube.py b/src/ytdl_sub/entries/youtube.py deleted file mode 100644 index 15094156..00000000 --- a/src/ytdl_sub/entries/youtube.py +++ /dev/null @@ -1,23 +0,0 @@ -import os.path -from pathlib import Path - -from ytdl_sub.entries.entry import Entry -from ytdl_sub.entries.variables.youtube_variables import YoutubeVideoVariables - - -class YoutubeVideo(YoutubeVideoVariables, Entry): - """ - Entry object to represent a Youtube video. Reserved for shared Youtube entry logic. - """ - - @property - def ext(self) -> str: - """ - With ffmpeg installed, yt-dlp will sometimes merge the file into an mkv file. - This is not reflected in the entry. See if the mkv file exists and return "mkv" if so, - otherwise, return the original extension. - """ - mkv_file_path = str(Path(self.working_directory()) / f"{self.uid}.mkv") - if os.path.isfile(mkv_file_path): - return "mkv" - return super().ext