파일 관리 - 이미지 처리 - pdf

moviepy, pytube

나도초딩 2022. 10. 25.

목차

    -_-;; 4k 다운로더 쓰는게 훨씬 낫겠다. 장점이 없뜨아....

    https://pytube.io/en/latest/user/streams.html#filtering-by-streaming-method

    yt = YouTube(url)
    stream = yt.streams.get_highest_resolution()
    stream.download(DOWNLOAD_FOLDER)
    
    
    print("제목 : ", yt.title)
    print("길이 : ", yt.length)
    print("게시자 : ", yt.author)
    print("게시날짜 : ", yt.publish_date)
    print("조회수 : ", yt.views)
    print("키워드 : ", yt.keywords)
    print("설명 : ", yt.description)
    print("썸네일 : ", yt.thumbnail_url)
    
    p = Playlist('https://www.youtube.com/watch?v=ea7hkgs9DJo&list=PLsBObkGU9zQMirwoCV2lgHOl5fqXIlcxI')
    for video in p.videos:
        video.streams.first().download(DOWNLOAD_FOLDER)

     

    실제 코드

    import moviepy.editor as mpe
    import os
    import pytube
    
    vname = "clip.mp4"
    aname = "audio.mp3"
    
    # Download video and rename
    video = pytube.YouTube("https://www.youtube.com/watch?v=kJQP7kiw5Fk").streams.filter(
        subtype='mp4', res="1080p").first().download()
    os.rename(video, vname)
    
    # Download audio and rename
    audio = pytube.YouTube(
        "https://www.youtube.com/watch?v=kJQP7kiw5Fk").streams.filter(only_audio=True).first().download()
    os.rename(audio, aname)
    
    # Setting the audio to the video
    video = mpe.VideoFileClip(vname)
    audio = mpe.AudioFileClip(aname)
    final = video.set_audio(audio)
    
    # Output result
    final.write_videofile("video.mp4")
    
    # Delete video and audio to keep the result
    os.remove(vname)
    os.remove(aname)