[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"):
|
||||
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"]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ytdl_sub.entries.variables.entry_variables import pad
|
||||
|
||||
Preset = Dict[str, Any]
|
||||
class PrebuiltPreset:
|
||||
"""placeholder"""
|
||||
|
||||
####################################################
|
||||
# TV SHOW TYPES
|
||||
|
||||
KODI_TV_SHOW = "_kodi_tv_show"
|
||||
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"
|
||||
_ = PrebuiltPreset()
|
||||
|
||||
|
||||
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
|
||||
def get_preset_names(cls) -> Set[str]:
|
||||
"""
|
||||
|
|
@ -50,17 +16,11 @@ class PrebuiltPresets:
|
|||
-------
|
||||
Preset names in the set
|
||||
"""
|
||||
preset_names = [prop for prop in dir(cls) if isinstance(getattr(cls, prop), property)]
|
||||
return set(preset_names)
|
||||
|
||||
@classmethod
|
||||
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()]
|
||||
return set(
|
||||
preset_name
|
||||
for preset_name in dir(cls)
|
||||
if isinstance(getattr(cls, preset_name), PrebuiltPreset)
|
||||
)
|
||||
|
||||
|
||||
class TvShowByDatePresets(PrebuiltPresets):
|
||||
|
|
@ -69,60 +29,16 @@ class TvShowByDatePresets(PrebuiltPresets):
|
|||
numbers.
|
||||
"""
|
||||
|
||||
@property
|
||||
def kodi_tv_show_by_date(self):
|
||||
"""
|
||||
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]
|
||||
)
|
||||
kodi_tv_show_by_date = _
|
||||
jellyfin_tv_show_by_date = _
|
||||
plex_tv_show_by_date = _
|
||||
|
||||
|
||||
class TvShowByDateEpisodeFormattingPresets(PrebuiltPresets):
|
||||
@property
|
||||
def season_by_year__episode_by_month_day(self) -> Preset:
|
||||
"""
|
||||
DOC
|
||||
"""
|
||||
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()
|
||||
season_by_year__episode_by_month_day = _
|
||||
season_by_year__episode_by_month_day_reversed = _
|
||||
season_by_year_month__episode_by_day = _
|
||||
season_by_year__episode_by_download_index = _
|
||||
|
||||
|
||||
class TvShowCollectionPresets(PrebuiltPresets):
|
||||
|
|
@ -130,97 +46,21 @@ class TvShowCollectionPresets(PrebuiltPresets):
|
|||
Docstring for all TV SHOW URL presets
|
||||
"""
|
||||
|
||||
@property
|
||||
def kodi_tv_show_collection(self) -> Preset:
|
||||
"""
|
||||
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]
|
||||
)
|
||||
kodi_tv_show_collection = _
|
||||
jellyfin_tv_show_collection = _
|
||||
plex_tv_show_collection = _
|
||||
|
||||
|
||||
class TvShowCollectionEpisodeFormattingPresets(PrebuiltPresets):
|
||||
@property
|
||||
def season_by_collection__episode_by_year_month_day(self) -> Preset:
|
||||
"""
|
||||
DOC
|
||||
"""
|
||||
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()
|
||||
season_by_collection__episode_by_year_month_day = _
|
||||
season_by_collection__episode_by_year_month_day_reversed = _
|
||||
season_by_collection__episode_by_playlist_index = _
|
||||
season_by_collection__episode_by_playlist_index_reversed = _
|
||||
|
||||
|
||||
class TvShowCollectionSeasonPresets(PrebuiltPresets):
|
||||
@property
|
||||
def collection_season_1(self):
|
||||
"""
|
||||
DOC
|
||||
"""
|
||||
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()
|
||||
collection_season_1 = _
|
||||
collection_season_2 = _
|
||||
collection_season_3 = _
|
||||
collection_season_4 = _
|
||||
collection_season_5 = _
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
####################################################################################################
|
||||
|
||||
# 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"
|
||||
kodi_tv_show_collection:
|
||||
preset:
|
||||
- "_kodi_tv_show"
|
||||
- "_tv_show_collection"
|
||||
|
||||
####################################################################################################
|
||||
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
|
||||
# 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}"
|
||||
plex_tv_show_collection:
|
||||
preset:
|
||||
- "_plex_tv_show"
|
||||
- "_tv_show_collection"
|
||||
|
||||
collection_season_1:
|
||||
generic:
|
||||
Loading…
Reference in a new issue