Remove identify traces (#1178)

This commit is contained in:
Zoe Roux 2025-11-23 23:55:23 +01:00 committed by GitHub
parent eb56dd70d6
commit c56f9ea791
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,18 +1,15 @@
import os
from collections.abc import Awaitable from collections.abc import Awaitable
from hashlib import sha256 from hashlib import sha256
from itertools import zip_longest from itertools import zip_longest
from logging import getLogger from logging import getLogger
from typing import Callable, Literal, cast from typing import Callable, Literal, cast
from opentelemetry import trace
from rebulk.match import Match from rebulk.match import Match
from ..models.videos import Guess, Video from ..models.videos import Guess, Video
from .guess.guess import guessit from .guess.guess import guessit
logger = getLogger(__name__) logger = getLogger(__name__)
tracer = trace.get_tracer("kyoo.scanner")
pipeline: list[Callable[[str, Guess], Awaitable[Guess]]] = [ pipeline: list[Callable[[str, Guess], Awaitable[Guess]]] = [
# TODO: add nfo scanner # TODO: add nfo scanner
@ -22,66 +19,62 @@ pipeline: list[Callable[[str, Guess], Awaitable[Guess]]] = [
async def identify(path: str) -> Video: async def identify(path: str) -> Video:
with tracer.start_as_current_span(f"identify {os.path.basename(path)}") as span: raw = guessit(path, expected_titles=[])
span.set_attribute("video.path", path)
raw = guessit(path, expected_titles=[]) # guessit should only return one (according to the doc)
title = raw.get("title", [])[0]
kind = raw.get("type", [])[0]
version = next(iter(raw.get("version", [])), None)
# apparently guessit can return multiples but tbh idk what to do with
# multiples part. we'll just ignore them for now
part = next(iter(raw.get("part", [])), None)
# guessit should only return one (according to the doc) years = raw.get("year", [])
title = raw.get("title", [])[0] seasons = raw.get("season", [])
kind = raw.get("type", [])[0] episodes = raw.get("episode", [])
version = next(iter(raw.get("version", [])), None)
# apparently guessit can return multiples but tbh idk what to do with
# multiples part. we'll just ignore them for now
part = next(iter(raw.get("part", [])), None)
years = raw.get("year", []) # just strip the version & part number from the path
seasons = raw.get("season", []) rendering_path = "".join(
episodes = raw.get("episode", []) 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)
)
# just strip the version & part number from the path guess = Guess(
rendering_path = "".join( title=cast(str, title.value),
c kind=cast(Literal["episode", "movie"], kind.value),
for i, c in enumerate(path) extra_kind=None,
if not (version and version.start <= i < version.end) years=[cast(int, y.value) for y in years],
and not (part and part.start <= i < part.end) episodes=[
) Guess.Episode(season=cast(int, s.value), episode=cast(int, e.value))
for s, e in zip_longest(
seasons,
episodes,
fillvalue=seasons[-1] if any(seasons) else Match(0, 0, value=1),
)
],
external_id={},
from_="guessit",
raw={
k: [x.value if x.value is int else str(x.value) for x in v]
for k, v in raw.items()
},
)
guess = Guess( for step in pipeline:
title=cast(str, title.value), try:
kind=cast(Literal["episode", "movie"], kind.value), guess = await step(path, guess)
extra_kind=None, except Exception as e:
years=[cast(int, y.value) for y in years], logger.error("Couldn't run %s.", step.__name__, exc_info=e)
episodes=[
Guess.Episode(season=cast(int, s.value), episode=cast(int, e.value))
for s, e in zip_longest(
seasons,
episodes,
fillvalue=seasons[-1] if any(seasons) else Match(0, 0, value=1),
)
],
external_id={},
from_="guessit",
raw={
k: [x.value if x.value is int else str(x.value) for x in v]
for k, v in raw.items()
},
)
span.set_attribute("video.name", guess.title)
for step in pipeline: return Video(
try: path=path,
guess = await step(path, guess) rendering=sha256(rendering_path.encode()).hexdigest(),
except Exception as e: part=cast(int, part.value) if part else None,
logger.error("Couldn't run %s.", step.__name__, exc_info=e) version=cast(int, version.value) if version else 1,
guess=guess,
return Video( )
path=path,
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,
)
if __name__ == "__main__": if __name__ == "__main__":