def get_media(url, options): if "http" not in url[:4]: url = "http://%s" % url if options.silent_semi: options.silent = True if options.verbose: log.debug("version: {0}".format( __version__)) stream = service_handler(sites, options, url) if not stream: generic = Generic(options, url) url, stream = generic.get(sites) if not stream: if url.find(".f4m") > 0 or url.find(".m3u8") > 0: stream = Raw(options, url) if not stream: log.error("That site is not supported. Make a ticket or send a message") sys.exit(2) if is_py2: url = ensure_unicode(url) if options.all_episodes: get_all_episodes(stream, copy.copy(options), url) else: get_one_media(stream, copy.copy(options))
def get_media(url, options): if "http" not in url[:4]: url = "http://%s" % url if options.silent_semi: options.silent = True if options.verbose: log.debug("version: {0}".format(__version__)) stream = service_handler(sites, options, url) if not stream: generic = Generic(options, url) url, stream = generic.get(sites) if not stream: if re.search(".f4m", url) or re.search(".m3u8", url) or re.search( ".mpd", url): stream = Raw(options, url) if not stream: log.error( "That site is not supported. Make a ticket or send a message") sys.exit(2) if is_py2: url = ensure_unicode(url) if options.all_episodes: get_all_episodes(stream, copy.copy(options), url) else: get_one_media(stream, copy.copy(options))
def download(self): """ Get the stream from RTMP """ args = [] if self.options.live: args.append("-v") if self.options.resume: args.append("-e") file_d = output(self.options, "flv", False) if file_d is None: return args += ["-o", self.options.output] if self.options.silent or self.options.output == "-": args.append("-q") if self.options.other: if is_py2: args += shlex.split(self.options.other.encode("utf-8")) else: args += shlex.split(self.options.other) if self.options.verbose: args.append("-V") command = ["rtmpdump", "-r", self.url] + args log.debug("Running: %s", " ".join(command)) try: subprocess.call(command) except OSError as e: log.error("Could not execute rtmpdump: " + e.strerror) return self.finished = True
def download(self): """ Get the stream from RTMP """ args = [] if self.options.live: args.append("-v") if self.options.resume: args.append("-e") file_d = output(self.options, self.options.output, "flv", False) if file_d is None: return args += ["-o", self.options.output] if self.options.silent or self.options.output == "-": args.append("-q") if self.options.other: if is_py2: args += shlex.split(self.options.other.encode("utf-8")) else: args += shlex.split(self.options.other) if self.options.verbose: args.append("-V") command = ["rtmpdump", "-r", self.url] + args log.debug("Running: %s", " ".join(command)) try: subprocess.call(command) except OSError as e: log.error("Could not execute rtmpdump: " + e.strerror)
def download(self): """ Get the stream from RTMP """ self.output_extention = "flv" args = [] if self.config.get("live"): args.append("-v") if self.config.get("resume"): args.append("-e") file_d = output(self.output, self.config, "flv", False) if file_d is None: return args += ["-o", formatname(self.output, self.config, "flv")] if self.config.get("silent"): args.append("-q") if self.kwargs.get("other"): args += shlex.split(self.kwargs.pop("other")) if self.config.get("verbose"): args.append("-V") command = ["rtmpdump", "-r", self.url] + args log.debug("Running: {0}".format(" ".join(command))) try: subprocess.call(command) except OSError as e: log.error("Could not execute rtmpdump: {0}".format(e.strerror)) return self.finished = True
def get(self, options): log.debug('Using VHX handler') try: video_id = self.url.split('vhx.tv/videos/')[1].split('?')[0] log.debug("Video ID: {}".format(video_id)) except IndexError: # Rudimentary error check log.error("Error parsing URL") sys.exit(2) methods_url = 'https://embed.vhx.tv/videos/{}/files'.format(video_id) streaming_methods = get_http_data(methods_url) js = json.loads(streaming_methods) playlist = js['hls'] streams = hlsparse(playlist) for bitrate, url in streams.items(): yield HLS(copy.copy(options), url, bitrate)
def get(self, options): urlp = urlparse(self.url) success = False for jtv_video_type in [self._get_chapter, self._get_archive, self._get_channel]: try: jtv_video_type(urlp, options) success = True break except JustinUrlException as e: log.debug(str(e)) if not success: log.debug(str(e)) log.error("This twitch/justin video type is unsupported") sys.exit(2)
def get(self, options): urlp = urlparse(self.url) if self.exclude(options): return match = re.match(r'/(\w+)/([bcv])/(\d+)', urlp.path) if not match: data = self._get_channel(options, urlp) else: if match.group(2) in ["b", "c"]: log.error("This twitch video type is unsupported") return data = self._get_archive(options, match.group(3)) try: for i in data: yield i except JustinUrlException as e: log.debug(str(e)) log.error("This twitch video type is unsupported") return
def get_media(url, options, version="Unknown"): if "http" not in url[:4]: url = "http://%s" % url if options.get("verbose"): log.debug("version: {0}".format(version)) stream = service_handler(sites, options, url) if not stream: generic = Generic(options, url) url, stream = generic.get(sites) if not stream: if url.find(".f4m") > 0 or url.find(".m3u8") > 0: stream = Raw(options, url) if not stream: log.error( "That site is not supported. Make a ticket or send a message") sys.exit(2) if options.get("all_episodes"): get_all_episodes(stream, url) else: get_one_media(stream)
def download(self): """ Get the stream from RTMP """ args = [] if self.options.live: args.append("-v") if self.options.resume: args.append("-e") extension = re.search(r"(\.[a-z0-9]+)$", self.url) if self.options.output != "-": if not extension: self.options.output = "%s.flv" % self.options.output else: self.options.output = self.options.output + extension.group(1) log.info("Outfile: %s", self.options.output) if os.path.isfile(self.options.output) and not self.options.force: log.info("File already exists. use --force to overwrite") return args += ["-o", self.options.output] if self.options.silent or self.options.output == "-": args.append("-q") if self.options.other: if is_py2: args += shlex.split(self.options.other.encode("utf-8")) else: args += shlex.split(self.options.other) if self.options.verbose: args.append("-V") command = ["rtmpdump", "-r", self.url] + args log.debug("Running: %s", " ".join(command)) try: subprocess.call(command) except OSError as e: log.error("Could not execute rtmpdump: " + e.strerror)
def _download2(self, files, audio=False): cookies = self.kwargs["cookies"] if audio: file_d = output(copy.copy(self.options), "m4a") else: file_d = output(self.options, self.options.other) if hasattr(file_d, "read") is False: return if file_d == None: return eta = ETA(len(files)) n = 1 # check if we can resume a past download already_downloaded = os.fstat(file_d.fileno()).st_size if self.options.resume and already_downloaded != 0: print('Checking for existing segments...') bytes_so_far = 0 resumed = False data_size = 0 for i in files: if self.options.output != "-" and not self.options.silent: eta.increment() progressbar(len(files), n, ''.join(['ETA: ', str(eta)])) n += 1 # get segment size if self.options.resume and already_downloaded != 0: if bytes_so_far < already_downloaded: head_req = self.http.request("head", i, cookies=cookies) if head_req.status_code == 404: break data_size = int(head_req.headers['Content-Length']) bytes_so_far += data_size log.debug('Segment %d', n-1) log.debug('So far: %d, segment size: %d, on disk: %d', bytes_so_far - data_size, data_size, already_downloaded) if bytes_so_far >= already_downloaded: if not resumed and self.options.resume: print print('Resuming download on segment ' + str(n-1)) log.debug('Truncating output file to %d', bytes_so_far - data_size) file_d.truncate(bytes_so_far - data_size) # line up the file with a segment boundary eta = ETA(len(files) - n) resumed = True data = self.http.request("get", i, cookies=cookies) if data.status_code == 404: break data = data.content file_d.write(data) else: data = self.http.request("get", i, cookies=cookies) if data.status_code == 404: break data = data.content file_d.write(data) if self.options.output != "-": file_d.close() if not self.options.silent: progress_stream.write('\n') self.finished = True