mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Proper rendering
computation (god that was a pain)
This commit is contained in:
parent
968dc8eab9
commit
fff0c0ea91
@ -1,13 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(str(Path(f"{__file__}/../../..").resolve()))
|
||||
from typing import Any, List, cast
|
||||
|
||||
from guessit.api import default_api
|
||||
from typing import cast, List, Any
|
||||
from rebulk import Rebulk
|
||||
from rebulk.match import Match
|
||||
|
||||
@ -27,8 +20,7 @@ def guessit(
|
||||
expected_titles: List[str] = [],
|
||||
extra_flags: dict[str, Any] = {},
|
||||
) -> dict[str, list[Match]]:
|
||||
rendering = []
|
||||
ret = default_api.guessit(
|
||||
return default_api.guessit(
|
||||
name,
|
||||
{
|
||||
"episode_prefer_number": True,
|
||||
@ -36,34 +28,6 @@ def guessit(
|
||||
"expected_title": expected_titles,
|
||||
"enforce_list": True,
|
||||
"advanced": True,
|
||||
"rendering": rendering,
|
||||
}
|
||||
| extra_flags,
|
||||
)
|
||||
print(rendering)
|
||||
return ret
|
||||
|
||||
|
||||
# Only used to test locally
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
import json
|
||||
|
||||
# from providers.implementations.thexem import TheXemClient
|
||||
from guessit.jsonutils import GuessitEncoder
|
||||
from aiohttp import ClientSession
|
||||
import asyncio
|
||||
|
||||
async def main():
|
||||
async with ClientSession() as client:
|
||||
# xem = TheXemClient(client)
|
||||
|
||||
advanced = any(x == "-a" for x in sys.argv)
|
||||
ret = guessit(
|
||||
sys.argv[1],
|
||||
expected_titles=[],
|
||||
extra_flags={"advanced": advanced},
|
||||
)
|
||||
print(json.dumps(ret, cls=GuessitEncoder, indent=4))
|
||||
|
||||
asyncio.run(main())
|
||||
|
@ -1,6 +1,5 @@
|
||||
# Read that for examples/rules: https://github.com/pymedusa/Medusa/blob/master/medusa/name_parser/rules/rules.py
|
||||
|
||||
import hashlib
|
||||
from copy import copy
|
||||
from logging import getLogger
|
||||
from typing import Any, List, Optional, cast
|
||||
@ -187,29 +186,3 @@ class SeasonYearDedup(Rule):
|
||||
year: List[Match] = matches.named("year") # type: ignore
|
||||
if len(season) == 1 and len(year) == 1 and season[0].value == year[0].value:
|
||||
return season
|
||||
|
||||
|
||||
# class RenderingDedup(Rule):
|
||||
# """Compute rendering (sha of path - version/part)
|
||||
#
|
||||
# Example: "One Piece (1999) v2 152 part2.mkv"
|
||||
# Computes: sha("One Piece (1999) 152.mkv")
|
||||
# ```
|
||||
# """
|
||||
#
|
||||
# priority = POST_PROCESS + 100000
|
||||
# consequence = AppendMatch
|
||||
#
|
||||
# def when(self, matches: Matches, context: dict[str, list[str]]) -> Any:
|
||||
# ret = hashlib.new("sha256")
|
||||
#
|
||||
# value: list[Match] = sorted(
|
||||
# list(matches) + matches.holes(), # type: ignore
|
||||
# key=lambda m: m.start,
|
||||
# )
|
||||
# for m in value:
|
||||
# if m.name == "part" or m.name == "version":
|
||||
# continue
|
||||
# ret.update(cast(str, m.raw).encode("utf-8"))
|
||||
# context["rendering"] = [ret.hexdigest()]
|
||||
# return [Match(start=0, end=1, value=ret.hexdigest(), raw="", name="rendering")]
|
||||
|
@ -16,11 +16,7 @@ pipeline: list[Callable[[str, Guess], Awaitable[Guess]]] = [
|
||||
|
||||
|
||||
async def identify(path: str) -> Video:
|
||||
raw = guessit(
|
||||
path,
|
||||
expected_titles=[],
|
||||
extra_flags={"advanced": True},
|
||||
)
|
||||
raw = guessit(path, expected_titles=[])
|
||||
|
||||
# guessit should only return one (according to the doc)
|
||||
title = raw.get("title", [])[0]
|
||||
@ -34,9 +30,14 @@ async def identify(path: str) -> Video:
|
||||
seasons = raw.get("season", [])
|
||||
episodes = raw.get("episode", [])
|
||||
|
||||
rendering = path[:version.start] + path[version.end:]
|
||||
# just strip the version & part number from the path
|
||||
rendering_path = "".join(
|
||||
c
|
||||
for i, c in enumerate(path)
|
||||
if not (version and version.start <= i < version.end)
|
||||
and not (part and part.start <= i < part.end)
|
||||
)
|
||||
|
||||
print(raw)
|
||||
guess = Guess(
|
||||
title=cast(str, title.value),
|
||||
kind=cast(Literal["episode"] | Literal["movie"], kind.value),
|
||||
@ -63,7 +64,7 @@ async def identify(path: str) -> Video:
|
||||
|
||||
return Video(
|
||||
path=path,
|
||||
rendering=sha256(path.encode()).hexdigest(),
|
||||
rendering=sha256(rendering_path.encode()).hexdigest(),
|
||||
part=cast(int, part.value) if part else None,
|
||||
version=cast(int, version.value) if version else 1,
|
||||
guess=guess,
|
||||
|
Loading…
x
Reference in New Issue
Block a user