mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-06-15 13:37:24 +00:00
refactor(routes, subtitle, track): improve code readability by formatting list structures
This commit is contained in:
@@ -1327,7 +1327,8 @@ def setup_swagger(app: web.Application) -> None:
|
||||
)
|
||||
|
||||
# Add routes with OpenAPI documentation
|
||||
swagger.add_routes([
|
||||
swagger.add_routes(
|
||||
[
|
||||
web.get("/api/health", health),
|
||||
web.get("/api/services", services),
|
||||
web.post("/api/search", search),
|
||||
@@ -1347,4 +1348,5 @@ def setup_swagger(app: web.Application) -> None:
|
||||
web.post("/api/session/{session_id}/prompt", session_prompt_submit),
|
||||
web.get("/api/session/{session_id}", session_info),
|
||||
web.delete("/api/session/{session_id}", session_delete),
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
@@ -461,7 +461,8 @@ class Subtitle(Track):
|
||||
content_lines.append(lines[i])
|
||||
i += 1
|
||||
|
||||
cues.append({
|
||||
cues.append(
|
||||
{
|
||||
"start_ms": Subtitle._parse_vtt_time(start_str),
|
||||
"end_ms": Subtitle._parse_vtt_time(end_str),
|
||||
"start_str": start_str,
|
||||
@@ -469,7 +470,8 @@ class Subtitle(Track):
|
||||
"line_pos": line_pos,
|
||||
"content": "\n".join(content_lines),
|
||||
"settings": settings,
|
||||
})
|
||||
}
|
||||
)
|
||||
else:
|
||||
i += 1
|
||||
|
||||
@@ -494,19 +496,23 @@ class Subtitle(Track):
|
||||
group.sort(key=lambda x: x["line_pos"])
|
||||
# Use the earliest start time from the group
|
||||
earliest = min(group, key=lambda x: x["start_ms"])
|
||||
merged_cues.append({
|
||||
merged_cues.append(
|
||||
{
|
||||
"start_str": earliest["start_str"],
|
||||
"end_str": group[0]["end_str"],
|
||||
"content": "\n".join(c["content"] for c in group),
|
||||
"settings": "",
|
||||
})
|
||||
}
|
||||
)
|
||||
else:
|
||||
merged_cues.append({
|
||||
merged_cues.append(
|
||||
{
|
||||
"start_str": current["start_str"],
|
||||
"end_str": current["end_str"],
|
||||
"content": current["content"],
|
||||
"settings": current["settings"],
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
i = j if len(group) > 1 else i + 1
|
||||
|
||||
@@ -1145,14 +1151,16 @@ class Subtitle(Track):
|
||||
if cue_box.type == b"sttg":
|
||||
layout = Layout(webvtt_positioning=cue_box.settings)
|
||||
elif cue_box.type == b"payl":
|
||||
nodes.extend([
|
||||
nodes.extend(
|
||||
[
|
||||
node
|
||||
for line in cue_box.cue_text.split("\n")
|
||||
for node in [
|
||||
CaptionNode.create_text(WebVTTReader()._decode(line)),
|
||||
CaptionNode.create_break(),
|
||||
]
|
||||
])
|
||||
]
|
||||
)
|
||||
nodes.pop()
|
||||
|
||||
if nodes:
|
||||
|
||||
@@ -687,16 +687,19 @@ class Track:
|
||||
if hasattr(self, "data") and self.data.get("audio_language"):
|
||||
audio_lang = self.data["audio_language"]
|
||||
audio_name = self.data.get("audio_language_name", audio_lang)
|
||||
args.extend([
|
||||
args.extend(
|
||||
[
|
||||
"-metadata:s:a:0",
|
||||
f"language={audio_lang}",
|
||||
"-metadata:s:a:0",
|
||||
f"title={audio_name}",
|
||||
"-metadata:s:a:0",
|
||||
f"handler_name={audio_name}",
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
args.extend([
|
||||
args.extend(
|
||||
[
|
||||
# Following are very important!
|
||||
"-map_metadata",
|
||||
"-1", # don't transfer metadata to output file
|
||||
@@ -705,7 +708,8 @@ class Track:
|
||||
"-codec",
|
||||
"copy",
|
||||
str(output_path),
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
args,
|
||||
|
||||
Reference in New Issue
Block a user