mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
feat(naming): per-service title_map remapping (#106)
Add services.<TAG>.title_map exact-match dict to rewrite service-provided titles before naming/output. Shared remap_titles helper applied on local dl, import, and client-side dl --remote (server stays raw so clients can override names for services they don't have installed locally).
This commit is contained in:
@@ -8,4 +8,40 @@ Title_T = Union[Movie, Episode, Song]
|
||||
Titles_T = Union[Movies, Series, Album]
|
||||
|
||||
|
||||
__all__ = ("Episode", "Series", "Movie", "Movies", "Album", "Song", "Title_T", "Titles_T")
|
||||
def remap_titles(titles: Titles_T, title_map: dict) -> Titles_T:
|
||||
"""
|
||||
Rewrite titles in-place using an exact-match ``title_map``.
|
||||
|
||||
Some services name a title differently from how the user wants it stored, which can
|
||||
break library matching. ``title_map`` maps a source title string to the desired output
|
||||
title. Episodes are matched on their ``title`` (the show name), Movies and Songs on
|
||||
their ``name``. Returns the same collection for convenient chaining.
|
||||
"""
|
||||
if not title_map or not titles:
|
||||
return titles
|
||||
|
||||
def remap_one(title: Title_T) -> None:
|
||||
attr = "title" if isinstance(title, Episode) else "name"
|
||||
current = getattr(title, attr, None)
|
||||
if current and current in title_map:
|
||||
setattr(title, attr, title_map[current])
|
||||
|
||||
if hasattr(titles, "__iter__"):
|
||||
for title in titles:
|
||||
remap_one(title)
|
||||
else:
|
||||
remap_one(titles)
|
||||
return titles
|
||||
|
||||
|
||||
__all__ = (
|
||||
"Episode",
|
||||
"Series",
|
||||
"Movie",
|
||||
"Movies",
|
||||
"Album",
|
||||
"Song",
|
||||
"Title_T",
|
||||
"Titles_T",
|
||||
"remap_titles",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user