[REFACTOR] Clean up prebuilt presets (#291)
* [REFACTOR] Clean up prebuilt presets * prebuilt class
This commit is contained in:
parent
fcdcb509c4
commit
4ce3d9e9fb
6 changed files with 108 additions and 243 deletions
|
|
@ -17,13 +17,6 @@ def _merge_presets() -> Dict[str, Any]:
|
||||||
if file.is_file() and file.name.endswith("yaml"):
|
if file.is_file() and file.name.endswith("yaml"):
|
||||||
mergedeep.merge(merged_configs, load_yaml(file))
|
mergedeep.merge(merged_configs, load_yaml(file))
|
||||||
|
|
||||||
# Get all presets from published preset configs
|
|
||||||
mergedeep.merge(
|
|
||||||
merged_configs,
|
|
||||||
*TvShowByDatePresets.get_presets(),
|
|
||||||
*TvShowCollectionPresets.get_presets(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return merged_configs["presets"]
|
return merged_configs["presets"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,14 @@
|
||||||
from typing import Any
|
|
||||||
from typing import Dict
|
|
||||||
from typing import List
|
|
||||||
from typing import Optional
|
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
from ytdl_sub.entries.variables.entry_variables import pad
|
|
||||||
|
|
||||||
Preset = Dict[str, Any]
|
class PrebuiltPreset:
|
||||||
|
"""placeholder"""
|
||||||
|
|
||||||
####################################################
|
|
||||||
# TV SHOW TYPES
|
|
||||||
|
|
||||||
KODI_TV_SHOW = "_kodi_tv_show"
|
_ = PrebuiltPreset()
|
||||||
JELLYFIN_TV_SHOW = "_jellyfin_tv_show"
|
|
||||||
PLEX_TV_SHOW = "_plex_tv_show"
|
|
||||||
|
|
||||||
#####################################################
|
|
||||||
# TV SHOW URL PRESETS
|
|
||||||
|
|
||||||
TV_SHOW_BY_DATE = "_tv_show_by_date"
|
|
||||||
|
|
||||||
SEASON_YEAR__EPISODE_MONTH_DAY = "season_by_year__episode_by_month_day"
|
|
||||||
SEASON_YEAR__EPISODE_MONTH_DAY_REVERSED = "season_by_year__episode_by_month_day_reversed"
|
|
||||||
SEASON_YEAR__EPISODE_UPLOAD_INDEX = "season_by_year__episode_by_upload_index"
|
|
||||||
SEASON_YEAR_MONTH__EPISODE_DAY = "season_by_year_month__episode_by_day"
|
|
||||||
|
|
||||||
#####################################################
|
|
||||||
# TV SHOW COLLECTION PRESETS
|
|
||||||
|
|
||||||
TV_SHOW_COLLECTION = "_tv_show_collection"
|
|
||||||
|
|
||||||
SEASON_COLLECTION__EPISODE_Y_M_D = "season_by_collection__episode_by_year_month_day"
|
|
||||||
SEASON_COLLECTION__EPISODE_Y_M_D_REV = "season_by_collection__episode_by_year_month_day_reversed"
|
|
||||||
|
|
||||||
|
|
||||||
class PrebuiltPresets:
|
class PrebuiltPresets:
|
||||||
@classmethod
|
|
||||||
def _build_preset(cls, name: str, parent_presets: List[str]) -> Preset:
|
|
||||||
return {"presets": {name: {"preset": parent_presets}}}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _document_preset(cls) -> Preset:
|
|
||||||
return {}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_preset_names(cls) -> Set[str]:
|
def get_preset_names(cls) -> Set[str]:
|
||||||
"""
|
"""
|
||||||
|
|
@ -50,17 +16,11 @@ class PrebuiltPresets:
|
||||||
-------
|
-------
|
||||||
Preset names in the set
|
Preset names in the set
|
||||||
"""
|
"""
|
||||||
preset_names = [prop for prop in dir(cls) if isinstance(getattr(cls, prop), property)]
|
return set(
|
||||||
return set(preset_names)
|
preset_name
|
||||||
|
for preset_name in dir(cls)
|
||||||
@classmethod
|
if isinstance(getattr(cls, preset_name), PrebuiltPreset)
|
||||||
def get_presets(cls) -> List[Preset]:
|
)
|
||||||
"""
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Preset dicts in the set if they are not added in other yamls
|
|
||||||
"""
|
|
||||||
return [getattr(cls(), preset_name) for preset_name in cls.get_preset_names()]
|
|
||||||
|
|
||||||
|
|
||||||
class TvShowByDatePresets(PrebuiltPresets):
|
class TvShowByDatePresets(PrebuiltPresets):
|
||||||
|
|
@ -69,60 +29,16 @@ class TvShowByDatePresets(PrebuiltPresets):
|
||||||
numbers.
|
numbers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@property
|
kodi_tv_show_by_date = _
|
||||||
def kodi_tv_show_by_date(self):
|
jellyfin_tv_show_by_date = _
|
||||||
"""
|
plex_tv_show_by_date = _
|
||||||
Formats a TV show organized by date for Kodi
|
|
||||||
"""
|
|
||||||
return self._build_preset(
|
|
||||||
name="kodi_tv_show_by_date", parent_presets=[KODI_TV_SHOW, TV_SHOW_BY_DATE]
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def jellyfin_tv_show_by_date(self):
|
|
||||||
"""
|
|
||||||
Formats a TV show organized by date for Jellyfin
|
|
||||||
"""
|
|
||||||
return self._build_preset(
|
|
||||||
name="jellyfin_tv_show_by_date", parent_presets=[JELLYFIN_TV_SHOW, TV_SHOW_BY_DATE]
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def plex_tv_show_by_date(self):
|
|
||||||
"""
|
|
||||||
Formats a TV show organized by date for Plex
|
|
||||||
"""
|
|
||||||
return self._build_preset(
|
|
||||||
name="plex_tv_show_by_date", parent_presets=[PLEX_TV_SHOW, TV_SHOW_BY_DATE]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TvShowByDateEpisodeFormattingPresets(PrebuiltPresets):
|
class TvShowByDateEpisodeFormattingPresets(PrebuiltPresets):
|
||||||
@property
|
season_by_year__episode_by_month_day = _
|
||||||
def season_by_year__episode_by_month_day(self) -> Preset:
|
season_by_year__episode_by_month_day_reversed = _
|
||||||
"""
|
season_by_year_month__episode_by_day = _
|
||||||
DOC
|
season_by_year__episode_by_download_index = _
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def season_by_year__episode_by_month_day_reversed(self) -> Preset:
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def season_by_year_month__episode_by_day(self) -> Preset:
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def season_by_year__episode_by_download_index(self) -> Preset:
|
|
||||||
"""DOC"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
|
|
||||||
class TvShowCollectionPresets(PrebuiltPresets):
|
class TvShowCollectionPresets(PrebuiltPresets):
|
||||||
|
|
@ -130,97 +46,21 @@ class TvShowCollectionPresets(PrebuiltPresets):
|
||||||
Docstring for all TV SHOW URL presets
|
Docstring for all TV SHOW URL presets
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@property
|
kodi_tv_show_collection = _
|
||||||
def kodi_tv_show_collection(self) -> Preset:
|
jellyfin_tv_show_collection = _
|
||||||
"""
|
plex_tv_show_collection = _
|
||||||
Kodi TV Show with seasons as years, episodes ordered by upload date
|
|
||||||
"""
|
|
||||||
return self._build_preset(
|
|
||||||
name="kodi_tv_show_collection", parent_presets=[KODI_TV_SHOW, TV_SHOW_COLLECTION]
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def jellyfin_tv_show_collection(self) -> Preset:
|
|
||||||
"""
|
|
||||||
Kodi TV Show with seasons as years, episodes ordered by upload date
|
|
||||||
"""
|
|
||||||
return self._build_preset(
|
|
||||||
name="jellyfin_tv_show_collection",
|
|
||||||
parent_presets=[JELLYFIN_TV_SHOW, TV_SHOW_COLLECTION],
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def plex_tv_show_collection(self) -> Preset:
|
|
||||||
"""
|
|
||||||
Kodi TV Show with seasons as years, episodes ordered by upload date
|
|
||||||
"""
|
|
||||||
return self._build_preset(
|
|
||||||
name="plex_tv_show_collection", parent_presets=[PLEX_TV_SHOW, TV_SHOW_COLLECTION]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TvShowCollectionEpisodeFormattingPresets(PrebuiltPresets):
|
class TvShowCollectionEpisodeFormattingPresets(PrebuiltPresets):
|
||||||
@property
|
season_by_collection__episode_by_year_month_day = _
|
||||||
def season_by_collection__episode_by_year_month_day(self) -> Preset:
|
season_by_collection__episode_by_year_month_day_reversed = _
|
||||||
"""
|
season_by_collection__episode_by_playlist_index = _
|
||||||
DOC
|
season_by_collection__episode_by_playlist_index_reversed = _
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def season_by_collection__episode_by_year_month_day_reversed(self) -> Preset:
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def season_by_collection__episode_by_playlist_index(self) -> Preset:
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def season_by_collection__episode_by_playlist_index_reversed(self) -> Preset:
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
|
|
||||||
class TvShowCollectionSeasonPresets(PrebuiltPresets):
|
class TvShowCollectionSeasonPresets(PrebuiltPresets):
|
||||||
@property
|
collection_season_1 = _
|
||||||
def collection_season_1(self):
|
collection_season_2 = _
|
||||||
"""
|
collection_season_3 = _
|
||||||
DOC
|
collection_season_4 = _
|
||||||
"""
|
collection_season_5 = _
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def collection_season_2(self):
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def collection_season_3(self):
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def collection_season_4(self):
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def collection_season_5(self):
|
|
||||||
"""
|
|
||||||
DOC
|
|
||||||
"""
|
|
||||||
return self._document_preset()
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
presets:
|
|
||||||
|
|
||||||
_plex_tv_show:
|
|
||||||
preset:
|
|
||||||
- "_episode_video_tags"
|
|
||||||
overrides:
|
|
||||||
tv_show_poster_file_name: "poster.jpg"
|
|
||||||
tv_show_fanart_file_name: "fanart.jpg"
|
|
||||||
season_poster_file_name: "Season{season_number_padded}.jpg"
|
|
||||||
file_convert: # Plex currently does not support webm
|
|
||||||
convert_to: "mp4"
|
|
||||||
|
|
||||||
_jellyfin_tv_show:
|
|
||||||
preset:
|
|
||||||
- "_episode_video_tags"
|
|
||||||
- "_episode_nfo_tags"
|
|
||||||
overrides:
|
|
||||||
tv_show_poster_file_name: "poster.jpg"
|
|
||||||
tv_show_fanart_file_name: "fanart.jpg"
|
|
||||||
season_poster_file_name: "season{season_number_padded}-poster.jpg"
|
|
||||||
|
|
||||||
_kodi_tv_show:
|
|
||||||
preset:
|
|
||||||
- "_kodi_base"
|
|
||||||
- "_jellyfin_tv_show"
|
|
||||||
53
src/ytdl_sub/prebuilt_presets/tv_show/tv_show.yaml
Normal file
53
src/ytdl_sub/prebuilt_presets/tv_show/tv_show.yaml
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
presets:
|
||||||
|
|
||||||
|
_plex_tv_show:
|
||||||
|
preset:
|
||||||
|
- "_episode_video_tags"
|
||||||
|
overrides:
|
||||||
|
tv_show_poster_file_name: "poster.jpg"
|
||||||
|
tv_show_fanart_file_name: "fanart.jpg"
|
||||||
|
season_poster_file_name: "Season{season_number_padded}.jpg"
|
||||||
|
file_convert: # Plex currently does not support webm
|
||||||
|
convert_to: "mp4"
|
||||||
|
|
||||||
|
_jellyfin_tv_show:
|
||||||
|
preset:
|
||||||
|
- "_episode_video_tags"
|
||||||
|
- "_episode_nfo_tags"
|
||||||
|
overrides:
|
||||||
|
tv_show_poster_file_name: "poster.jpg"
|
||||||
|
tv_show_fanart_file_name: "fanart.jpg"
|
||||||
|
season_poster_file_name: "season{season_number_padded}-poster.jpg"
|
||||||
|
|
||||||
|
_kodi_tv_show:
|
||||||
|
preset:
|
||||||
|
- "_kodi_base"
|
||||||
|
- "_jellyfin_tv_show"
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
# TV show from any single source. Uses latest entry's thumbnail as tv show poster
|
||||||
|
_tv_show_by_date:
|
||||||
|
generic:
|
||||||
|
download_strategy: "source"
|
||||||
|
url: "{url}"
|
||||||
|
playlist_thumbnails:
|
||||||
|
# Use latest_entry first, then see if YT channel artwork exists
|
||||||
|
- name: "{tv_show_poster_file_name}"
|
||||||
|
uid: "latest_entry"
|
||||||
|
- name: "{tv_show_poster_file_name}"
|
||||||
|
uid: "avatar_uncropped"
|
||||||
|
- name: "{tv_show_fanart_file_name}"
|
||||||
|
uid: "banner_uncropped"
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
# TV show from a collection. Must specify additional `tv_show_collection_season` presets in
|
||||||
|
# addition. Each season sets its own `collection_season_number/_padded`
|
||||||
|
_tv_show_collection:
|
||||||
|
generic:
|
||||||
|
download_strategy: "collection"
|
||||||
|
|
||||||
|
overrides:
|
||||||
|
season_number: "{collection_season_number}"
|
||||||
|
season_number_padded: "{collection_season_number_padded}"
|
||||||
16
src/ytdl_sub/prebuilt_presets/tv_show/tv_show_by_date.yaml
Normal file
16
src/ytdl_sub/prebuilt_presets/tv_show/tv_show_by_date.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
presets:
|
||||||
|
|
||||||
|
kodi_tv_show_by_date:
|
||||||
|
preset:
|
||||||
|
- "_kodi_tv_show"
|
||||||
|
- "_tv_show_by_date"
|
||||||
|
|
||||||
|
jellyfin_tv_show_by_date:
|
||||||
|
preset:
|
||||||
|
- "_jellyfin_tv_show"
|
||||||
|
- "_tv_show_by_date"
|
||||||
|
|
||||||
|
plex_tv_show_by_date:
|
||||||
|
preset:
|
||||||
|
- "_plex_tv_show"
|
||||||
|
- "_tv_show_by_date"
|
||||||
|
|
@ -1,32 +1,20 @@
|
||||||
presets:
|
presets:
|
||||||
|
|
||||||
####################################################################################################
|
|
||||||
|
|
||||||
# TV show from any single source. Uses latest entry's thumbnail as tv show poster
|
kodi_tv_show_collection:
|
||||||
_tv_show_by_date:
|
preset:
|
||||||
generic:
|
- "_kodi_tv_show"
|
||||||
download_strategy: "source"
|
- "_tv_show_collection"
|
||||||
url: "{url}"
|
|
||||||
playlist_thumbnails:
|
|
||||||
# Use latest_entry first, then see if YT channel artwork exists
|
|
||||||
- name: "{tv_show_poster_file_name}"
|
|
||||||
uid: "latest_entry"
|
|
||||||
- name: "{tv_show_poster_file_name}"
|
|
||||||
uid: "avatar_uncropped"
|
|
||||||
- name: "{tv_show_fanart_file_name}"
|
|
||||||
uid: "banner_uncropped"
|
|
||||||
|
|
||||||
####################################################################################################
|
jellyfin_tv_show_collection:
|
||||||
|
preset:
|
||||||
|
- "_jellyfin_tv_show"
|
||||||
|
- "_tv_show_collection"
|
||||||
|
|
||||||
# TV show from a collection. Must specify additional `tv_show_collection_season` presets in
|
plex_tv_show_collection:
|
||||||
# addition. Each season sets its own `collection_season_number/_padded`
|
preset:
|
||||||
_tv_show_collection:
|
- "_plex_tv_show"
|
||||||
generic:
|
- "_tv_show_collection"
|
||||||
download_strategy: "collection"
|
|
||||||
|
|
||||||
overrides:
|
|
||||||
season_number: "{collection_season_number}"
|
|
||||||
season_number_padded: "{collection_season_number_padded}"
|
|
||||||
|
|
||||||
collection_season_1:
|
collection_season_1:
|
||||||
generic:
|
generic:
|
||||||
Loading…
Reference in a new issue