diff --git a/requirements.txt b/requirements.txt index fc693c9..b0fabc1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/requirements_optional.txt b/requirements_optional.txt new file mode 100644 index 0000000..3025730 --- /dev/null +++ b/requirements_optional.txt @@ -0,0 +1 @@ +pytube \ No newline at end of file diff --git a/v2m.py b/v2m.py index fe0e18b..191be7f 100755 --- a/v2m.py +++ b/v2m.py @@ -7,6 +7,7 @@ import sys import os +import re filepath='' if ( len(sys.argv) < 2 ): @@ -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