def download(): youtube_link = input("Enter The Link of youtube video ? ") print("1 - 360p") print("2 - 720p") quality = input("choose [1-2]: ") if (quality == "1"): downloader.download_video(youtube_link, "360p") elif (quality == "2"): downloader.download_video(youtube_link, "720p") else: print("Wrong Choice")
def loopify(_id, path, url=None, sound=True, stabilize=True): # define our callback for updating the job progress def update_record(status=None, progress=None): if status is not None: record.status = status if progress is not None: record.progress = progress db.session.commit() record = Record.query.get(_id) # do the work try: # download the video, if necessary if url is not None: record.status = 'Downloading video...' db.session.commit() # download the youtube video download_video(url, path, record.start_seconds, record.end_seconds) # correct the seconds offsets for a ~30 second video # because the downloaded video already starts at record.start_seconds record.end_seconds = record.end_seconds - record.start_seconds record.start_seconds = 0 record.status = 'Loopifying...' db.session.commit() result = make_loops(path, callback=update_record, start_time=record.start_seconds, end_time=record.end_seconds, sound_enabled=sound) for r in result: video = Video(webm_location=os.path.basename(r.webm_location), gif_location=os.path.basename(r.gif_location), mp4_location=os.path.basename(r.mp4_location), score=r.score, start_frame=r.start_frame_number, end_frame=r.end_frame_number, record_id=record.id) db.session.add(video) except Exception as e: sentry_sdk.capture_exception() logger.exception('Job loopify failed') record.failed = True finally: record.done = True record.finished_at = datetime.utcnow() db.session.commit()
def get(self): link = self.get_argument('link') path = os.path.join('mp4cache/', sha_hash(link)) if not os.path.exists(path): try: downloader.download_video(link) except Exception: self.set_status(404, 'Not Found') self.set_header('Content-Type', 'text/html') with open('web/404-video.html') as fin: self.smart_write(fin.read()) self.finish() return self.set_status(200, 'OK') self.set_header('Content-Type', 'application/octet-stream') with open(path, 'rb') as fin: self.smart_write(fin.read()) self.finish()
def click_button(): # obtém os textos url = entry_url.get() name_video = entry_name_video.get() # se a função retornar 'True' if download_video(url, name_video): msg['fg'] = 'Green' msg['text'] = 'Download feito com sucesso!' else: msg['fg'] = 'Red' msg['text'] = 'Ocorreu alguma falha... :('
def index(): form = DownloadForm(request.form) if request.method == 'POST' and form.validate_on_submit(): url = form.url.data media_format = form.media_format.data download_token = form.download_token.data if media_format == 'video': filename = download_video(url) else: filename = download_music(url) response = make_response( send_from_directory('./data', filename, as_attachment=True)) response.set_cookie('download_token', download_token) return response return render_template('index.html', form=form, redirect_url=url_for('index'))
def download_video(update, context): db = DBManager() url = update.message.text chat_id = update.message.chat_id quality = db.get_chat_quality(chat_id) username = str(update.message.from_user.username) if is_url(url) is False: update.message.reply_text('Enter Url please') return file_id = db.get_url_file_id(url, quality) if file_id: update.message.reply_audio(file_id) db.insert_user_request(url, username) context.bot.send_message(chat_id=owner_chat_id, text=TELEGRAM_LOG.format(username, url)) return try: meta = downloader.download_video(url, quality) except youtube_dl.utils.DownloadError as e: update.message.reply_text(str(e)) return audio_file = open(meta.file_name, 'rb') cover = open(meta.cover, 'rb') response = update.message.reply_audio( audio_file, title=meta.meta.get('title', None), performer=meta.meta.get('uploader', None), duration=meta.meta.get('duration', None), caption=meta.meta.get('title', None), thumb=cover) context.bot.send_message(chat_id=owner_chat_id, text=TELEGRAM_LOG.format(username, url)) db.insert_file_id(url, response['audio']['file_id'], quality) db.insert_user_request(url, username) os.remove(meta.file_name) os.remove(meta.cover)
filename='music-yt.log', filemode='w') console = logging.StreamHandler() console.setLevel(logging.INFO) formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) if __name__ == '__main__': setup_logging() for playlist_id,playlist_name in get_list_of_playlists(): if playlist_name.startswith("Music"): for video in get_videos_from_playlist(playlist_id): if video in utils.downloaded_videos: logging.info("Already downloaded video : " + video + ". Skipping.") continue try: m4a_file = download_video(video) if m4a_file is None or len(m4a_file) == 0: logging.error("Skipping : " + video + " because it was not downloaded") continue except Exception, e: logging.error("Could not download video : " + video) logging.error(e) continue mp3_file = mp3_encode(m4a_file) tags.set_video_name(mp3_file, video) os.remove(m4a_file) add_all_tags(mp3_file)
def download_video(self, video_info): """Task for downloading the requested video and updating the request in the DB""" video_info['celery_id'] = self.request.id downloader.download_video(video_info)
print("Welcome to YouTube Downloader") print("Loading...") import pytube import downloader print(''' What do you want? (1) Download YouTube Videos Manually (2) Download a YouTube Playlist ''') choice = input("Choice: ") if choice == "1" or choice == "2": quality = input("Please choose a quality (low, medium, high, very high):") if choice == "2": link = input("Enter the link to the playlist: ") print("Downloading playlist...") downloader.download_playlist(link, quality) print("Download finished!") if choice == "1": links = downloader.input_links() for link in links: downloader.download_video(link, quality) else: print("Invalid input! Try Again...")