mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Create a proper handling of titles as list
This commit is contained in:
parent
cd7bde944e
commit
9445b71c5c
@ -55,8 +55,6 @@ class Matcher:
|
|||||||
logger.info("Identied %s: %s", path, raw)
|
logger.info("Identied %s: %s", path, raw)
|
||||||
|
|
||||||
title = raw.get("title")
|
title = raw.get("title")
|
||||||
if isinstance(title, list):
|
|
||||||
title = title[0]
|
|
||||||
if not isinstance(title, str):
|
if not isinstance(title, str):
|
||||||
raise ProviderError(f"Could not guess title, found: {title}")
|
raise ProviderError(f"Could not guess title, found: {title}")
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Read that for examples/rules: https://github.com/pymedusa/Medusa/blob/master/medusa/name_parser/rules/rules.py
|
# Read that for examples/rules: https://github.com/pymedusa/Medusa/blob/master/medusa/name_parser/rules/rules.py
|
||||||
|
|
||||||
|
from logging import getLogger
|
||||||
from typing import Any, List, Optional, cast
|
from typing import Any, List, Optional, cast
|
||||||
from rebulk import Rule, RemoveMatch, AppendMatch, POST_PROCESS
|
from rebulk import Rule, RemoveMatch, AppendMatch, POST_PROCESS
|
||||||
from rebulk.match import Matches, Match
|
from rebulk.match import Matches, Match
|
||||||
@ -7,6 +8,68 @@ from copy import copy
|
|||||||
|
|
||||||
from providers.implementations.thexem import clean
|
from providers.implementations.thexem import clean
|
||||||
|
|
||||||
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class UnlistTitles(Rule):
|
||||||
|
"""Join titles to a single string instead of a list
|
||||||
|
|
||||||
|
Example: '/media/series/Demon Slayer - Kimetsu no Yaiba/Season 4/Demon Slayer - Kimetsu no Yaiba - S04E10 - Love Hashira Mitsuri Kanroji WEBDL-1080p.mkv'
|
||||||
|
Default:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"title": [
|
||||||
|
"Demon Slayer",
|
||||||
|
"Kimetsu no Yaiba"
|
||||||
|
],
|
||||||
|
"season": 4,
|
||||||
|
"episode_title": "Demon Slayer",
|
||||||
|
"alternative_title": "Kimetsu no Yaiba",
|
||||||
|
"episode": 10,
|
||||||
|
"source": "Web",
|
||||||
|
"screen_size": "1080p",
|
||||||
|
"container": "mkv",
|
||||||
|
"mimetype": "video/x-matroska",
|
||||||
|
"type": "episode"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Expected:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"title": "Demon Slayer - Kimetsu no Yaiba",
|
||||||
|
"season": 4,
|
||||||
|
"episode_title": "Demon Slayer",
|
||||||
|
"alternative_title": "Kimetsu no Yaiba",
|
||||||
|
"episode": 10,
|
||||||
|
"source": "Web",
|
||||||
|
"screen_size": "1080p",
|
||||||
|
"container": "mkv",
|
||||||
|
"mimetype": "video/x-matroska",
|
||||||
|
"type": "episode"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
|
priority = POST_PROCESS
|
||||||
|
consequence = [RemoveMatch, AppendMatch]
|
||||||
|
|
||||||
|
def when(self, matches: Matches, context) -> Any:
|
||||||
|
titles: List[Match] = matches.named("title") # type: ignore
|
||||||
|
|
||||||
|
if not titles or len(titles) <= 1:
|
||||||
|
return
|
||||||
|
|
||||||
|
title = copy(titles[0])
|
||||||
|
for nmatch in titles[1:]:
|
||||||
|
# Check if titles are next to each other, if they are not ignore it.
|
||||||
|
next: List[Match] = matches.next(title) # type: ignore
|
||||||
|
if not next or next[0] != nmatch:
|
||||||
|
logger.warn(f"Ignoring potential part of title: {nmatch.value}")
|
||||||
|
continue
|
||||||
|
title.end = nmatch.end
|
||||||
|
|
||||||
|
return [titles, [title]]
|
||||||
|
|
||||||
|
|
||||||
class EpisodeTitlePromotion(Rule):
|
class EpisodeTitlePromotion(Rule):
|
||||||
"""Promote "episode_title" to "episode" when the title is in fact the episode number
|
"""Promote "episode_title" to "episode" when the title is in fact the episode number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user