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