sc working again
This commit is contained in:
parent
a5b3615a7a
commit
a7b652de72
11 changed files with 29 additions and 25 deletions
|
|
@ -116,7 +116,7 @@ def mock_entry_kwargs(
|
|||
|
||||
@pytest.fixture
|
||||
def mock_entry(mock_entry_kwargs):
|
||||
return Entry(**mock_entry_kwargs)
|
||||
return Entry(entry_dict=mock_entry_kwargs)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def mock_soundcloud_track_kwargs(mock_entry_kwargs, url):
|
|||
|
||||
@pytest.fixture
|
||||
def mock_soundcloud_track(mock_soundcloud_track_kwargs):
|
||||
return SoundcloudTrack(**mock_soundcloud_track_kwargs)
|
||||
return SoundcloudTrack(entry_dict=mock_soundcloud_track_kwargs)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from abc import ABC
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
|
||||
from yt_dlp.utils import sanitize_filename
|
||||
|
|
@ -12,7 +10,6 @@ from ytdl_subscribe.validators.string_formatter_validators import OverridesStrin
|
|||
from ytdl_subscribe.validators.string_formatter_validators import StringFormatterValidator
|
||||
from ytdl_subscribe.validators.validators import BoolValidator
|
||||
from ytdl_subscribe.validators.validators import LiteralDictValidator
|
||||
from ytdl_subscribe.validators.validators import StringValidator
|
||||
|
||||
|
||||
class YTDLOptions(LiteralDictValidator):
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ class SoundcloudDownloader(
|
|||
|
||||
info = self.extract_info(url=artist_albums_url)
|
||||
albums = [
|
||||
SoundcloudAlbum(working_direcotry=self.working_directory, **e) for e in info["entries"]
|
||||
SoundcloudAlbum(entry_dict=e, working_directory=self.working_directory)
|
||||
for e in info["entries"]
|
||||
]
|
||||
|
||||
return [album for album in albums if album.track_count > 0]
|
||||
|
|
@ -79,7 +80,7 @@ class SoundcloudDownloader(
|
|||
|
||||
info = self.extract_info(url=artist_tracks_url)
|
||||
return [
|
||||
SoundcloudTrack(working_directory=self.working_directory, kwargs=e)
|
||||
SoundcloudTrack(entry_dict=e, working_directory=self.working_directory)
|
||||
for e in info["entries"]
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -80,16 +80,22 @@ class YoutubeDownloader(
|
|||
|
||||
# Load the entries from info.json, ignore the playlist entry
|
||||
for file_name in os.listdir(self.working_directory):
|
||||
if file_name.endswith(".info.json") and not file_name.startswith(ignore_prefix):
|
||||
with open(Path(self.working_directory) / file_name, "r", encoding="utf-8") as file:
|
||||
entries.append(YoutubeVideo(**json.load(file)))
|
||||
if file_name.startswith(ignore_prefix) or not file_name.endswith(".info.json"):
|
||||
continue
|
||||
|
||||
with open(Path(self.working_directory) / file_name, "r", encoding="utf-8") as file:
|
||||
entries.append(
|
||||
YoutubeVideo(
|
||||
entry_dict=json.load(file), working_directory=self.working_directory
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
|
||||
def download_video(self, video_id: str) -> YoutubeVideo:
|
||||
"""Download a single Youtube video"""
|
||||
entry = self.extract_info(url=self.video_url(video_id))
|
||||
return YoutubeVideo(**entry)
|
||||
return YoutubeVideo(entry_dict=entry, working_directory=self.working_directory)
|
||||
|
||||
def download_playlist(self, playlist_id: str) -> List[YoutubeVideo]:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -24,19 +24,19 @@ class BaseEntry(ABC):
|
|||
Abstract entry object to represent anything download from ytdl (playlist metadata, media, etc).
|
||||
"""
|
||||
|
||||
def __init__(self, working_directory: Optional[str] = None, **kwargs):
|
||||
def __init__(self, entry_dict: Dict, working_directory: Optional[str] = None):
|
||||
"""
|
||||
Initialize the entry using ytdl metadata
|
||||
|
||||
Parameters
|
||||
----------
|
||||
entry_dict
|
||||
Entry metadata
|
||||
working_directory
|
||||
Optional. Directory that the entry is downloaded to
|
||||
kwargs
|
||||
Entry metadata
|
||||
"""
|
||||
self._working_directory = working_directory
|
||||
self._kwargs = kwargs
|
||||
self._kwargs = entry_dict
|
||||
|
||||
def kwargs_contains(self, key: str) -> bool:
|
||||
"""Returns whether internal kwargs contains the specified key"""
|
||||
|
|
|
|||
|
|
@ -69,16 +69,16 @@ class SoundcloudAlbumTrack(SoundcloudTrack):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
entry_dict: Dict,
|
||||
working_directory: str,
|
||||
album: str,
|
||||
album_year: int,
|
||||
playlist_metadata: PlaylistMetadata,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Initialize the album track using album metadata and ytdl metadata for the specific track.
|
||||
"""
|
||||
super().__init__(working_directory=working_directory, **kwargs)
|
||||
super().__init__(entry_dict=entry_dict, working_directory=working_directory)
|
||||
self._album = album
|
||||
self._album_year = album_year
|
||||
self._playlist_metadata = playlist_metadata
|
||||
|
|
@ -111,11 +111,11 @@ class SoundcloudAlbumTrack(SoundcloudTrack):
|
|||
playlist_metadata: PlaylistMetadata,
|
||||
) -> "SoundcloudAlbumTrack":
|
||||
return SoundcloudAlbumTrack(
|
||||
entry_dict=soundcloud_track._kwargs, # pylint: disable=protected-access
|
||||
working_directory=soundcloud_track.working_directory,
|
||||
album=album,
|
||||
album_year=album_year,
|
||||
playlist_metadata=playlist_metadata,
|
||||
**soundcloud_track._kwargs, # pylint: disable=protected-access
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ class SoundcloudAlbum(Entry):
|
|||
data needed from the tracks before representing it as an album track.
|
||||
"""
|
||||
return [
|
||||
SoundcloudTrack(working_directory=self._working_directory, **entry)
|
||||
SoundcloudTrack(entry_dict=entry, working_directory=self._working_directory)
|
||||
for entry in self.kwargs("entries")
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
|
||||
from PIL.Image import Image
|
||||
from PIL.Image import open as pil_open
|
||||
|
||||
from ytdl_subscribe.entries.entry import Entry
|
||||
from ytdl_subscribe.plugins.plugin import Plugin
|
||||
|
|
@ -33,7 +34,7 @@ class ConvertThumbnailPlugin(Plugin[ConvertThumbnailOptions]):
|
|||
if not os.path.isfile(entry.download_thumbnail_path):
|
||||
raise ValueError("Thumbnail not found")
|
||||
|
||||
image = Image.open(entry.download_thumbnail_path).convert("RGB")
|
||||
image: Image = pil_open(entry.download_thumbnail_path).convert("RGB")
|
||||
|
||||
# Pillow likes the formal 'jpeg' name and not 'jpg'
|
||||
thumbnail_format = self.plugin_options.convert_to.value
|
||||
|
|
|
|||
|
|
@ -127,9 +127,10 @@ class Subscription:
|
|||
def _prepare_working_directory(self):
|
||||
os.makedirs(self.working_directory, exist_ok=True)
|
||||
|
||||
yield
|
||||
|
||||
shutil.rmtree(self.working_directory)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
shutil.rmtree(self.working_directory)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _maintain_archive_file(self):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from typing import List
|
||||
from typing import Set
|
||||
|
||||
from ytdl_subscribe.utils.exceptions import ValidationException
|
||||
from ytdl_subscribe.validators.validators import DictValidator
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from yt_dlp.utils import datetime_from_str
|
||||
|
||||
from ytdl_subscribe.utils.exceptions import ValidationException
|
||||
from ytdl_subscribe.validators.validators import Validator
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue