Example #1
0
def download(youtube_id):
    temp_dir = tempfile.mkdtemp()

    # Fake up a YouTube URL since youtube-dl expects one
    youtube_url = "http://www.youtube.com/watch?v={0}".format(youtube_id)

    video_filename_template = youtube_id + ".%(ext)s"
    video_path_template = os.path.join(temp_dir, video_filename_template)

    # Download a copy of the video from YouTube, but limit the resolution to
    # no more than "720p".  For details on the '--format' option, see
    # https://github.com/rg3/youtube-dl/blob/master/README.md#format-selection
    command_args = ["python", "youtube-dl/youtube-dl.py", "--format",
                    "best[height<=720]", "-icw", "-o", video_path_template,
                    youtube_url]
    results = popen_results(command_args)
    logger.info(results)

    files = os.listdir(temp_dir)
    if not files:
        return
    assert len(files) == 1
    video_path = os.path.join(temp_dir, files[0])
    logger.info(video_path)

    return video_path
Example #2
0
def download(youtube_id):
    temp_dir = tempfile.mkdtemp()

    # Fake up a YouTube URL since youtube-dl expects one
    youtube_url = "http://www.youtube.com/watch?v={0}".format(youtube_id)

    video_filename_template = youtube_id + ".%(ext)s"
    video_path_template = os.path.join(temp_dir, video_filename_template)

    # Download a copy of the video from YouTube, but limit the resolution to
    # no more than "720p".  For details on the '--format' option, see
    # https://github.com/rg3/youtube-dl/blob/master/README.md#format-selection
    command_args = [
        "python", "youtube-dl/youtube-dl.py", "--format", "best[height<=720]",
        "-icw", "-o", video_path_template, youtube_url
    ]
    results = popen_results(command_args)
    logger.info(results)

    files = os.listdir(temp_dir)
    if not files:
        return
    assert len(files) == 1
    video_path = os.path.join(temp_dir, files[0])
    logger.info(video_path)

    return video_path
Example #3
0
def download(youtube_id):
    temp_dir = tempfile.mkdtemp()

    # Fake up a YouTube URL since youtube-dl expects one
    youtube_url = "http://www.youtube.com/watch?v={0}".format(youtube_id)

    video_filename_template = youtube_id + ".%(ext)s"
    video_path_template = os.path.join(temp_dir, video_filename_template)

    command_args = ["python", "youtube-dl/youtube-dl.py", "--max-quality", "22", "-icw", "-o", video_path_template, youtube_url]
    results = popen_results(command_args)
    logger.info(results)

    files = os.listdir(temp_dir)
    assert len(files) == 1
    video_path = os.path.join(temp_dir, files[0])
    logger.info(video_path)

    return video_path