-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
123 lines (102 loc) · 4 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from flask import Flask
from flask import request
import json,requests,random
#from pprint import pprint
app = Flask(__name__)
@app.route('/download',methods=['POST'])
def download_sub():
try :
# VARIABLES
global token
req = request.form.to_dict()
id = str(req['id'])
try:
fname = str(req['filename'])
except :
pass
try:
language = str(req['language'])
except:
language = 'en'
# API LIST
api_list= ['8N3cWyJvYvWL5KDLxt0aKzu4vhNkUCnr','1J8MVetljab3wYO4ancDmuk0We1RieMB']
api = random.choice(list(api_list))
# LOGIN TO GET TOKEN
token_url ="https://api.opensubtitles.com/api/v1/login"
token_headers ={
'Api-Key':api,
'content-type': 'application/json'
}
token_data ={
'username': 'filmvision',
'password': 'filmvision'
}
token_req = requests.post(token_url, data= json.dumps(token_data), headers=token_headers)
token_req_json = token_req.json()
if token_req.status_code == 200:
token = token_req_json['token']
else :
token = "None"
# GENERATING DOWNLOAD URL & HANDLING RESPONSES
download_url = "https://www.opensubtitles.com/api/v1/download"
download_headers = {
'Api-Key': api,
'Authorization': token ,
'content-type': 'application/json'
}
download_file_id = {'file_id': id}
download_response = requests.post(download_url, data=json.dumps(download_file_id), headers=download_headers)
download_json_response = download_response.json()
if (download_response.status_code == 200) :
print ("\n\n# Successful :: 200 \n")
r = {
'response':200,
'link': download_json_response['link'],
'remaining': download_json_response['remaining']
}
return (json.dumps(r))
else :
if 'remains' in download_response:
r ={
'again' : 'true',
'response' : download_response.status_code,
'message' : download_json_response['message']
}
else:
try:
r ={
'again' : 'false',
'response' : download_response.status_code,
'message' : download_json_response['message']
}
except:
r ={
'response' : download_response.status_code
}
return (json.dumps(r))
except Exception as e:
error = (f"Error detected on filmvision download server ::: {e}")
h = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Apikey eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1Yzc5NjAyMC1hNTM5LTExZWMtYjhhYy04Zjk2YjExMDNmYzkiLCJzdWIiOiJTSE9VVE9VVF9BUElfVVNFUiIsImlhdCI6MTY0NzQ0MjYzMiwiZXhwIjoxOTYzMDYxODMyLCJzY29wZXMiOnsiYWN0aXZpdGllcyI6WyJyZWFkIiwid3JpdGUiXSwibWVzc2FnZXMiOlsicmVhZCIsIndyaXRlIl0sImNvbnRhY3RzIjpbInJlYWQiLCJ3cml0ZSJdfSwic29fdXNlcl9pZCI6IjY2MDE5Iiwic29fdXNlcl9yb2xlIjoidXNlciIsInNvX3Byb2ZpbGUiOiJhbGwiLCJzb191c2VyX25hbWUiOiIiLCJzb19hcGlrZXkiOiJub25lIn0.nwgRCXa-tQ6s9L-n6QRjFlfqR11UPjIj3Solr43Weck'
}
d = {
"source": "ShoutDEMO",
"destinations": [
"945656567"
],
"transports": [
"sms"
],
"content": {
"sms": error
}
}
r = requests.post('https://api.getshoutout.com/coreservice/messages', data= json.dumps(d) ,headers = h)
res ={
'response' : 503
}
return (json.dumps(res))
if __name__ == '__main__':
app.run(debug=True)