예제 #1
0
파일: conftest.py 프로젝트: Twixes/pytube3
def load_and_init_from_playback_file(filename):
    """Load a gzip json playback file and create YouTube instance."""
    pb = load_playback_file(filename)
    yt = YouTube(pb["url"], defer_prefetch_init=True)
    yt.watch_html = pb["watch_html"]
    yt.js = pb["js"]
    yt.vid_info = pb["video_info"]
    yt.descramble()
    return yt
예제 #2
0
파일: ppytube.py 프로젝트: jsmoon/ppye
def ppytube_download(url: str, mime_type: str):
    try:
        from pytube import extract
        extract.video_id(url)
    except Exception as e:
        sys.exit("Unsupported URL -- {}\n{}".format(url, e))

    try:
        #object creation using YouTube which was imported in the beginning
        yt = YouTube(url, defer_prefetch_init=True)
        yt.prefetch()
        yt.descramble()
    except Exception as e:
        sys.exit("YouTube Init Error -- {}\n{}".format(url, e))

    if len(yt.streams) == 0:
        sys.exit("No streams")

    try:
        print('{}'.format(yt.title))
        streams = [
            st for st in yt.streams if st.mime_type.startswith(mime_type)
        ]
        stream = streams[0]
        if len(streams) > 1:
            from pprint import pprint
            for st in streams:
                pprint(st)
            itag = input("Select itag (default:{}): ".format(stream.itag))
            if itag:
                stream = [st for st in streams if st.itag is int(itag)][0]
    except Exception as e:
        sys.exit("No stream specified\n{}".format(e))

    try:
        print('From {}'.format(stream.url))
        stream.download()
    except Exception as e:
        sys.exit("Download Failed! -- {}\n{}".format(url, e))

    print('Download Completed!')