1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

getmedia: make the subtitle section a bit easier to read.

This commit is contained in:
Johan Andersson 2021-05-22 22:57:43 +02:00
parent cb3ec04b04
commit 0fdcb1e1f0
2 changed files with 44 additions and 34 deletions

View File

@ -20,6 +20,7 @@ from svtplay_dl.utils.output import find_dupes
from svtplay_dl.utils.output import formatname from svtplay_dl.utils.output import formatname
from svtplay_dl.utils.stream import list_quality from svtplay_dl.utils.stream import list_quality
from svtplay_dl.utils.stream import select_quality from svtplay_dl.utils.stream import select_quality
from svtplay_dl.utils.stream import subtitle_decider
from svtplay_dl.utils.text import exclude from svtplay_dl.utils.text import exclude
@ -104,7 +105,7 @@ def get_one_media(stream):
sys.exit(2) sys.exit(2)
videos = [] videos = []
subs = [] subtitles = []
subfixes = [] subfixes = []
error = [] error = []
streams = stream.get() streams = stream.get()
@ -120,7 +121,7 @@ def get_one_media(stream):
else: else:
videos.append(i) videos.append(i)
if isinstance(i, subtitle): if isinstance(i, subtitle):
subs.append(i) subtitles.append(i)
except Exception: except Exception:
if stream.config.get("verbose"): if stream.config.get("verbose"):
raise raise
@ -151,44 +152,15 @@ def get_one_media(stream):
) )
return return
if stream.config.get("require_subtitle") and not subs: if stream.config.get("require_subtitle") and not subtitles:
logging.info("No subtitles available") logging.info("No subtitles available")
return return
if stream.config.get("subtitle") and stream.config.get("get_url"): if not stream.config.get("list_quality"):
if subs: subtitle_decider(stream, subtitles)
if stream.config.get("get_all_subtitles"):
for sub in subs:
print(sub.url)
else:
print(subs[0].url)
if stream.config.get("force_subtitle"): if stream.config.get("force_subtitle"):
return return
def options_subs_dl(subfixes):
if subs:
if stream.config.get("get_all_subtitles"):
for sub in subs:
sub.download()
if stream.config.get("merge_subtitle"):
if sub.subfix:
subfixes += [sub.subfix]
else:
stream.config.set("get_all_subtitles", False)
else:
subs[0].download()
elif stream.config.get("merge_subtitle"):
stream.config.set("merge_subtitle", False)
if stream.config.get("subtitle") and not stream.config.get("get_url"):
options_subs_dl(subfixes)
if stream.config.get("force_subtitle"):
if not subs:
logging.info("No subtitles available")
return
if stream.config.get("merge_subtitle") and not stream.config.get("subtitle"):
options_subs_dl(subfixes)
if not videos: if not videos:
errormsg = None errormsg = None
for exc in error: for exc in error:

View File

@ -73,6 +73,44 @@ def audio_role(config, streams) -> List:
return prioritized return prioritized
def subtitle_filter(subtitles) -> List:
languages = []
subs = []
preferred = subtitles[0].config.get("subtitle_preferred")
all_subs = subtitles[0].config.get("get_all_subtitles")
for sub in subtitles:
if sub.subfix not in languages:
if not all_subs and sub.subfix == preferred:
subs.append(sub)
languages.append(sub.subfix)
else:
subs.append(sub)
languages.append(sub.subfix)
return subs
def subtitle_decider(stream, subtitles):
if subtitles and (stream.config.get("merge_subtitle") or stream.config.get("subtitle")):
subtitles = subtitle_filter(subtitles)
if stream.config.get("get_all_subtitles"):
for sub in subtitles:
if stream.config.get("get_url"):
print(sub.url)
else:
sub.download()
if stream.config.get("merge_subtitle"):
if not sub.subfix:
stream.config.set("get_all_subtitles", False)
else:
if stream.config.get("get_url"):
print(subtitles[0].url)
else:
subtitles[0].download()
elif stream.config.get("merge_subtitle"):
stream.config.set("merge_subtitle", False)
def select_quality(config, streams): def select_quality(config, streams):
high = 0 high = 0
if isinstance(config.get("quality"), str): if isinstance(config.get("quality"), str):