mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-24 09:55:12 +00:00
fix(chapters): drop duplicate timestamps in the EXAMPLE template and docs
Log a get_chapters failure at debug level on the API tracks route.
This commit is contained in:
@@ -550,7 +550,10 @@ exists. Timestamps take `"HH:MM:SS[.mmm]"`, int milliseconds, or float seconds.
|
|||||||
```python
|
```python
|
||||||
def get_chapters(self, title: Title_T) -> Chapters:
|
def get_chapters(self, title: Title_T) -> Chapters:
|
||||||
chapters = [Chapter(name=c.get("name"), timestamp=c["start"]) for c in title.data.get("chapters", [])]
|
chapters = [Chapter(name=c.get("name"), timestamp=c["start"]) for c in title.data.get("chapters", [])]
|
||||||
return Chapters(sorted(chapters, key=lambda c: c.timestamp))
|
unique: dict[str, Chapter] = {}
|
||||||
|
for chapter in sorted(chapters, key=lambda c: not c.named):
|
||||||
|
unique.setdefault(chapter.timestamp, chapter)
|
||||||
|
return Chapters(sorted(unique.values(), key=lambda c: c.timestamp))
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! warning "Sort by timestamp before you build the `Chapters`"
|
!!! warning "Sort by timestamp before you build the `Chapters`"
|
||||||
@@ -559,7 +562,7 @@ def get_chapters(self, title: Title_T) -> Chapters:
|
|||||||
lands before it.
|
lands before it.
|
||||||
|
|
||||||
You never need to add `Chapter(0)`. An API chapter at `0` keeps its name. Drop
|
You never need to add `Chapter(0)`. An API chapter at `0` keeps its name. Drop
|
||||||
duplicate timestamps.
|
duplicate timestamps and keep the named chapter, as the example does.
|
||||||
|
|
||||||
!!! note "Close a named range with an unnamed chapter"
|
!!! note "Close a named range with an unnamed chapter"
|
||||||
An unnamed `Chapter` ends the range before it: `Chapter(name="Intro")` at the
|
An unnamed `Chapter` ends the range before it: `Chapter(name="Intro")` at the
|
||||||
|
|||||||
@@ -4290,7 +4290,8 @@ async def session_tracks_handler(
|
|||||||
try:
|
try:
|
||||||
chapters = await asyncio.to_thread(service_instance.get_chapters, title)
|
chapters = await asyncio.to_thread(service_instance.get_chapters, title)
|
||||||
session.chapters_by_title[str(title_id)] = chapters if chapters else []
|
session.chapters_by_title[str(title_id)] = chapters if chapters else []
|
||||||
except (Exception, SystemExit):
|
except (Exception, SystemExit) as e:
|
||||||
|
log.debug("get_chapters failed for title %s: %s", title_id, e)
|
||||||
session.chapters_by_title[str(title_id)] = []
|
session.chapters_by_title[str(title_id)] = []
|
||||||
|
|
||||||
snapshot = await asyncio.to_thread(capture, tracks, config.serve.get("compression_level", 1))
|
snapshot = await asyncio.to_thread(capture, tracks, config.serve.get("compression_level", 1))
|
||||||
|
|||||||
@@ -443,14 +443,17 @@ class EXAMPLE(Service):
|
|||||||
return tracks
|
return tracks
|
||||||
|
|
||||||
def get_chapters(self, title: Title_T) -> Chapters:
|
def get_chapters(self, title: Title_T) -> Chapters:
|
||||||
chapters = Chapters()
|
chapters = []
|
||||||
for chapter in title.data.get("chapters", []):
|
for chapter in title.data.get("chapters", []):
|
||||||
if chapter["name"] == "Intro":
|
if chapter["name"] == "Intro":
|
||||||
chapters.add(Chapter(timestamp=chapter["start"], name="Opening"))
|
chapters.append(Chapter(timestamp=chapter["start"], name="Opening"))
|
||||||
chapters.add(Chapter(timestamp=chapter["end"])) # unnamed marker = chapter break
|
chapters.append(Chapter(timestamp=chapter["end"])) # unnamed marker = chapter break
|
||||||
elif chapter["name"] == "Credits":
|
elif chapter["name"] == "Credits":
|
||||||
chapters.add(Chapter(timestamp=chapter["start"], name="Credits"))
|
chapters.append(Chapter(timestamp=chapter["start"], name="Credits"))
|
||||||
return chapters
|
unique: dict[str, Chapter] = {}
|
||||||
|
for chapter in sorted(chapters, key=lambda c: not c.named):
|
||||||
|
unique.setdefault(chapter.timestamp, chapter)
|
||||||
|
return Chapters(sorted(unique.values(), key=lambda c: c.timestamp))
|
||||||
|
|
||||||
def get_widevine_service_certificate(self, **_: Any) -> Optional[str]:
|
def get_widevine_service_certificate(self, **_: Any) -> Optional[str]:
|
||||||
# Returning the service cert enables privacy-mode license requests.
|
# Returning the service cert enables privacy-mode license requests.
|
||||||
|
|||||||
Reference in New Issue
Block a user