python3.10 better generics
This commit is contained in:
parent
688c6361bf
commit
beb48ac5aa
5 changed files with 7 additions and 57 deletions
|
|
@ -4,38 +4,14 @@ 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):
|
|
||||||
"""
|
|
||||||
Abstract class for all Soundcloud-based subscriptions. Sets entry type to SoundcloudTrack
|
|
||||||
"""
|
|
||||||
|
|
||||||
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(
|
||||||
SoundcloudSubscription[SoundcloudAlbumsAndSinglesSourceValidator]
|
Subscription[SoundcloudAlbumsAndSinglesSourceValidator, SoundcloudTrack]
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Soundcloud subscription to download albums and tracks as singles.
|
Soundcloud subscription to download albums and tracks as singles.
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ EntryT = TypeVar("EntryT", bound=Entry)
|
||||||
DownloaderT = TypeVar("DownloaderT", bound=Downloader)
|
DownloaderT = TypeVar("DownloaderT", bound=Downloader)
|
||||||
|
|
||||||
|
|
||||||
class Subscription(Generic[SourceT], ABC):
|
class Subscription(Generic[SourceT, EntryT], ABC):
|
||||||
"""
|
"""
|
||||||
Subscription classes are the 'controllers' that perform...
|
Subscription classes are the 'controllers' that perform...
|
||||||
|
|
||||||
|
|
@ -58,7 +58,6 @@ class Subscription(Generic[SourceT], ABC):
|
||||||
name: str,
|
name: str,
|
||||||
config_options: ConfigOptionsValidator,
|
config_options: ConfigOptionsValidator,
|
||||||
preset_options: PresetValidator,
|
preset_options: PresetValidator,
|
||||||
entry_type: Type[EntryT],
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
|
|
@ -71,7 +70,6 @@ class Subscription(Generic[SourceT], 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,
|
||||||
|
|
@ -80,11 +78,11 @@ class Subscription(Generic[SourceT], ABC):
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entry_type(self) -> EntryT:
|
def entry_type(self) -> Type[EntryT]:
|
||||||
"""
|
"""
|
||||||
:return: The Entry type this subscription uses to represent downloaded media
|
:return: The Entry type this subscription uses to represent downloaded media
|
||||||
"""
|
"""
|
||||||
return self.__entry_type
|
return EntryT.__class__
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_options(self) -> SourceT:
|
def source_options(self) -> SourceT:
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,7 @@ from typing import List
|
||||||
|
|
||||||
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.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,
|
||||||
)
|
)
|
||||||
|
|
@ -20,26 +15,7 @@ from ytdl_subscribe.validators.config.source_options.youtube_validators import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class YoutubeSubscription(Subscription[SourceT], ABC):
|
class YoutubePlaylistSubscription(Subscription[YoutubePlaylistSourceValidator, YoutubeVideo]):
|
||||||
"""
|
|
||||||
Abstract class for all Youtube-based subscriptions. Sets entry type to YoutubeVideo
|
|
||||||
"""
|
|
||||||
|
|
||||||
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=YoutubeVideo,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class YoutubePlaylistSubscription(YoutubeSubscription[YoutubePlaylistSourceValidator]):
|
|
||||||
"""
|
"""
|
||||||
Youtube subscription to download videos from a playlist
|
Youtube subscription to download videos from a playlist
|
||||||
"""
|
"""
|
||||||
|
|
@ -50,7 +26,7 @@ class YoutubePlaylistSubscription(YoutubeSubscription[YoutubePlaylistSourceValid
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class YoutubeChannelSubscription(YoutubeSubscription[YoutubeChannelSourceValidator]):
|
class YoutubeChannelSubscription(Subscription[YoutubeChannelSourceValidator, YoutubeVideo]):
|
||||||
"""
|
"""
|
||||||
Youtube subscription to download videos from a channel
|
Youtube subscription to download videos from a channel
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,7 +41,7 @@ class YoutubeChannelSubscription(YoutubeSubscription[YoutubeChannelSourceValidat
|
||||||
return downloader.download_channel(channel_id=self.source_options.channel_id.value)
|
return downloader.download_channel(channel_id=self.source_options.channel_id.value)
|
||||||
|
|
||||||
|
|
||||||
class YoutubeVideoSubscription(YoutubeSubscription[YoutubeVideoSourceValidator]):
|
class YoutubeVideoSubscription(Subscription[YoutubeVideoSourceValidator, YoutubeVideo]):
|
||||||
"""
|
"""
|
||||||
Youtube subscription to download a single video
|
Youtube subscription to download a single video
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue