Skip to content

Instantly share code, notes, and snippets.

@osuranboa
Created August 2, 2022 20:32
Show Gist options
  • Select an option

  • Save osuranboa/bcc9d6b08565e4f8bfbb08a5d6ec1827 to your computer and use it in GitHub Desktop.

Select an option

Save osuranboa/bcc9d6b08565e4f8bfbb08a5d6ec1827 to your computer and use it in GitHub Desktop.

Revisions

  1. @lunaynx lunaynx revised this gist Jun 30, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,7 @@ def get_chapters(self, title):
    "LFEC", # End of Credits
    "tag_end", # End of Post-Credits Scene
    "LFOC", # Last Frame of Composition. Seems to include credits.
    ]
    chapters = []
    scene = 0
    post_credit = 0
  2. @lunaynx lunaynx revised this gist Jun 30, 2022. 1 changed file with 23 additions and 12 deletions.
    35 changes: 23 additions & 12 deletions dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -11,32 +11,39 @@ def get_chapters(self, title):
    "FFER": "Recap", # recap_start
    "LFER": "Scene {i}", # recap_end
    "FFEI": "Intro", # intro_start
    "FFTC": "Intro", # intro_start?
    "FFTC": "Intro", # First Frame of Title Credits. This may be after the actual episode has already started.
    "LFEI": "Scene {i}", # intro_end
    "LFTC": "Scene {i}", # intro_end?
    "LFTC": "Scene {i}", # Last Frame of Title Credits (see above).
    "FPCI": "Scene {i}", # Placeholder for commercial breaks
    "FFEC": "Credits",
    # TODO: Are these used for anything else?
    "tag_start": "Post-Credits Scene {j}",
    # This is when the player shrinks and the next episode countdown starts.
    # May be later than the actual start of credits.
    "up_next": "Credits",
    # "LFEC": "End of Credits",
    }
    alternate_types = {
    ("FFER",): "recap_start",
    ("LFER",): "recap_end",
    ("FFEI", "FFTC"): "intro_start",
    ("LFEI", "LFTC"): "intro_end",
    ("FFEC",): "up_next", # Not an exact match, but we only need up_next if FFEC doesn't exist
    ("FFEI",): "intro_start",
    ("FFEI", "intro_start"): "FFTC", # Not an exact match
    ("LFEI",): "intro_end",
    ("LFEI", "intro_end"): "LFTC", # Not an exact match
    ("FFEC",): "up_next", # Not an exact match
    }
    ignore_types = [
    "LFEC",
    ]
    "FFOC", # First Frame of Composition. Seems to include intro and maybe recap too.
    "LFEC", # End of Credits
    "tag_end", # End of Post-Credits Scene
    "LFOC", # Last Frame of Composition. Seems to include credits.
    chapters = []
    scene = 0
    post_credit = 0
    num_post_credit = len([1 for t, _ in milestones if t == "tag_start"])
    for main_types, alternate in alternate_types.items():
    if any(type_ in main_types for type_, _ in milestones):
    ignore_types.append(alternate)
    for type_, milestone in milestones:
    for type_, milestone in sorted(milestones, key=lambda tm: tm[1]["milestoneTime"][0]["startMillis"]):
    if type_ in ignore_types:
    continue
    if not (name := types.get(type_)):
    @@ -45,9 +52,13 @@ def get_chapters(self, title):
    ms = int(milestone["milestoneTime"][0]["startMillis"])
    if "{i}" in name:
    scene += 1
    chapters.append(MenuTrack(
    if "{j}" in name:
    post_credit += 1
    chapter = MenuTrack(
    number=len(chapters) + 1,
    title=name.format(i=scene),
    title=name.format(i=scene, j=post_credit if num_post_credit > 1 else "").strip(),
    timecode=ms / 1000,
    ))
    )
    chapter.note = type_
    chapters.append(chapter)
    return chapters
  3. @lunaynx lunaynx revised this gist Jun 29, 2022. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -21,17 +21,21 @@ def get_chapters(self, title):
    "up_next": "Credits",
    # "LFEC": "End of Credits",
    }
    alternate_types = {
    ("FFER",): "recap_start",
    ("LFER",): "recap_end",
    ("FFEI", "FFTC"): "intro_start",
    ("LFEI", "LFTC"): "intro_end",
    ("FFEC",): "up_next", # Not an exact match, but we only need up_next if FFEC doesn't exist
    }
    ignore_types = [
    "recap_start",
    "recap_end",
    "intro_start",
    "intro_end",
    "LFEC",
    ]
    chapters = []
    scene = 0
    if any(type_ == "FFEC" for type_, _ in milestones):
    ignore_types.append("up_next")
    for main_types, alternate in alternate_types.items():
    if any(type_ in main_types for type_, _ in milestones):
    ignore_types.append(alternate)
    for type_, milestone in milestones:
    if type_ in ignore_types:
    continue
  4. @lunaynx lunaynx revised this gist Jun 29, 2022. 1 changed file with 23 additions and 16 deletions.
    39 changes: 23 additions & 16 deletions dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,11 @@
    def get_chapters(self, title):
    if not (milestones := title.service_data.get("milestone")):
    milestones = []
    for type_, type_milestones in title.service_data.get("milestone").items():
    for milestone in type_milestones:
    milestones.append((type_, milestone))
    if not milestones:
    return []

    types = {
    # https://github.com/IMFTool/IMFTool/blob/master/src/ImfCommon.cpp#L458-L504
    "FFER": "Recap", # recap_start
    @@ -13,7 +18,7 @@ def get_chapters(self, title):
    "FFEC": "Credits",
    # This is when the player shrinks and the next episode countdown starts.
    # May be later than the actual start of credits.
    "up_next": "Up Next",
    "up_next": "Credits",
    # "LFEC": "End of Credits",
    }
    ignore_types = [
    @@ -25,18 +30,20 @@ def get_chapters(self, title):
    ]
    chapters = []
    scene = 0
    for type_, type_milestones in milestones.items():
    for milestone in type_milestones:
    if not (name := types.get(type_)):
    if type_ not in ignore_types:
    self.log.warning(f"Skipping unknown chapter type {type_}")
    continue
    ms = int(milestone["milestoneTime"][0]["startMillis"])
    if "{i}" in name:
    scene += 1
    chapters.append(MenuTrack(
    number=len(chapters) + 1,
    title=name.format(i=scene),
    timecode=ms / 1000,
    ))
    if any(type_ == "FFEC" for type_, _ in milestones):
    ignore_types.append("up_next")
    for type_, milestone in milestones:
    if type_ in ignore_types:
    continue
    if not (name := types.get(type_)):
    self.log.warning(f"Skipping unknown chapter type {type_}")
    continue
    ms = int(milestone["milestoneTime"][0]["startMillis"])
    if "{i}" in name:
    scene += 1
    chapters.append(MenuTrack(
    number=len(chapters) + 1,
    title=name.format(i=scene),
    timecode=ms / 1000,
    ))
    return chapters
  5. @lunaynx lunaynx revised this gist Jun 29, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ def get_chapters(self, title):
    "FFTC": "Intro", # intro_start?
    "LFEI": "Scene {i}", # intro_end
    "LFTC": "Scene {i}", # intro_end?
    "FPCI": "Scene {i}", # Placeholder for commercial break
    "FPCI": "Scene {i}", # Placeholder for commercial breaks
    "FFEC": "Credits",
    # This is when the player shrinks and the next episode countdown starts.
    # May be later than the actual start of credits.
  6. @lunaynx lunaynx revised this gist Jun 29, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,6 @@ def get_chapters(self, title):
    if "{i}" in name:
    scene += 1
    chapters.append(MenuTrack(
    number=len(chapters) + 1,
    number=len(chapters) + 1,
    title=name.format(i=scene),
    timecode=ms / 1000,
  7. @lunaynx lunaynx created this gist Jun 29, 2022.
    43 changes: 43 additions & 0 deletions dsnp_chapters.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    def get_chapters(self, title):
    if not (milestones := title.service_data.get("milestone")):
    return []
    types = {
    # https://github.com/IMFTool/IMFTool/blob/master/src/ImfCommon.cpp#L458-L504
    "FFER": "Recap", # recap_start
    "LFER": "Scene {i}", # recap_end
    "FFEI": "Intro", # intro_start
    "FFTC": "Intro", # intro_start?
    "LFEI": "Scene {i}", # intro_end
    "LFTC": "Scene {i}", # intro_end?
    "FPCI": "Scene {i}", # Placeholder for commercial break
    "FFEC": "Credits",
    # This is when the player shrinks and the next episode countdown starts.
    # May be later than the actual start of credits.
    "up_next": "Up Next",
    # "LFEC": "End of Credits",
    }
    ignore_types = [
    "recap_start",
    "recap_end",
    "intro_start",
    "intro_end",
    "LFEC",
    ]
    chapters = []
    scene = 0
    for type_, type_milestones in milestones.items():
    for milestone in type_milestones:
    if not (name := types.get(type_)):
    if type_ not in ignore_types:
    self.log.warning(f"Skipping unknown chapter type {type_}")
    continue
    ms = int(milestone["milestoneTime"][0]["startMillis"])
    if "{i}" in name:
    scene += 1
    chapters.append(MenuTrack(
    number=len(chapters) + 1,
    number=len(chapters) + 1,
    title=name.format(i=scene),
    timecode=ms / 1000,
    ))
    return chapters