示例#1
0
def _clip_target_filename(clip, args):
    date, time = clip["createdAt"].split("T")

    url = clip["videoQualities"][0]["sourceURL"]
    _, ext = path.splitext(url)
    ext = ext.lstrip(".")

    subs = {
        "channel": clip["broadcaster"]["displayName"],
        "channel_login": clip["broadcaster"]["login"],
        "date": date,
        "datetime": clip["createdAt"],
        "format": ext,
        "game": clip["game"]["name"],
        "game_slug": utils.slugify(clip["game"]["name"]),
        "id": clip["id"],
        "time": time,
        "title": utils.titlify(clip["title"]),
        "title_slug": utils.slugify(clip["title"]),
    }

    try:
        return args.output.format(**subs)
    except KeyError as e:
        supported = ", ".join(subs.keys())
        raise ConsoleError(
            "Invalid key {} used in --output. Supported keys are: {}".format(
                e, supported))
示例#2
0
文件: commands.py 项目: m4p/twitch-dl
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))
示例#3
0
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))
示例#4
0
文件: commands.py 项目: m4p/twitch-dl
def _video_target_filename(video, format):
    match = re.search(r"^(\d{4})-(\d{2})-(\d{2})T", video['published_at'])
    date = "".join(match.groups())

    name = "_".join([
        date,
        video['_id'][1:],
        video['channel']['name'],
        utils.slugify(video['title']),
    ])

    return video['_id'][1:] + "." + format
示例#5
0
def _video_target_filename(video, format):
    match = re.search(r"^(\d{4})-(\d{2})-(\d{2})T", video['publishedAt'])
    date = "".join(match.groups())

    name = "_".join([
        date,
        video['id'],
        video['creator']['login'],
        utils.slugify(video['title']),
    ])

    return name + "." + format
示例#6
0
def _video_target_filename(video, args):
    date, time = video['publishedAt'].split("T")

    subs = {
        "channel": video["creator"]["displayName"],
        "channel_login": video["creator"]["login"],
        "date": date,
        "datetime": video["publishedAt"],
        "format": args.format,
        "game": video["game"]["name"],
        "game_slug": utils.slugify(video["game"]["name"]),
        "id": video["id"],
        "time": time,
        "title": utils.titlify(video["title"]),
        "title_slug": utils.slugify(video["title"]),
    }

    try:
        return args.output.format(**subs)
    except KeyError as e:
        supported = ", ".join(subs.keys())
        raise ConsoleError(
            "Invalid key {} used in --output. Supported keys are: {}".format(
                e, supported))
示例#7
0
def _clip_target_filename(clip):
    url = clip["videoQualities"][0]["sourceURL"]
    _, ext = path.splitext(url)
    ext = ext.lstrip(".")

    match = re.search(r"^(\d{4})-(\d{2})-(\d{2})T", clip["createdAt"])
    date = "".join(match.groups())

    name = "_".join([
        date,
        clip["id"],
        clip["broadcaster"]["login"],
        utils.slugify(clip["title"]),
    ])

    return "{}.{}".format(name, ext)
示例#8
0
def _video_target_filename(video, format):
    match = re.search(r"^(\d{4})-(\d{2})-(\d{2})T", video['published_at'])
    date = "".join(match.groups())
    
    if os.name == "posix":
      name = date + " " + video['_id'][1:] + " " + video['channel']['name'] + " " + str(video.get('game').replace("/", "")) + " " + str(video.get('title').replace("/", "")) + " " + str(video.get("fps").get("chunked")) + " " + str(video.get("resolutions").get("chunked")) + " " + str(video.get("length"))
    else:
      name = date + " " + video['_id'][1:] + " " + video['channel']['name'] + " " + str(str(utils.slugify(video.get('game'))).replace("/", "")) + " " + str(str(utils.slugify(video.get('title'))).replace("/", "")) + " " + str(video.get("fps").get("chunked")) + " " + str(video.get("resolutions").get("chunked")) + " " + str(video.get("length"))
    
    print(name + "." + format)
      
    return name + "." + format
示例#9
0
def test_slugify():
    assert slugify("Foo Bar Baz") == "foo_bar_baz"
    assert slugify("  Foo   Bar   Baz  ") == "foo_bar_baz"
    assert slugify("Foo@{}[] Bar Baz!\"#$%&/()=?*+'🔪") == "foo_bar_baz"