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

Merge pull request #379 from qnorsten/master

Added support for download of all available subtitles on a video
This commit is contained in:
Johan Andersson 2016-05-03 20:18:32 +02:00
commit 435e58436e
4 changed files with 36 additions and 7 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ cover/
svtplay-dl svtplay-dl
svtplay-dl.1 svtplay-dl.1
svtplay-dl.1.gz svtplay-dl.1.gz
github.com/*

View File

@ -135,6 +135,7 @@ class Options(object):
self.http_headers = None self.http_headers = None
self.stream_prio = None self.stream_prio = None
self.remux = False self.remux = False
self.get_all_subtitles = False
def get_media(url, options): def get_media(url, options):
@ -222,12 +223,23 @@ def get_one_media(stream, options):
log.info("No subtitles available") log.info("No subtitles available")
return return
if options.subtitle and options.get_url and options.force_subtitle: if options.subtitle and options.get_url:
print(subs[0].url) if options.get_all_subtitles:
return for sub in subs:
print(sub.url)
else:
print(subs[0].url)
if options.force_subtitle:
return
if options.subtitle and options.output != "-" and not options.get_url: if options.subtitle and options.output != "-" and not options.get_url:
if subs: if subs:
subs[0].download() if options.get_all_subtitles:
for sub in subs:
sub.download()
else:
subs[0].download()
if options.force_subtitle: if options.force_subtitle:
return return
@ -349,6 +361,8 @@ def main():
help="If two streams have the same quality, choose the one you prefer") help="If two streams have the same quality, choose the one you prefer")
parser.add_option("--remux", dest="remux", default=False, action="store_true", parser.add_option("--remux", dest="remux", default=False, action="store_true",
help="Remux from one container to mp4 using ffmpeg or avconv") help="Remux from one container to mp4 using ffmpeg or avconv")
parser.add_option("--all-subtitles", dest="get_all_subtitles", default=False, action="store_true",
help="Download all available subtitles for the video")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if not args: if not args:
parser.print_help() parser.print_help()
@ -401,4 +415,5 @@ def mergeParserOption(options, parser):
options.http_headers = parser.http_headers options.http_headers = parser.http_headers
options.stream_prio = parser.stream_prio options.stream_prio = parser.stream_prio
options.remux = parser.remux options.remux = parser.remux
options.get_all_subtitles = parser.get_all_subtitles
return options return options

View File

@ -31,7 +31,16 @@ class Urplay(Service, OpenGraphThumbMixin):
data = match.group(1) data = match.group(1)
jsondata = json.loads(data) jsondata = json.loads(data)
if len(jsondata["subtitles"]) > 0: if len(jsondata["subtitles"]) > 0:
yield subtitle(copy.copy(self.options), "tt", jsondata["subtitles"][0]["file"].split(",")[0]) for sub in jsondata["subtitles"][:-1]:
yield subtitle(copy.copy(self.options), "tt", sub["file"].split(",")[0], "- " + sub["label"])
#used if you do not want to auto add subfix when downloading just one sub (should possibly also check if option is set)
#Loops through and adds all subtitles and adds label as subfix(last 1 is some tumbnail thingy, so strips it)
#if len(jsondata["subtitles"]) > 1:
# for sub in jsondata["subtitles"][:-1]:
# yield subtitle(copy.copy(self.options), "tt", sub["file"].split(",")[0], "- " + sub["label"])
#Else only add one sub without subfix label
#elif len(jsondata["subtitles"]) > 0:
# yield subtitle(copy.copy(self.options), "tt", jsondata["subtitles"][0]["file"].split(",")[0])
if "streamer" in jsondata["streaming_config"]: if "streamer" in jsondata["streaming_config"]:
basedomain = jsondata["streaming_config"]["streamer"]["redirect"] basedomain = jsondata["streaming_config"]["streamer"]["redirect"]
else: else:

View File

@ -11,12 +11,13 @@ import platform
class subtitle(object): class subtitle(object):
def __init__(self, options, subtype, url): def __init__(self, options, subtype, url, subfix = None):
self.url = url self.url = url
self.subtitle = None self.subtitle = None
self.options = options self.options = options
self.subtype = subtype self.subtype = subtype
self.http = Session() self.http = Session()
self.subfix = subfix
def download(self): def download(self):
subdata = self.http.request("get", self.url, cookies=self.options.cookies) subdata = self.http.request("get", self.url, cookies=self.options.cookies)
@ -37,7 +38,10 @@ class subtitle(object):
data = subdata.text.encode("utf-8") data = subdata.text.encode("utf-8")
else: else:
data = subdata.text data = subdata.text
if self.subfix:
self.options.output = self.options.output + self.subfix
if platform.system() == "Windows" and is_py3: if platform.system() == "Windows" and is_py3:
file_d = output(self.options, "srt", mode="wt", encoding="utf-8") file_d = output(self.options, "srt", mode="wt", encoding="utf-8")
else: else: