Skip to content

Commit

Permalink
- Добавил опциональную возможность загружать видео напрямую с YouTube…
Browse files Browse the repository at this point in the history
… с помощью PyTube.

 для этого вместо имени файла указываете URL к видео на YouTube, к примеру: (./v2m.py "https://www.youtube.com/watch?v=BuHVVxvtl2s")
 с YouTube будет получен список актуальных форматов и отсортирован по приоритету в начале видео со звуком и по разрешению потока в убывающем порядке, после чего будет скачен первый файл в текущий каталог.
  • Loading branch information
svsdval committed May 4, 2024
1 parent a505f80 commit 54fc765
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIDIUtil==1.2.1
MIDIUtil>=1.2.1
opencv-python>=4.2.0.34
pygame==2.0.1
PyOpenGL==3.1.0
pygame>=2.0.1
PyOpenGL>=3.1.0
1 change: 1 addition & 0 deletions requirements_optional.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytube
25 changes: 23 additions & 2 deletions v2m.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sys
import os
import re

filepath=''
if ( len(sys.argv) < 2 ):
Expand All @@ -25,9 +26,29 @@
filepath = sys.argv[1]

if not os.path.exists( filepath ):
print("file not exists [" + filepath +"]")
sys.exit( 0 )
has_pytube = False

try:
from pytube import YouTube
has_pytube = True
except:
pass

if has_pytube:
print("Downloading video by url: %s ..." % filepath)
yt = YouTube( filepath )
videos = [ { 'itag' : i.itag, 'res' : int(re.sub('[^0-9]','', i.resolution)), 'progressive' : int(i.is_progressive) } for i in yt.streams.filter(file_extension='mp4') if i.mime_type.find("video") != -1 ]
print(videos)
videos = sorted( videos , key = lambda d : ( -d['progressive'], - d['res']) )
print('sorted by progressive (has video & audio in same file) and video resolution')
for i in videos:
print('processing: %s' % i)
filepath = "%s_%s_%s.mp4" % ( re.sub(r'[\W_]','_', yt.title), i['itag'], i['res'])
yt.streams.get_by_itag(i['itag']).download( "./" , filepath, skip_existing=True)
break
else:
print("file not exists [" + filepath +"], and no pytube has installed..., exit.")
sys.exit( 0 )

import math
import cv2
Expand Down

0 comments on commit 54fc765

Please sign in to comment.