This commit is contained in:
jbannon 2022-04-05 07:50:43 +00:00
parent 14d8440ee7
commit b225461339
7 changed files with 20 additions and 23 deletions

View file

@ -58,5 +58,5 @@ class SoundcloudAlbumsAndSinglesSubscription(SoundcloudSubscription):
if not any(album.contains(track) for album in albums)
]
for e in tracks:
self.post_process_entry(e)
for entry in tracks:
self.post_process_entry(entry)

View file

@ -30,8 +30,6 @@ DOWNLOADER_T = TypeVar("DOWNLOADER_T", bound=Downloader)
class Subscription(object):
SOURCE_T = TypeVar("SOURCE_T", bound=SourceValidator)
source_validator_type: Type[SOURCE_T]
download_strategy_type: Type[DOWNLOAD_STRATEGY_T]
downloader_type: Type[Downloader]
@ -96,14 +94,14 @@ class Subscription(object):
def _post_process_tagging(self, entry: Entry):
id3_options = self.metadata_options.id3
t = music_tag.load_file(
audio_file = music_tag.load_file(
entry.file_path(relative_directory=self.working_directory)
)
for tag, tag_formatter in id3_options.tags.dict.items():
t[tag] = entry.apply_formatter(
audio_file[tag] = entry.apply_formatter(
format_string=tag_formatter, overrides=self.overrides.dict
)
t.save()
audio_file.save()
def _post_process_nfo(self, entry):
nfo = {}
@ -128,14 +126,14 @@ class Subscription(object):
nfo_file_path = Path(self.output_options.output_directory.value) / Path(
nfo_file_name
)
with open(nfo_file_path, "wb") as f:
f.write(xml)
with open(nfo_file_path, "wb") as nfo_file:
nfo_file.write(xml)
def extract_info(self):
"""
Extracts only the info of the source, does not download it
"""
raise NotImplemented("Each source needs to implement how it extracts info")
raise NotImplementedError("Each source needs to implement how it extracts info")
def post_process_entry(self, entry: Entry):
if self.metadata_options.id3:
@ -176,8 +174,8 @@ class Subscription(object):
# If the thumbnail is to be converted, then save the converted thumbnail to the
# output filepath
if self.output_options.convert_thumbnail:
im = Image.open(source_thumbnail_path).convert("RGB")
im.save(
image = Image.open(source_thumbnail_path).convert("RGB")
image.save(
fp=output_thumbnail_path,
format=self.output_options.convert_thumbnail.value,
)

View file

@ -33,5 +33,5 @@ class YoutubePlaylistSubscription(YoutubeSubscription):
playlist_id=self.download_strategy_options.playlist_id.value
)
for e in entries:
self.post_process_entry(e)
for entry in entries:
self.post_process_entry(entry)

View file

@ -184,8 +184,10 @@ class LiteralDictValidator(DictValidator):
@property
def dict(self) -> Dict:
"""Returns the entire dict"""
return super()._dict
@property
def keys(self) -> List[str]:
"""Returns a sorted list of the dict's keys"""
return super()._keys

View file

@ -1,15 +1,15 @@
from typing import Any
from typing import Dict
import yaml
from ytdl_subscribe.validators.base.strict_dict_validator import StrictDictValidator
from ytdl_subscribe.validators.base.validators import DictValidator
from ytdl_subscribe.validators.base.validators import LiteralDictValidator
from ytdl_subscribe.validators.base.validators import StringValidator
class ConfigOptionsValidator(StrictDictValidator):
"""Validation for the config options"""
_required_keys = {"working_directory"}
def __init__(self, name: str, value: Any):
@ -23,8 +23,6 @@ class ConfigOptionsValidator(StrictDictValidator):
class ConfigPresetsValidator(LiteralDictValidator):
"""Shallow validator checking for the presets dict in the config"""
pass
class ConfigFileValidator(StrictDictValidator):
_required_keys = {"configuration", "presets"}

View file

@ -1,5 +1,3 @@
from typing import Optional
from ytdl_subscribe.validators.base.strict_dict_validator import StrictDictValidator
from ytdl_subscribe.validators.base.string_formatter_validator import (
StringFormatterValidator,
@ -8,10 +6,14 @@ from ytdl_subscribe.validators.base.string_select_validator import StringSelectV
class ConvertThumbnailValidator(StringSelectValidator):
"""Valid image types that thumbnails can be converted to"""
_select_values = {"jpeg"}
class OutputOptionsValidator(StrictDictValidator):
"""Where to output the final files and thumbnails"""
_required_keys = {"output_directory", "file_name"}
_optional_keys = {"convert_thumbnail", "thumbnail_name"}

View file

@ -1,9 +1,7 @@
import copy
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Tuple
from typing import Type
import sanitize_filename
@ -12,7 +10,6 @@ from ytdl_subscribe.validators.base.strict_dict_validator import StrictDictValid
from ytdl_subscribe.validators.base.string_formatter_validator import (
DictFormatterValidator,
)
from ytdl_subscribe.validators.base.validators import DictValidator
from ytdl_subscribe.validators.base.validators import LiteralDictValidator
from ytdl_subscribe.validators.config.metadata_options.metadata_options_validator import (
MetadataOptionsValidator,