Code:
import cv2
import os
import re
import urllib3
http = urllib3.PoolManager(maxsize=1, block=True)
directory = r'E:\Music\PMV'
n = 0
dlList = []
def getVideoHeight(path):
cv2video = cv2.VideoCapture(path)
return int(cv2video.get(cv2.CAP_PROP_FRAME_HEIGHT))
def processFile(filename, path):
global http
match = re.match('(?P<Id>\\d*)_(?P<Name>.*)\\.mp4', filename)
if not match:
print('skipping')
return
id = match.group('Id')
name = match.group('Name')
if not id or not name:
print('ERROR id or name')
return
print('id = ' + id + ', name = "' + name + '", ', end='')
name = name.replace(' ', '_')
url = r'**External links are only visible to Support Staff** + id + '/' + name
print('url = ' + url + ', ', end='')
r = http.request('GET', url)
if len(r.data) == 0:
print('ERROR url')
return
page = r.data.decode('utf-8')
hdMarkMatch = re.search('<span class=\\"video-hd-mark\\">(?P<resolution>\\d*)p<\\/span><\\/h2>', page)
if not hdMarkMatch:
print('not hi-res, skipping')
return
urlHeight = int(hdMarkMatch.group('resolution'))
print('res = ' + hdMarkMatch.group('resolution') + ', ', end='')
videoHeight = getVideoHeight(path)
print('vid res = ' + str(videoHeight) + ', ', end='')
if videoHeight >= urlHeight:
print('OK!!!')
return
else:
print('queued for dl.')
dlList.append(url)
for f in os.listdir(directory):
path = os.path.join(directory, f)
if os.path.isfile(path) and f.endswith('.mp4'):
n = n + 1
print(str(n) + '. ' + f + ': ', end='')
processFile(f, path)
print('DL list(' + str(len(dlList)) + '):')
for url in dlList:
print(url)