-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.py
130 lines (118 loc) · 4.46 KB
/
lib.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
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Matteo'
import httplib
import json
import urllib
import requests
import urllib2, re
import config
import sys
def find_str(s, char):
index = 0
if char in s:
c = char[0]
for ch in s:
if ch == c:
if s[index:index+len(char)] == char:
return index
index += 1
return -1
def create_config():
info = {}
info['user'] = config.USER
info['pass'] = config.PASSWORD
return info
def create_cookie(info):
try:
req = urllib2.Request("https://www.alldebrid.com/api.php?action=info_user&login="+info['user']+"&pw="+info['pass'], None,
{'User-agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'})
response = urllib2.urlopen(req).read()
cookie = response.split('<cookie>')[-1].split('</cookie>')[0]
except Exception, e:
print "Error in cookie creation (check user and password setting)"
sys.exit(-1)
return cookie
def get_magnet():
magnet = raw_input("Insert magnet:\n")
return magnet
def create_upload_request(cookie, magnet):
UPLOAD_MAGNET_HEADER = {
'method': 'POST',
'url': 'http://upload.alldebrid.com/uploadtorrent.php',
'headers': { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' },
}
UPLOAD_PAYLOAD = {
'domain': config.URL_PAYLOAD_UPLOAD_MAGNET,
'uid': cookie,
'magnet': magnet
}
UPLOAD_PAYLOAD = urllib.urlencode(UPLOAD_PAYLOAD)
req = urllib2.Request(config.URL_UPLOAD_TORRENT, UPLOAD_PAYLOAD, UPLOAD_MAGNET_HEADER)
return req
def execute_upload_request(req):
response = urllib2.urlopen(req).read()
return response
def get_torrent_page(cookie):
try:
url = 'http://www.alldebrid.com/api/torrent.php?json=true'
header = {'Accept' : '*/*',
'Accept-Encoding' : 'gzip, deflate, sdch',
'Accept-Language' : 'it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4',
'Cache-Control' : 'no-cache',
'Connection' : 'keep-alive',
'Cookie' : 'lang=en; domain=com; uid='+cookie+'; ssl=0;',
'Host' : 'www.alldebrid.com',
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36'}
req = requests.get(url, headers=header)
return req.json()
except Exception, e:
print "Error in upload request (check header and req error in lib)"
sys.exit(-1)
def get_unlocked_link(url):
try:
URL_DOWNLOAD = "http://www.alldebrid.com/service.php?pseudo="+config.USER+"&password="+config.PASSWORD+"&link="+url
return urllib2.urlopen(URL_DOWNLOAD).read()
except Exception, e:
print "Error in retrieving upload download link (check url error in lib)"
sys.exit(-1)
def get_unlocked_torrent(json):
torrents_unlocked = {}
counter = 0
for i in json:
# get info
index = 3
for k in i[4:]:
k = str(k)
if "a" in k or "img" in k:
break
else:
index += 1
infos = i[4:index+1]
if len(infos) > 0:
status = str(infos[0])
downloaded = str(infos[1])
filesize = str(infos[2])
seeders = str(infos[3])
speed = str(infos[4])
adding_date = str(infos[5])
# get data
url = i[-2][10:41]
name = i[3][find_str(i[3], "'>")+2 : find_str(i[3], "</")]
# unlocked = get_unlocked_link(url)
# first_ = find_str(unlocked, "href='")+6
# second_ = find_str(unlocked, "' style='")
# download_link = unlocked[first_ : second_]
# third_ = str(download_link).rindex("/")+1
# name = download_link[third_:]
torrents_unlocked[counter] = {'name' : name,
'download' : url,
'status' : status,
'downloaded' : downloaded,
'filesize' : filesize,
'seeders' : seeders,
'speed' : speed,
'adding_date' : adding_date
}
counter += 1
return torrents_unlocked