diff --git a/demo/youtube/octotube.py b/demo/youtube/octotube.py index 4b9fb15..08e8e70 100644 --- a/demo/youtube/octotube.py +++ b/demo/youtube/octotube.py @@ -14,13 +14,14 @@ import time from argparse import ArgumentParser from threading import Thread +from typing import * import pvoctopus -from pytube import YouTube +from yt_dlp import YoutubeDL class ProgressAnimation(Thread): - def __init__(self, prefix, step_sec=0.1): + def __init__(self, prefix: str, step_sec: float = 0.1): self._prefix = prefix self._step_sec = step_sec self._frames = [ @@ -48,17 +49,19 @@ def stop(self): self._done = True -def download(url: str, folder: str) -> str: - webm_path = os.path.join(folder, '%s.webm' % url.split("watch?v=")[1]) - if not os.path.exists(webm_path): - anime = ProgressAnimation('Downloading %s' % url) - anime.start() - youtube = YouTube(url) - audio_stream = youtube.streams.filter(only_audio=True, audio_codec='opus').order_by('bitrate').last() - audio_stream.download(output_path=folder, filename=os.path.basename(webm_path), skip_existing=True) - anime.stop() - - return webm_path +def download(url: str, output_dir: str) -> str: + ydl_opts = { + 'outtmpl': "%(id)s.%(ext)s", + 'format': 'bestaudio', + 'paths': { + 'home': output_dir + }, + 'geo_bypass': True + } + with YoutubeDL(ydl_opts) as ydl: + info = ydl.sanitize_info(ydl.extract_info(url, download=False)) + ydl.download([url]) + return os.path.join(output_dir, f"{info['id']}.webm") def main(): @@ -70,7 +73,7 @@ def main(): parser.add_argument('--work-folder', default=os.path.expanduser('~/')) args = parser.parse_args() - webm_path = download(url=args.url, folder=args.work_folder) + webm_path = download(url=args.url, output_dir=args.work_folder) o = pvoctopus.create(access_key=args.access_key) diff --git a/demo/youtube/requirements.txt b/demo/youtube/requirements.txt index 5cda740..d7b608e 100644 --- a/demo/youtube/requirements.txt +++ b/demo/youtube/requirements.txt @@ -1,2 +1,2 @@ pvoctopus -pytube \ No newline at end of file +yt-dlp \ No newline at end of file diff --git a/res/spell-check/dict.txt b/res/spell-check/dict.txt index c35d8fa..ba31aab 100644 --- a/res/spell-check/dict.txt +++ b/res/spell-check/dict.txt @@ -1,4 +1,5 @@ Autocorrection +bestaudio CMAKE Cocoapods Compat @@ -29,15 +30,16 @@ magnifyingglass manzana octopusdemo octotube +outtmpl perroquet porco porcospino pvbase pvoctopus pvoctopusdemo -pytube recyclerview reindex wargv whitespaces -xcworkspace \ No newline at end of file +xcworkspace +ytdlp \ No newline at end of file