Only have subscription download the files
This commit is contained in:
parent
fd10d5acfd
commit
6cccb37ab7
3 changed files with 74 additions and 27 deletions
|
|
@ -1,18 +1,39 @@
|
||||||
|
from abc import ABC
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from ytdl_subscribe.downloaders.soundcloud_downloader import SoundcloudDownloader
|
from ytdl_subscribe.downloaders.soundcloud_downloader import SoundcloudDownloader
|
||||||
from ytdl_subscribe.entries.soundcloud import SoundcloudAlbum
|
from ytdl_subscribe.entries.soundcloud import SoundcloudAlbum
|
||||||
from ytdl_subscribe.entries.soundcloud import SoundcloudTrack
|
from ytdl_subscribe.entries.soundcloud import SoundcloudTrack
|
||||||
|
from ytdl_subscribe.subscriptions.subscription import SourceT
|
||||||
from ytdl_subscribe.subscriptions.subscription import Subscription
|
from ytdl_subscribe.subscriptions.subscription import Subscription
|
||||||
|
from ytdl_subscribe.validators.config.config_options.config_options_validator import (
|
||||||
|
ConfigOptionsValidator,
|
||||||
|
)
|
||||||
|
from ytdl_subscribe.validators.config.preset_validator import PresetValidator
|
||||||
from ytdl_subscribe.validators.config.source_options.soundcloud_validators import (
|
from ytdl_subscribe.validators.config.source_options.soundcloud_validators import (
|
||||||
SoundcloudAlbumsAndSinglesSourceValidator,
|
SoundcloudAlbumsAndSinglesSourceValidator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SoundcloudSubscription(Subscription[SourceT], ABC):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
config_options: ConfigOptionsValidator,
|
||||||
|
preset_options: PresetValidator,
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
config_options=config_options,
|
||||||
|
preset_options=preset_options,
|
||||||
|
entry_type=SoundcloudTrack,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SoundcloudAlbumsAndSinglesSubscription(
|
class SoundcloudAlbumsAndSinglesSubscription(
|
||||||
Subscription[SoundcloudAlbumsAndSinglesSourceValidator]
|
Subscription[SoundcloudAlbumsAndSinglesSourceValidator]
|
||||||
):
|
):
|
||||||
def _extract_info(self):
|
def _extract_info(self) -> List[SoundcloudTrack]:
|
||||||
tracks: List[SoundcloudTrack] = []
|
tracks: List[SoundcloudTrack] = []
|
||||||
downloader = self.get_downloader(SoundcloudDownloader)
|
downloader = self.get_downloader(SoundcloudDownloader)
|
||||||
|
|
||||||
|
|
@ -33,5 +54,4 @@ class SoundcloudAlbumsAndSinglesSubscription(
|
||||||
track for track in single_tracks if not any(album.contains(track) for album in albums)
|
track for track in single_tracks if not any(album.contains(track) for album in albums)
|
||||||
]
|
]
|
||||||
|
|
||||||
for entry in tracks:
|
return tracks
|
||||||
self.post_process_entry(entry)
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from pathlib import Path
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Generic
|
from typing import Generic
|
||||||
|
from typing import List
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Type
|
from typing import Type
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
|
|
@ -33,16 +34,18 @@ from ytdl_subscribe.validators.config.source_options.mixins import DownloadDateR
|
||||||
from ytdl_subscribe.validators.config.source_options.source_validators import SourceValidator
|
from ytdl_subscribe.validators.config.source_options.source_validators import SourceValidator
|
||||||
from ytdl_subscribe.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive
|
from ytdl_subscribe.ytdl_additions.enhanced_download_archive import EnhancedDownloadArchive
|
||||||
|
|
||||||
S = TypeVar("S", bound=SourceValidator)
|
SourceT = TypeVar("SourceT", bound=SourceValidator)
|
||||||
D = TypeVar("D", bound=Downloader)
|
EntryT = TypeVar("EntryT", bound=Entry)
|
||||||
|
DownloaderT = TypeVar("DownloaderT", bound=Downloader)
|
||||||
|
|
||||||
|
|
||||||
class Subscription(Generic[S], ABC):
|
class Subscription(Generic[SourceT], ABC):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
config_options: ConfigOptionsValidator,
|
config_options: ConfigOptionsValidator,
|
||||||
preset_options: PresetValidator,
|
preset_options: PresetValidator,
|
||||||
|
entry_type: Type[EntryT],
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -55,6 +58,7 @@ class Subscription(Generic[S], ABC):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.__config_options = config_options
|
self.__config_options = config_options
|
||||||
self.__preset_options = preset_options
|
self.__preset_options = preset_options
|
||||||
|
self.__entry_type = entry_type
|
||||||
|
|
||||||
self._enhanced_download_archive = EnhancedDownloadArchive(
|
self._enhanced_download_archive = EnhancedDownloadArchive(
|
||||||
subscription_name=name,
|
subscription_name=name,
|
||||||
|
|
@ -63,7 +67,11 @@ class Subscription(Generic[S], ABC):
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_options(self) -> S:
|
def entry_type(self) -> EntryT:
|
||||||
|
return self.__entry_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def source_options(self) -> SourceT:
|
||||||
"""Returns the source options defined for this subscription"""
|
"""Returns the source options defined for this subscription"""
|
||||||
return self.__preset_options.subscription_source
|
return self.__preset_options.subscription_source
|
||||||
|
|
||||||
|
|
@ -98,8 +106,8 @@ class Subscription(Generic[S], ABC):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_downloader(
|
def get_downloader(
|
||||||
self, downloader_type: Type[D], source_ytdl_options: Optional[Dict] = None
|
self, downloader_type: Type[DownloaderT], source_ytdl_options: Optional[Dict] = None
|
||||||
) -> D:
|
) -> DownloaderT:
|
||||||
"""Returns the downloader that will be used to download media for this subscription"""
|
"""Returns the downloader that will be used to download media for this subscription"""
|
||||||
# if source_ytdl_options are present, override the ytdl_options with them
|
# if source_ytdl_options are present, override the ytdl_options with them
|
||||||
ytdl_options = self.__preset_options.ytdl_options.dict
|
ytdl_options = self.__preset_options.ytdl_options.dict
|
||||||
|
|
@ -239,9 +247,11 @@ class Subscription(Generic[S], ABC):
|
||||||
Performs the subscription download.
|
Performs the subscription download.
|
||||||
"""
|
"""
|
||||||
with self._maintain_archive_file():
|
with self._maintain_archive_file():
|
||||||
self._extract_info()
|
entries = self._extract_info()
|
||||||
|
for entry in entries:
|
||||||
|
self.post_process_entry(entry)
|
||||||
|
|
||||||
def _extract_info(self):
|
def _extract_info(self) -> List[EntryT]:
|
||||||
"""
|
"""
|
||||||
Extracts only the info of the source, does not download it
|
Extracts only the info of the source, does not download it
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
|
from abc import ABC
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from yt_dlp import DateRange
|
from yt_dlp import DateRange
|
||||||
|
|
||||||
from ytdl_subscribe.downloaders.youtube_downloader import YoutubeDownloader
|
from ytdl_subscribe.downloaders.youtube_downloader import YoutubeDownloader
|
||||||
|
from ytdl_subscribe.entries.youtube import YoutubeVideo
|
||||||
|
from ytdl_subscribe.subscriptions.subscription import SourceT
|
||||||
from ytdl_subscribe.subscriptions.subscription import Subscription
|
from ytdl_subscribe.subscriptions.subscription import Subscription
|
||||||
|
from ytdl_subscribe.validators.config.config_options.config_options_validator import (
|
||||||
|
ConfigOptionsValidator,
|
||||||
|
)
|
||||||
|
from ytdl_subscribe.validators.config.preset_validator import PresetValidator
|
||||||
from ytdl_subscribe.validators.config.source_options.youtube_validators import (
|
from ytdl_subscribe.validators.config.source_options.youtube_validators import (
|
||||||
YoutubeChannelSourceValidator,
|
YoutubeChannelSourceValidator,
|
||||||
)
|
)
|
||||||
|
|
@ -13,34 +22,42 @@ from ytdl_subscribe.validators.config.source_options.youtube_validators import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class YoutubePlaylistSubscription(Subscription[YoutubePlaylistSourceValidator]):
|
class YoutubeSubscription(Subscription[SourceT], ABC):
|
||||||
def _extract_info(self):
|
def __init__(
|
||||||
entries = self.get_downloader(YoutubeDownloader).download_playlist(
|
self,
|
||||||
|
name: str,
|
||||||
|
config_options: ConfigOptionsValidator,
|
||||||
|
preset_options: PresetValidator,
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
config_options=config_options,
|
||||||
|
preset_options=preset_options,
|
||||||
|
entry_type=YoutubeVideo,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class YoutubePlaylistSubscription(YoutubeSubscription[YoutubePlaylistSourceValidator]):
|
||||||
|
def _extract_info(self) -> List[YoutubeVideo]:
|
||||||
|
return self.get_downloader(YoutubeDownloader).download_playlist(
|
||||||
playlist_id=self.source_options.playlist_id.value
|
playlist_id=self.source_options.playlist_id.value
|
||||||
)
|
)
|
||||||
|
|
||||||
for entry in entries:
|
|
||||||
self.post_process_entry(entry)
|
|
||||||
|
|
||||||
|
class YoutubeChannelSubscription(YoutubeSubscription[YoutubeChannelSourceValidator]):
|
||||||
class YoutubeChannelSubscription(Subscription[YoutubeChannelSourceValidator]):
|
def _extract_info(self) -> List[YoutubeVideo]:
|
||||||
def _extract_info(self):
|
|
||||||
source_ytdl_options = {}
|
source_ytdl_options = {}
|
||||||
source_date_range = self.source_options.get_date_range()
|
source_date_range = self.source_options.get_date_range()
|
||||||
if source_date_range:
|
if source_date_range:
|
||||||
source_ytdl_options["daterange"] = source_ytdl_options
|
source_ytdl_options["daterange"] = source_ytdl_options
|
||||||
|
|
||||||
downloader = self.get_downloader(YoutubeDownloader, source_ytdl_options=source_ytdl_options)
|
downloader = self.get_downloader(YoutubeDownloader, source_ytdl_options=source_ytdl_options)
|
||||||
entries = downloader.download_channel(channel_id=self.source_options.channel_id.value)
|
return downloader.download_channel(channel_id=self.source_options.channel_id.value)
|
||||||
|
|
||||||
for entry in entries:
|
|
||||||
self.post_process_entry(entry)
|
|
||||||
|
|
||||||
|
|
||||||
class YoutubeVideoSubscription(Subscription[YoutubeVideoSourceValidator]):
|
class YoutubeVideoSubscription(YoutubeSubscription[YoutubeVideoSourceValidator]):
|
||||||
def _extract_info(self):
|
def _extract_info(self) -> List[YoutubeVideo]:
|
||||||
entry = self.get_downloader(YoutubeDownloader).download_video(
|
entry = self.get_downloader(YoutubeDownloader).download_video(
|
||||||
video_id=self.source_options.video_id.value
|
video_id=self.source_options.video_id.value
|
||||||
)
|
)
|
||||||
|
return [entry]
|
||||||
self.post_process_entry(entry)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue