def download(url): vid = YouTube(url).streams.filter(subtype='mp4', res='1080p') if (len(vid)): vid.first().download('/tmp') return 'Success' else: return 'Fail but ok'
def main(ass): yt = YouTube(str(ass)) image = yt.thumbnail_url yt = yt.streams.filter(progressive=True, file_extension="mp4") fileName = yt.first().default_filename reshaped_text = arabic_reshaper.reshape(fileName) bidi_text = get_display(reshaped_text) print("Start Download: " + bidi_text) yt.first().download() sleep(2) print("Finish Download the video") video = VideoFileClip(fileName) fileNameMp3 = fileName.replace("mp4", "mp3") video.audio.write_audiofile(fileNameMp3) video.close() sleep(2) audiofile = eyed3.load(fileNameMp3) if (audiofile.tag == None): audiofile.initTag() response = get(image) audiofile.tag.images.set(3, response.content, 'image/jpeg') audiofile.tag.save() move("./"+fileName, "./mp4s/"+fileName) pathToSaveMp3 = "Music/iTunes/iTunes Media/Automatically Add to iTunes/"+fileNameMp3 move("./"+fileNameMp3, os.path.join(os.path.expanduser("~"), pathToSaveMp3)) return
def download_video(self, url): myfile = self.desktop_path + os.sep + "myfile.mp4" os.remove(myfile) if os.path.exists(myfile) else None yt = YouTube(url).streams.filter(only_audio=True) yt.first().download(self.desktop_path, filename='myfile') print('done') self.my_song.play() print('done playing song') return
def download_video(url, raw_title, save_dir): logging.info(f'[downloading] \n\nurl: {url} \ntitle: {raw_title} \n') title = convert_title(raw_title) fname = f'{title}.mp4' os.makedirs(save_dir, exist_ok = True) streams = YouTube(url).streams.filter( progressive = True, file_extension = 'mp4', res = '720p' ) streams.first().download(save_dir, filename = fname) logging.info(f'[complete] \n\nurl: {url} \ntitle: {raw_title} \n') return None
def downloadFile(url): streams = YouTube(url).streams streams.filter(progressive=True).desc().first() name = streams.first().download() newname = name.replace(' ','_') os.rename(name,newname) return newname
def playlist(): try: playlist = [] url = input("Enter URL of the PLAYLIST: ") driver = webdriver.Edge(executable_path='msedgedriver.exe') driver.get(url) links = driver.find_elements_by_xpath("//a[@href]") for link in links: href = link.get_attribute("href") if href.startswith('https://www.youtube.com/watch?v='): playlist.append(href) driver.close() #Gets rid of duplicate links playlist = list(dict.fromkeys(playlist)) print("Length of playlist: " + str((len(playlist) - 2))) # outputs all the links in the playlist # for x in playlist: # print(x) # First link will be a duplicate with a different URL, because thats how YouTube playlists work # The algorithm of collecting a playlist is abstract, the beginning of every scrape there are 2 links that are songs, # but not actually indexed to the playlist, so we start from the third link, which is the beginning of the playlist name_pref = input("Do you want to rename these files? (y/n): ") if name_pref == 'y': for l in range(2, len(playlist)): youtube = YouTube(playlist[l]) print(youtube.title) video = youtube.first() file_download = video.download(directory_path) new_file_name = input("New file name: ") print((new_file_name + '.mp3')) # changes file to mp3 os.rename(file_download, (directory_path + '\\' + new_file_name + '.mp3')) try: os.remove(file_download) except: pass elif name_pref == 'n': for l in range(2, len(playlist)): youtube = YouTube(playlist[l]) # print(youtube.title + ' - ' + playlist[l]) print(youtube.title) video = youtube.streams.filter(only_audio=True).first() file_download = video.download(directory_path) # changes file to mp3 os.rename(file_download, file_download[0:-4] + '.mp3') print("Playlist downloaded successfully") except Exception as ex: print("Error: " + str(ex))
def downloadvid_createdir(list_of_youtube_videos): for i in range(len(list_of_youtube_videos)): try: temp = list_of_youtube_videos[i] temp = temp[32:] #creating folder for each video path = "/Video_Files/failure/{0}".format(temp) #downloading each video video_link = list_of_youtube_videos[i] yt = YouTube(video_link).streams.filter(progressive=True, file_extension='mp4') yt.order_by('resolution') yt.desc() #yt.first() #print(yt.title) os.makedirs(path) yt.first().download(path, filename='vid') except OSError: print("Creation of the directory %s failed" % path) else: print("Successfully created the directory %s " % path)
def download_video(url, path): ''' 완성된 URL을 받아(실제 동영상 실행 페이지) 동영상을 path에 1080p으로 다운로드합니다. 'https://www.youtube.com/watch?v=riI4FGbKN9k' ''' try: data = YouTube(url).streams ''' 1080p 기능 임시 비활성화 for s in data: if s.resolution == "1080p": return s.download(path) return data[0].download(path) ''' return data.first().download(path) except: return "ERROR"
def __scoutDownloadUrl(self, url): yt = YouTube(url).streams return yt.first().url
# @princesanjivy # download youtube videos using # pip install pytube from pytube import YouTube ytlink = input("video link: ") yt = YouTube(ytlink).streams yt.first().download() print("video saved!") # will be saved in current directory
def selectVideoResToDL(videoUrl, videotitle, fornumname): #init table Download_log print 'Download starting' if isCanDownload() == False: randomDelete() print 'hello---------------------------' #initDownloadLog() db = getConnectDB() cursor = db.cursor() cursor.execute('select count(*) from download_log where videotitle="' + videotitle + '"') count = cursor.fetchone()[0] if count == 0: videoid = str(uuid.uuid1()) isNewDirPath(str(getFid(cursor, fornumname))) yt720p = YouTube(videoUrl).streams.filter(res='720p') if yt720p.first() != None: print videotitle + ".mp4(720p) download starting" yt720p.first().download( output_path='/www/wwwroot/youtube.club/upload/videosource/' + str(getFid(cursor, fornumname)), filename=str(videoid)) writeDownloadLog(videoid, getFid(cursor, fornumname), fornumname, videotitle) #push website publishWebsite(videoid, fornumname, videotitle) # push website end else: yt360p = YouTube(videoUrl).streams.filter(res='360p') if yt360p.first() != None: print videotitle + ".mp4(360p) download starting" yt360p.first().download( output_path='/www/wwwroot/youtube.club/upload/videosource/' + str(getFid(cursor, fornumname)), filename=str(videoid)) writeDownloadLog(getFid(cursor, fornumname), fornumname, videotitle) # push website publishWebsite(fornumname, videotitle) # push website end else: yt240p = YouTube(videoUrl).streams.filter(res='240p') if (yt240p != None): print videotitle + ".mp4(360p) download starting" yt240p.first().download( output_path= '/www/wwwroot/youtube.club/upload/videosource/' + str(getFid(cursor, fornumname)), filename=str(videoid)) writeDownloadLog(getFid(cursor, fornumname), fornumname, videotitle) # push website publishWebsite(fornumname, videotitle) # push website end else: yt144p = YouTube(videoUrl).streams.filter(res='144p') if yt144p != None: print videotitle + ".mp4(144p) download starting" yt144p.first().download( output_path= '/www/wwwroot/youtube.club/upload/videosource/' + str(getFid(cursor, fornumname)), filename=str(videoid)) writeDownloadLog(getFid(cursor, fornumname), fornumname, videotitle) # push website publishWebsite(fornumname, videotitle) # push website end db.close() return