-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvcs-downloader.py
executable file
·53 lines (50 loc) · 1.58 KB
/
vcs-downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import urllib.request
import re
import ssl
if (len(sys.argv) > 1 and sys.argv[1]):
downloadUrl = sys.argv[1]
else:
downloadUrl = input("Please enter the Download URL: ")
downloadUrl = re.sub("_[0-9]{3}.ts", "", downloadUrl)
if (len(sys.argv) > 2 and sys.argv[2]):
filename = sys.argv[2] + ".ts"
else:
filename = input("File Name? (No ext and special chars): ") + ".ts"
print("Downloading from " + downloadUrl)
filesize = 100
i = 0
videodata = ""
context = ssl._create_unverified_context()
phpSessId = None
while filesize > 0:
numberStr = str(i)
if i < 10000:
numberStr = numberStr.zfill(3)
url = downloadUrl + "_"+ numberStr +".ts"
localFile = numberStr + ".ts"
#print(url)
print('.', end='',flush=True)
#urllib.request.urlretrieve(url, localFile)
try:
request = urllib.request.Request(url)
# Add login Cookie
if (phpSessId):
request.add_header("Cookie", "PHPSESSID=" + phpSessId)
response = urllib.request.urlopen(request, context=context)
ts = response.read()
filesize = len(ts)
tsfile = open(filename, 'ab')
tsfile.write(ts)
#filesize = os.stat(localFile).st_size
i = i + 1
except urllib.error.HTTPError as e:
if (e.code == 404):
if (i < 10):
phpSessId = input("Please enter the PHPSESSID Cookie: ")
else:
# Pretend filesize is 0 to exit loop
filesize = 0
else:
print('HTTP Error at', url, '| Code:', e.code)
print('Done downloading ' + localFile + '!')