提问人:LukaGujabidze 提问时间:10/11/2023 更新时间:10/11/2023 访问量:114
如何使用 pytube 使用 python 下载有年龄限制的视频(音乐)
How to download age restricted videos(musics) with python using pytube
问:
我已经制作了可以下载mp4视频并将其导出到mp3的代码。您可以选择要下载的内容、播放列表或视频。 我尝试过:在我的代码中,所以它会尝试下载视频,但如果年龄限制,它会跳过它。 我怎样才能下载有年龄限制的视频。 这是我的代码:
from pytube import *
from moviepy.editor import *
import os
choice = input('What do you want to dowload playlist or the video? (P,V) ')
if choice == 'V':
#ask for the link from user
link = input("Enter the link of YouTube video you want to download: ")
yt = YouTube(link)
#Showing details
print("Title: ",yt.title)
print("Number of views: ",yt.views)
print("Length of video: ",yt.length)
print("Author of video: ",yt.author)
print("Rating of video: ",yt.rating)
try:
#Getting the highest resolution possible
youtube_stream = yt.streams.get_highest_resolution()
#Starting download
print("Downloading...")
youtube_stream.download()
print("Download completed!!")
# Load the mp4 file
video = VideoFileClip(f"{yt.title}.mp4")
# Extract audio from video
video.audio.write_audiofile(f"{yt.title}.mp3")
except:
print('Sorry, this video is age restricted.')
elif choice == 'P':
restricted_videos = []
restricted_videos_links = []
playlist = input('Enter your playlist link: ')
playlist = Playlist(playlist)
print('NOTE: if your video is age restricted it won\'t be downloaded! \n')
for video in playlist.videos:
try:
print(f'Downloading {video.title}...')
video_stream = video.streams.get_highest_resolution()
video_stream.download()
print('Downloaded.')
# Load the mp4 file
new_video = VideoFileClip(f"{video.title}.mp4")
new_video.audio.write_audiofile(f"{video.title}.mp3")
except:
print(f'This video: {video.title} is age restricted!')
restricted_videos.append(video.title)
restricted_videos_links.append(str(video))
pass
restricted_videos_names = '\n'.join(restricted_videos)
print(f'Video titles they hasn\'t been downloaded: {restricted_videos_names}')
提前致谢!
答: 暂无答案
评论