Skip to content

Commit

Permalink
move pytube to ytdlp (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Jul 6, 2023
1 parent 4fba49d commit 5689981
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
31 changes: 17 additions & 14 deletions demo/youtube/octotube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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():
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion demo/youtube/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pvoctopus
pytube
yt-dlp
6 changes: 4 additions & 2 deletions res/spell-check/dict.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Autocorrection
bestaudio
CMAKE
Cocoapods
Compat
Expand Down Expand Up @@ -29,15 +30,16 @@ magnifyingglass
manzana
octopusdemo
octotube
outtmpl
perroquet
porco
porcospino
pvbase
pvoctopus
pvoctopusdemo
pytube
recyclerview
reindex
wargv
whitespaces
xcworkspace
xcworkspace
ytdlp

0 comments on commit 5689981

Please sign in to comment.