def _download_clip(slug, args): print_out("<dim>Looking up clip...</dim>") clip = twitch.get_clip(slug) if not clip: raise ConsoleError("Clip '{}' not found".format(slug)) print_out( "Found: <green>{}</green> by <yellow>{}</yellow>, playing <blue>{}</blue> ({})" .format(clip["title"], clip["broadcaster"]["displayName"], clip["game"]["name"], utils.format_duration(clip["durationSeconds"]))) url = _get_clip_url(clip, args) print_out("<dim>Selected URL: {}</dim>".format(url)) url_path = urlparse(url).path extension = Path(url_path).suffix filename = "{}_{}{}".format(clip["broadcaster"]["login"], utils.slugify(clip["title"]), extension) print_out("Downloading clip...") download_file(url, filename) print_out("Downloaded: {}".format(filename))
def _download_clip(slug, args): print_out("<dim>Looking up clip...</dim>") clip = twitch.get_clip(slug) print_out("Found: <green>{}</green> by <yellow>{}</yellow>, playing <blue>{}</blue> ({})".format( clip["title"], clip["broadcaster"]["displayName"], clip["game"]["name"], utils.format_duration(clip["durationSeconds"]) )) print_out("\nAvailable qualities:") qualities = clip["videoQualities"] for n, q in enumerate(qualities): print_out("{}) {} [{} fps]".format(n + 1, q["quality"], q["frameRate"])) no = utils.read_int("Choose quality", min=1, max=len(qualities), default=1) selected_quality = qualities[no - 1] url = selected_quality["sourceURL"] url_path = urlparse(url).path extension = Path(url_path).suffix filename = "{}_{}{}".format( clip["broadcaster"]["login"], utils.slugify(clip["title"]), extension ) print("Downloading clip...") download_file(url, filename) print("Downloaded: {}".format(filename))
def _download_clip(slug, args): print_out("<dim>Looking up clip...</dim>") clip = twitch.get_clip(slug) if not clip: raise ConsoleError("Clip '{}' not found".format(slug)) print_out( "Found: <green>{}</green> by <yellow>{}</yellow>, playing <blue>{}</blue> ({})" .format(clip["title"], clip["broadcaster"]["displayName"], clip["game"]["name"], utils.format_duration(clip["durationSeconds"]))) target = _clip_target_filename(clip, args) print_out("Target: <blue>{}</blue>".format(target)) if not args.overwrite and path.exists(target): response = input("File exists. Overwrite? [Y/n]: ") if response.lower().strip() not in ["", "y"]: raise ConsoleError("Aborted") args.overwrite = True url = get_clip_authenticated_url(slug, args.quality) print_out("<dim>Selected URL: {}</dim>".format(url)) print_out("<dim>Downloading clip...</dim>") download_file(url, target) print_out("Downloaded: <blue>{}</blue>".format(target))
def _print_progress(futures): downloaded_count = 0 downloaded_size = 0 max_msg_size = 0 start_time = datetime.now() total_count = len(futures) for future in as_completed(futures): size = future.result() downloaded_count += 1 downloaded_size += size percentage = 100 * downloaded_count // total_count est_total_size = int(total_count * downloaded_size / downloaded_count) duration = (datetime.now() - start_time).seconds speed = downloaded_size // duration if duration else 0 remaining = (total_count - downloaded_count) * duration / downloaded_count msg = " ".join([ "Downloaded VOD {}/{}".format(downloaded_count, total_count), "({}%)".format(percentage), "<cyan>{}</cyan>".format(format_size(downloaded_size)), "of <cyan>~{}</cyan>".format(format_size(est_total_size)), "at <cyan>{}/s</cyan>".format(format_size(speed)) if speed > 0 else "", "remaining <cyan>~{}</cyan>".format(format_duration(remaining)) if speed > 0 else "", ]) max_msg_size = max(len(msg), max_msg_size) print_out("\r" + msg.ljust(max_msg_size), end="")
def print_video(video): published_at = video['published_at'].replace('T', ' @ ').replace('Z', '') length = utils.format_duration(video['length']) name = video['channel']['display_name'] print_out("\n<bold>{}</bold>".format(video['_id'][1:])) print_out("<green>{}</green>".format(video["title"])) print_out("<cyan>{}</cyan> playing <cyan>{}</cyan>".format( name, video['game'])) print_out("Published <cyan>{}</cyan> Length: <cyan>{}</cyan> ".format( published_at, length)) print_out("<i>{}</i>".format(video["url"]))
def print_clip(clip): published_at = clip["createdAt"].replace("T", " @ ").replace("Z", "") length = utils.format_duration(clip["durationSeconds"]) channel = clip["broadcaster"]["channel"]["displayName"] playing = ("playing <blue>{}</blue>".format(clip["game"]["name"]) if clip["game"] else "") print_out("\n<b>{}</b>".format(clip["slug"])) print_out("<green>{}</green>".format(clip["title"])) print_out("<blue>{}</blue> {}".format(channel, playing)) print_out("Published <blue>{}</blue>" " Length: <blue>{}</blue>" " Views: <blue>{}</blue>".format(published_at, length, clip["viewCount"])) print_out("<i>{}</i>".format(clip["url"]))
def print_video(video): published_at = video["publishedAt"].replace("T", " @ ").replace("Z", "") length = utils.format_duration(video["lengthSeconds"]) channel = video["creator"]["channel"]["displayName"] playing = ("playing <blue>{}</blue>".format(video["game"]["name"]) if video["game"] else "") # Can't find URL in video object, strange url = "https://www.twitch.tv/videos/{}".format(video["id"]) print_out("\n<b>{}</b>".format(video["id"])) print_out("<green>{}</green>".format(video["title"])) print_out("<blue>{}</blue> {}".format(channel, playing)) print_out("Published <blue>{}</blue> Length: <blue>{}</blue> ".format( published_at, length)) print_out("<i>{}</i>".format(url))
def _download_clip(slug, args): print_out("<dim>Looking up clip...</dim>") clip = twitch.get_clip(slug) if not clip: raise ConsoleError("Clip '{}' not found".format(slug)) print_out( "Found: <green>{}</green> by <yellow>{}</yellow>, playing <blue>{}</blue> ({})" .format(clip["title"], clip["broadcaster"]["displayName"], clip["game"]["name"], utils.format_duration(clip["durationSeconds"]))) url = _get_clip_url(clip, args) print_out("<dim>Selected URL: {}</dim>".format(url)) target = _clip_target_filename(clip) print_out("Downloading clip...") download_file(url, target) print_out("Downloaded: {}".format(target))