-
Notifications
You must be signed in to change notification settings - Fork 0
/
getsub.py
38 lines (29 loc) · 973 Bytes
/
getsub.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
import sys
import time
import os
import hashlib
import requests
user_agent = {'User-Agent': "SubDB/1.0 (getsub/0.1; http:https://github.com/trecuu/getsub)"}
language = 'pt,en'#selected languages
videoFile = str(sys.argv[1]) #file location ex.: C:\Downloads\Video.mkv
def get_hash(name):
readsize = 64 * 1024
with open(name, 'rb') as f:
size = os.path.getsize(name)
data = f.read(readsize)
f.seek(-readsize, os.SEEK_END)
data += f.read(readsize)
return hashlib.md5(data).hexdigest()
def get_sub(fileHash, language):
url = 'http:https://api.thesubdb.com/?action=download&hash='+fileHash+'&language='+language
url = requests.get(url, headers=user_agent)
if str(url.status_code) == '404':
print ('Not Found')
elif str(url.status_code) == '400':
print ('Bad Request')
elif str(url.status_code) == '200':
open(videoFile[:-4]+'.srt', 'wb').write(url.content)
print ('SUB DOWNLOADED!')
videoHash = get_hash(videoFile)
get_sub(videoHash,language)
time.sleep(1)