forked from bikerider331/plugin.video.filelist.ro.api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flprovider.py
78 lines (55 loc) · 2.01 KB
/
flprovider.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
import urllib
from urllib import FancyURLopener
import xbmc
import json
import xbmcvfs
import os
class FireFoxAgent(FancyURLopener):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
class FLTorrentProvider:
def __init__(self, username, passkey):
self.username = username
self.passkey = passkey
def getLatestTorrentsByCategoryID(self, categoryId):
action="latest-torrents"
url = self.makeUrl(action)
url = url +"&category="+str(categoryId)
data = self.getData(url)
return data
def searchTorrents(self,searchType, query, categoryId):
action="search-torrents"
url = self.makeUrl(action)
url = url + "&type="+searchType
url = url + "&query="+query
if categoryId:
url = url + "&category="+categoryId
data = self.getData(url)
return data
def makeUrl(self, action):
url = "https://filelist.io/api.php?username="+self.username+"&passkey="+self.passkey+"&action="+action
return url
def getData(self, url):
xbmc.log("getData using url: "+url)
data = []
try:
agent = FireFoxAgent()
response = agent.open(url)
receivedData = response.read()
data = json.loads(receivedData)
except Exception as e:
xbmc.log("Error decoding json response from FL. Exception: "+str(e))
return data
def downloadTorrent(self, torrent, saveDir):
torrentPath = os.path.join(saveDir, torrent['name']+".torrent")
xbmc.log("Torrent path: "+torrentPath)
xbmcvfs.delete(torrentPath)
url = torrent['download_link']
xbmc.log("Download link: "+url)
agent = FireFoxAgent()
response = agent.open(url)
data = response.read()
response.close()
f = xbmcvfs.File(torrentPath, 'wb')
f.write(data)
f.close()
return torrentPath