def download(self): subdata = self.http.request("get", self.url, cookies=self.options.cookies) if subdata.status_code != 200: log.warning("Can't download subtitle file") return data = None if "mtgx" in self.url and subdata.content[:3] == b"\xef\xbb\xbf": subdata.encoding = "utf-8" self.bom = True if self.subtype == "tt": data = self.tt(subdata) if self.subtype == "json": data = self.json(subdata) if self.subtype == "sami": data = self.sami(subdata) if self.subtype == "smi": data = self.smi(subdata) if self.subtype == "wrst": data = self.wrst(subdata) if self.subtype == "raw": data = self.raw(subdata) if self.subfix: self.options.output = self.options.output + self.subfix if self.options.get_raw_subtitles: subdata = self.raw(subdata) self.save_file(subdata, self.subtype) self.save_file(data, "srt")
def get_one_media(stream, options): if not options.output or os.path.isdir(options.output): data = stream.get_urldata() match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S) if match: options.output_auto = True title_tag = decode_html_entities(match.group(1)) if not options.output: options.output = filenamify(title_tag) else: # output is a directory options.output = os.path.join(options.output, filenamify(title_tag)) if platform.system() == "Windows": # ugly hack. replace \ with / or add extra \ because c:\test\kalle.flv will add c:_tab_est\kalle.flv if options.output.find("\\") > 0: options.output = options.output.replace("\\", "/") videos = [] subs = [] streams = stream.get(options) for i in streams: if isinstance(i, VideoRetriever): if options.preferred: if options.preferred == i.name(): videos.append(i) else: videos.append(i) if isinstance(i, subtitle): subs.append(i) if options.subtitle and options.output != "-": if subs: subs[0].download(copy.copy(options)) if options.force_subtitle: return if len(videos) == 0: log.error("Can't find any streams for that url") else: stream = select_quality(options, videos) log.info("Selected to download %s, bitrate: %s", stream.name(), stream.bitrate) try: stream.download() except UIException as e: if options.verbose: raise e log.error(e.message) sys.exit(2) if options.thumbnail and hasattr(stream, "get_thumbnail"): if options.output != "-": log.info("Getting thumbnail") stream.get_thumbnail(options) else: log.warning("Can not get thumbnail when fetching to stdout")
def get_one_media(stream, options): # Make an automagic filename if not filename(options, stream): return videos = [] subs = [] streams = stream.get(options) for i in streams: if isinstance(i, VideoRetriever): if options.preferred: if options.preferred.lower() == i.name(): videos.append(i) else: videos.append(i) if isinstance(i, subtitle): subs.append(i) if options.subtitle and options.output != "-": if subs: subs[0].download() if options.force_subtitle: return if len(videos) == 0: log.error("Can't find any streams for that url") else: if options.list_quality: list_quality(videos) return stream = select_quality(options, videos) log.info("Selected to download %s, bitrate: %s", stream.name(), stream.bitrate) if options.get_url: print(stream.url) return try: stream.download() except UIException as e: if options.verbose: raise e log.error(e.message) sys.exit(2) if options.thumbnail and hasattr(stream, "get_thumbnail"): if options.output != "-": log.info("Getting thumbnail") stream.get_thumbnail(options) else: log.warning("Can not get thumbnail when fetching to stdout")
def download(self): subdata = self.http.request("get", self.url) if subdata.status_code != 200: log.warning("Can't download subtitle file") return data = None if "mtgx" in self.url and subdata.content[:3] == b"\xef\xbb\xbf": subdata.encoding = "utf-8" self.bom = True if self.subtype == "tt": data = self.tt(subdata) if self.subtype == "json": data = self.json(subdata) if self.subtype == "sami": data = self.sami(subdata) if self.subtype == "smi": data = self.smi(subdata) if self.subtype == "wrst": if "tv4play" in self.url and subdata.content[:3] == b"\xef\xbb\xbf": subdata.encoding = "utf-8" self.bom = True if "dplay" in self.url: subdata.encoding = "utf-8" data = self.wrst(subdata) if self.subtype == "wrstsegment": data = self.wrstsegment(subdata) if self.subtype == "raw": data = self.raw(subdata) if self.subfix: if self.config.get("get_all_subtitles"): if self.output["episodename"]: self.output["episodename"] = "{}-{}".format( self.output["episodename"], self.subfix) else: self.output["episodename"] = self.subfix if self.config.get("get_raw_subtitles"): subdata = self.raw(subdata) self.save_file(subdata, self.subtype) self.save_file(data, "srt")
def download(self): subdata = self.http.request("get", self.url) if subdata.status_code != 200: log.warning("Can't download subtitle file") return data = None if "mtgx" in self.url and subdata.content[:3] == b"\xef\xbb\xbf": subdata.encoding = "utf-8" self.bom = True if self.subtype == "tt": data = self.tt(subdata) if self.subtype == "json": data = self.json(subdata) if self.subtype == "sami": data = self.sami(subdata) if self.subtype == "smi": data = self.smi(subdata) if self.subtype == "wrst": if "tv4play" in self.url and subdata.content[:3] == b"\xef\xbb\xbf": subdata.encoding = "utf-8" self.bom = True if "dplay" in self.url: subdata.encoding = "utf-8" data = self.wrst(subdata) if self.subtype == "wrstsegment": data = self.wrstsegment(subdata) if self.subtype == "raw": data = self.raw(subdata) if self.subfix: if self.config.get("get_all_subtitles"): if self.output["episodename"]: self.output["episodename"] = "{}-{}".format(self.output["episodename"], self.subfix) else: self.output["episodename"] = self.subfix if self.config.get("get_raw_subtitles"): subdata = self.raw(subdata) self.save_file(subdata, self.subtype) self.save_file(data, "srt")
def find_all_episodes(self, options): parse = urlparse(self.url) self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) match = re.search("^/(program|programmer|videos|videoer)/([^/]+)", parse.path) if not match: log.error("Can't find show name") return None if not self._token(): log.error("Something went wrong getting token for requests") premium = False if self.options.username and self.options.password: premium = self._login() if not premium: log.warning("Wrong username/password.") url = "https://disco-api.{}/content/shows/{}".format( self.domain, match.group(2)) res = self.http.get(url) programid = res.json()["data"]["id"] seasons = res.json()["data"]["attributes"]["seasonNumbers"] episodes = [] for season in seasons: qyerystring = "include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&filter[seasonNumber]={}&" \ "page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid, season) res = self.http.get( "https://disco-api.{}/content/videos?{}".format( self.domain, qyerystring)) janson = res.json() for i in janson["data"]: if not premium and not "Free" in i["attributes"]["packages"]: continue episodes.append("https://www.{}/videos/{}".format( self.domain, i["attributes"]["path"])) if len(episodes) == 0: log.error("Cant find any playable files") if options.all_last > 0: return episodes[:options.all_last] return episodes
def find_all_episodes(self, options): parse = urlparse(self.url) self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) match = re.search("^/(program|programmer|videos|videoer)/([^/]+)", parse.path) if not match: log.error("Can't find show name") return None if not self._token(): log.error("Something went wrong getting token for requests") premium = False if self.options.username and self.options.password: premium = self._login() if not premium: log.warning("Wrong username/password.") url = "https://disco-api.{}/content/shows/{}".format(self.domain, match.group(2)) res = self.http.get(url) programid = res.json()["data"]["id"] seasons = res.json()["data"]["attributes"]["seasonNumbers"] episodes = [] for season in seasons: qyerystring = "include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&filter[seasonNumber]={}&" \ "page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid, season) res = self.http.get("https://disco-api.{}/content/videos?{}".format(self.domain, qyerystring)) janson = res.json() for i in janson["data"]: if not premium and not "Free" in i["attributes"]["packages"]: continue episodes.append("https://www.{}/videos/{}".format(self.domain, i["attributes"]["path"])) if len(episodes) == 0: log.error("Cant find any playable files") if options.all_last > 0: return episodes[:options.all_last] return episodes
def get_one_media(stream, options): # Make an automagic filename if not filename(stream): return if options.merge_subtitle: from svtplay_dl.utils import which if not which('ffmpeg'): log.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.") log.info("https://ffmpeg.org/download.html") sys.exit(2) videos = [] subs = [] subfixes = [] error = [] streams = stream.get() try: for i in streams: if isinstance(i, VideoRetriever): if options.preferred: if options.preferred.lower() == i.name(): videos.append(i) else: videos.append(i) if isinstance(i, subtitle): subs.append(i) if isinstance(i, Exception): error.append(i) except Exception as e: if options.verbose: raise else: log.error("svtplay-dl crashed") log.error("Run again and add --verbose as an argument, to get more information") log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues") log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue") sys.exit(3) if options.require_subtitle and not subs: log.info("No subtitles available") return if options.subtitle and options.get_url: if subs: if options.get_all_subtitles: for sub in subs: print(sub.url) else: print(subs[0].url) if options.force_subtitle: return def options_subs_dl(subfixes): if subs: if options.get_all_subtitles: for sub in subs: sub.download() if options.merge_subtitle: if sub.subfix: subfixes += [sub.subfix] else: options.get_all_subtitles = False else: subs[0].download() elif options.merge_subtitle: options.merge_subtitle = False if options.subtitle and options.output != "-" and not options.get_url: options_subs_dl(subfixes) if options.force_subtitle: return if options.merge_subtitle and not options.subtitle: options_subs_dl(subfixes) if not videos: log.error("No videos found.") for exc in error: log.error(str(exc)) else: if options.list_quality: list_quality(videos) return try: stream = select_quality(options, videos) if options.get_url: print(stream.url) return log.info("Selected to download %s, bitrate: %s", stream.name(), stream.bitrate) stream.download() except UIException as e: if options.verbose: raise e log.error(e) sys.exit(2) if options.thumbnail and hasattr(stream, "get_thumbnail"): if options.output != "-": log.info("Getting thumbnail") stream.get_thumbnail(options) else: log.warning("Can not get thumbnail when fetching to stdout") post = postprocess(stream, options, subfixes) if stream.name() == "dash" and post.detect: post.merge() if stream.name() == "dash" and not post.detect and stream.finished: log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds") if options.remux: post.remux() if options.silent_semi and stream.finished: log.log(25, "Download of %s was completed" % stream.options.output)
def get_one_media(stream, options): # Make an automagic filename if not filename(stream): return if options.merge_subtitle: from svtplay_dl.utils import which if not which('ffmpeg'): log.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.") log.info("https://ffmpeg.org/download.html") sys.exit(2) videos = [] subs = [] subfixes = [] error = [] streams = stream.get() try: for i in streams: if isinstance(i, VideoRetriever): if options.preferred: if options.preferred.lower() == i.name(): videos.append(i) else: videos.append(i) if isinstance(i, subtitle): subs.append(i) if isinstance(i, Exception): error.append(i) except Exception as e: if options.verbose: log.error("version: %s" % __version__) raise else: log.error("svtplay-dl crashed") log.error("Run again and add --verbose as an argument, to get more information") log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues") log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue") sys.exit(3) if options.require_subtitle and not subs: log.info("No subtitles available") return if options.subtitle and options.get_url: if subs: if options.get_all_subtitles: for sub in subs: print(sub.url) else: print(subs[0].url) if options.force_subtitle: return def options_subs_dl(subfixes): if subs: if options.get_all_subtitles: for sub in subs: sub.download() if options.merge_subtitle: if sub.subfix: subfixes += [sub.subfix] else: options.get_all_subtitles = False else: subs[0].download() elif options.merge_subtitle: options.merge_subtitle = False if options.subtitle and options.output != "-" and not options.get_url: options_subs_dl(subfixes) if options.force_subtitle: return if options.merge_subtitle and not options.subtitle: options_subs_dl(subfixes) if len(videos) == 0: for exc in error: log.error(str(exc)) else: if options.list_quality: list_quality(videos) return try: stream = select_quality(options, videos) if options.get_url: print(stream.url) return log.info("Selected to download %s, bitrate: %s", stream.name(), stream.bitrate) stream.download() except UIException as e: if options.verbose: raise e log.error(e) sys.exit(2) if options.thumbnail and hasattr(stream, "get_thumbnail"): if options.output != "-": log.info("Getting thumbnail") stream.get_thumbnail(options) else: log.warning("Can not get thumbnail when fetching to stdout") post = postprocess(stream, options, subfixes) if stream.name() == "dash" and post.detect: post.merge() if stream.name() == "dash" and not post.detect and stream.finished: log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds") if options.remux: post.remux() if options.silent_semi and stream.finished: log.log(25, "Download of %s was completed" % stream.options.output)
def get_one_media(stream, options): # Make an automagic filename if not filename(options, stream): return videos = [] subs = [] error = [] streams = stream.get(options) try: for i in streams: if isinstance(i, VideoRetriever): if options.preferred: if options.preferred.lower() == i.name(): videos.append(i) else: videos.append(i) if isinstance(i, subtitle): subs.append(i) if isinstance(i, Exception): error.append(i) except Exception as e: if options.verbose: raise e else: print("Script crashed. please run the script again and add --verbose as an argument") print("Make an issue with the url you used and include the stacktrace. please include the version of the script") sys.exit(3) if options.require_subtitle and not subs: log.info("No subtitles available") return if options.subtitle and options.output != "-": if subs: subs[0].download() if options.force_subtitle: return if len(videos) == 0: for exc in error: log.error(str(exc)) sys.exit(2) else: if options.list_quality: list_quality(videos) return stream = select_quality(options, videos) log.info("Selected to download %s, bitrate: %s", stream.name(), stream.bitrate) if options.get_url: print(stream.url) return try: stream.download() except UIException as e: if options.verbose: raise e log.error(e) sys.exit(2) if options.thumbnail and hasattr(stream, "get_thumbnail"): if options.output != "-": log.info("Getting thumbnail") stream.get_thumbnail(options) else: log.warning("Can not get thumbnail when fetching to stdout")
def get_one_media(stream, options): # Make an automagic filename if not filename(stream): return videos = [] subs = [] error = [] streams = stream.get() try: for i in streams: if isinstance(i, VideoRetriever): if options.preferred: if options.preferred.lower() == i.name(): videos.append(i) else: videos.append(i) if isinstance(i, subtitle): subs.append(i) if isinstance(i, Exception): error.append(i) except Exception as e: if options.verbose: raise else: log.error("svtplay-dl crashed") log.error("Run again and add --verbose as an argument, to get more information") log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues") log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue") sys.exit(3) if options.require_subtitle and not subs: log.info("No subtitles available") return if options.subtitle and options.output != "-": if subs: subs[0].download() if options.force_subtitle: return if len(videos) == 0: for exc in error: log.error(str(exc)) else: if options.list_quality: list_quality(videos) return stream = select_quality(options, videos) log.info("Selected to download %s, bitrate: %s", stream.name(), stream.bitrate) if options.get_url: print(stream.url) return try: stream.download() except UIException as e: if options.verbose: raise e log.error(e) sys.exit(2) if options.thumbnail and hasattr(stream, "get_thumbnail"): if options.output != "-": log.info("Getting thumbnail") stream.get_thumbnail(options) else: log.warning("Can not get thumbnail when fetching to stdout") post = postprocess(stream) if stream.name() == "dash" and post.detect: post.merge() if stream.name() == "dash" and not post.detect and stream.finished: log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds") if options.remux: post.remux()
def get(self): parse = urlparse(self.url) self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) if not self._token(): log.error("Something went wrong getting token for requests") if self.options.username and self.options.password: premium = self._login() if not premium: log.warning("Wrong username/password.") channel = False if "kanaler" in parse.path: match = re.search("kanaler/([^/]+)$", parse.path) path = "/channels/{}".format(match.group(1)) url = "https://disco-api.{}/content{}".format(self.domain, path) channel = True self.options.live = True elif "program" in parse.path: match = re.search("(programmer|program)/([^/]+)$", parse.path) path = "/shows/{}".format(match.group(2)) url = "https://disco-api.{}/content{}".format(self.domain, path) res = self.http.get(url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) programid = res.json()["data"]["id"] qyerystring = "include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&" \ "page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid) res = self.http.get("https://disco-api.{}/content/videos?{}".format(self.domain, qyerystring)) janson = res.json() vid = 0 slug = None for i in janson["data"]: if int(i["id"]) > vid: vid = int(i["id"]) slug = i["attributes"]["path"] if slug: url = "https://disco-api.{}/content/videos/{}".format(self.domain, slug) else: yield ServiceError("Cant find latest video on program url") return else: match = re.search("(videos|videoer)/(.*)$", parse.path) url = "https://disco-api.{}/content/videos/{}".format(self.domain, match.group(2)) res = self.http.get(url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) janson = res.json() if "errors" in janson: yield ServiceError("Cant find any videos on this url") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "dplay" if channel: name = filenamify(janson["data"]["attributes"]["name"]) else: name = self._autoname(janson) if name is None: yield ServiceError("Cant find vid id for autonaming") return title = "{0}-{1}-{2}".format(name, janson["data"]["id"], self.options.service) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return api = "https://disco-api.{}/playback/videoPlaybackInfo/{}".format(self.domain, janson["data"]["id"]) res = self.http.get(api) if res.status_code > 400: yield ServiceError("You dont have permission to watch this") return streams = hlsparse(self.options, self.http.request("get", res.json()["data"]["attributes"]["streaming"]["hls"]["url"]), res.json()["data"]["attributes"]["streaming"]["hls"]["url"], httpobject=self.http) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) if not self._token(): log.error("Something went wrong getting token for requests") if self.options.username and self.options.password: premium = self._login() if not premium: log.warning("Wrong username/password.") channel = False if "kanaler" in parse.path: match = re.search("kanaler/([^/]+)$", parse.path) path = "/channels/{}".format(match.group(1)) url = "https://disco-api.{}/content{}".format(self.domain, path) channel = True self.options.live = True else: match = re.search("(videos|videoer)/(.*)$", parse.path) url = "https://disco-api.{}/content/videos/{}".format( self.domain, match.group(2)) res = self.http.get( url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) janson = res.json() if "errors" in janson: yield ServiceError("Cant find any videos on this url") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "dplay" if channel: name = filenamify(janson["data"]["attributes"]["name"]) else: name = self._autoname(janson) if name is None: yield ServiceError("Cant find vid id for autonaming") return title = "{0}-{1}-{2}".format(name, janson["data"]["id"], self.options.service) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return api = "https://disco-api.{}/playback/videoPlaybackInfo/{}".format( self.domain, janson["data"]["id"]) res = self.http.get(api) if res.status_code > 400: yield ServiceError("You dont have permission to watch this") return streams = hlsparse( self.options, self.http.request( "get", res.json()["data"]["attributes"]["streaming"]["hls"]["url"]), res.json()["data"]["attributes"]["streaming"]["hls"]["url"], httpobject=self.http) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) self.domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) if not self._token(): log.error("Something went wrong getting token for requests") if self.options.username and self.options.password: premium = self._login() if not premium: log.warning("Wrong username/password.") channel = False if "kanaler" in parse.path: match = re.search("kanaler/([^/]+)$", parse.path) path = "/channels/{}".format(match.group(1)) url = "https://disco-api.{}/content{}".format(self.domain, path) channel = True self.options.live = True elif "program" in parse.path: match = re.search("(programmer|program)/([^/]+)$", parse.path) path = "/shows/{}".format(match.group(2)) url = "https://disco-api.{}/content{}".format(self.domain, path) res = self.http.get( url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) programid = res.json()["data"]["id"] qyerystring = "include=primaryChannel,show&filter[videoType]=EPISODE&filter[show.id]={}&" \ "page[size]=100&sort=seasonNumber,episodeNumber,-earliestPlayableStart".format(programid) res = self.http.get( "https://disco-api.{}/content/videos?{}".format( self.domain, qyerystring)) janson = res.json() vid = 0 slug = None for i in janson["data"]: if int(i["id"]) > vid: vid = int(i["id"]) slug = i["attributes"]["path"] if slug: url = "https://disco-api.{}/content/videos/{}".format( self.domain, slug) else: yield ServiceError("Cant find latest video on program url") return else: match = re.search("(videos|videoer)/(.*)$", parse.path) url = "https://disco-api.{}/content/videos/{}".format( self.domain, match.group(2)) res = self.http.get( url, headers={"x-disco-client": "WEB:UNKNOWN:dplay-client:0.0.1"}) janson = res.json() if "errors" in janson: yield ServiceError("Cant find any videos on this url") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "dplay" if channel: name = filenamify(janson["data"]["attributes"]["name"]) else: name = self._autoname(janson) if name is None: yield ServiceError("Cant find vid id for autonaming") return title = "{0}-{1}-{2}".format(name, janson["data"]["id"], self.options.service) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return api = "https://disco-api.{}/playback/videoPlaybackInfo/{}".format( self.domain, janson["data"]["id"]) res = self.http.get(api) if res.status_code > 400: yield ServiceError("You dont have permission to watch this") return streams = hlsparse( self.options, self.http.request( "get", res.json()["data"]["attributes"]["streaming"]["hls"]["url"]), res.json()["data"]["attributes"]["streaming"]["hls"]["url"], httpobject=self.http) if streams: for n in list(streams.keys()): yield streams[n]