window torrent browser and play

This commit is contained in:
DiMartinoXBMC committed 2016-11-27 16:12:06 +03:00
1 parent a20b7d2069
commit 81d4e22eed
2 files changed
+190 -53

No files matched your search

+57
View File
@@ -44,6 +44,7 @@ __settings__ = xbmcaddon.Addon(id='plugin.video.torrenter')
__language__ = __settings__.getLocalizedString
ROOT = __settings__.getAddonInfo('path') # .decode('utf-8').encode(sys.getfilesystemencoding())
userStorageDirectory = __settings__.getSetting("storage")
torrentFilesDirectory = 'torrents'
USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"
__addonpath__ = __settings__.getAddonInfo('path')
icon = os.path.join(__addonpath__, 'icon.png')
@@ -1309,6 +1310,62 @@ def search(url, searchersList, isApi=None):
filesList.extend(result[k])
return filesList
def get_filesList(query, addtime = None):
if __settings__.getSetting('history')=='true':
HistoryDB().add(query)
searchersList = []
if addtime:
providers=HistoryDB().get_providers(addtime)
if providers:
for searcher in providers:
searchersList.append(searcher)
if not addtime or not searchersList:
searchersList = Searchers().get_active()
filesList=search(query, searchersList)
if __settings__.getSetting('sort_search')=='true':
__settings__.setSetting('sort_search','1')
if int(__settings__.getSetting('sort_search'))==0:
filesList = sorted(filesList, key=lambda x: x[0], reverse=True)
elif int(__settings__.getSetting('sort_search'))==2:
filesList = sorted(filesList, key=lambda x: x[4], reverse=False)
debug('get_filesList filesList: '+str(filesList))
return filesList
def get_contentList(url):
import Downloader
url = urllib.unquote_plus(url)
__settings__.setSetting("lastTorrentUrl", url)
classMatch = re.search('(\w+)::(.+)', url)
if classMatch:
searcher = classMatch.group(1)
url = Searchers().downloadWithSearcher(classMatch.group(2), searcher)
__settings__.setSetting("lastTorrent", url)
torrent = Downloader.Torrent(userStorageDirectory, torrentFilesDirectory=torrentFilesDirectory)
__settings__.setSetting("lastTorrent", torrent.saveTorrent(url))
append_filesize = __settings__.getSetting("append_filesize") == 'true'
contentList = []
for filedict in torrent.getContentList():
fileTitle = filedict.get('title')
size = filedict.get('size')
if size:
if append_filesize:
fileTitle += ' [%d MB]' % (size / 1024 / 1024)
contentList.append([unescape(fileTitle), str(filedict.get('ind')), size])
# contentList = sorted(contentList, key=lambda x: x[0])
debug('get_contentList contentList: ' + str(contentList))
return contentList
def join_list(l, char=', ', replace=''):
string=''
+133 -53
View File
@@ -17,12 +17,12 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import sys, os, urllib
import sys, os, urllib, json
import xbmcaddon
import xbmc
import xbmcgui
from functions import search, HistoryDB, Searchers, log
from functions import get_filesList, HistoryDB, get_contentList, log, cutFolder, get_ids_video
import pyxbmct.addonwindow as pyxbmct
import Localization
@@ -38,6 +38,12 @@ log('SYS ARGV: ' + str(sys.argv))
class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
__settings__ = sys.modules["__main__"].__settings__
fileList = []
contentList = []
right_buttons_count = 6
last_right_buttons_count = 0
last_link = None
last_query = None
last_action = None
def __init__(self, title=""):
super(MultiChoiceDialog, self).__init__(title)
@@ -51,14 +57,12 @@ class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
return '%s/icons/%s.png' %(__root__, icon)
def set_controls(self):
self.input_search = pyxbmct.Edit("")
self.input_search = pyxbmct.Edit("", _alignment=pyxbmct.ALIGN_CENTER_X | pyxbmct.ALIGN_CENTER_Y)
self.placeControl(self.input_search, 0, 0, 1, 5)
self.button_search = pyxbmct.Button("Search")
self.placeControl(self.button_search, 0, 5, 1, 2)
self.button_history = pyxbmct.Button("History")
self.placeControl(self.button_history, 0, 7, 1, 2)
self.button_right1 = pyxbmct.Button("Open")
self.placeControl(self.button_right1, 1, 14, 1, 2)
self.right_menu()
self.listing = pyxbmct.List(_imageWidth=40, _imageHeight=40, _itemTextXOffset=10, _itemTextYOffset=2, _itemHeight=40, _space=2, _alignmentY=4)
@@ -69,79 +73,108 @@ class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
self.connect(self.listing, self.press)
self.connect(self.button_history, self.history)
self.connect(self.button_search, self.search)
#self.connectEventList([ACTION_ENTER], self.search)
def set_navigation(self):
#Top menu
self.input_search.setNavigation(self.listing, self.listing, self.button_history, self.button_search)
self.input_search.setNavigation(self.listing, self.listing, self.button_right1, self.button_search)
self.button_search.setNavigation(self.listing, self.listing, self.input_search, self.button_history)
self.button_history.setNavigation(self.listing, self.listing, self.button_search, self.input_search)
self.button_history.setNavigation(self.listing, self.listing, self.button_search, self.button_right1)
#Listing
self.listing.setNavigation(self.input_search, self.input_search, self.input_search, self.button_right1)
#Right menu
self.button_right1.setNavigation(self.button_history, self.listing, self.listing, self.input_search)
self.button_right1.setNavigation(self.button_history, self.button_right2, self.listing, self.input_search)
self.button_right2.setNavigation(self.button_right1, self.button_right3, self.listing, self.input_search)
self.button_right3.setNavigation(self.button_right2, self.button_right4, self.listing, self.input_search)
self.button_right4.setNavigation(self.button_right3, self.button_right5, self.listing, self.input_search)
self.button_right5.setNavigation(self.button_right4, self.button_right6, self.listing, self.input_search)
self.button_right6.setNavigation(self.button_right5, self.button_right1, self.listing, self.input_search)
if self.listing.size():
self.setFocus(self.listing)
else:
self.setFocus(self.input_search)
def setAnimation(self, control):
# Set fade animation for all add-on window controls
control.setAnimations([('WindowOpen', 'effect=fade start=0 end=100 time=500',),
('WindowClose', 'effect=fade start=100 end=0 time=500',)])
def search(self, addtime=None):
self.last_action = self.search
self.right_menu('search')
self.listing.reset()
query = self.input_search.getText()
log('Search query: '+str(query))
if len(query)>0:
self.filesList = self.get_filesList(query, addtime)
else:
#cache
if query != self.last_query and len(query)>0:
self.filesList = get_filesList(query, addtime)
self.last_query = query
elif len(query)==0:
self.filesList = [(1919, 1919, 52, u'102.66 MiB', u'South.Park.S20E06.HDTV.x264-FUM[ettv]',
u'ThePirateBay::magnet:?xt=urn:btih:0792ea51bc16a19893871197fa927ecec7ca25aa&dn=South.Park.S20E06.HDTV.x264-FUM%5Bettv%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969',
'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png')]
'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'),
(1919, 1919, 52, u'102.66 MiB', u'Haruhi',
u'D:\\htest.torrent',
'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png') ]
if 1==1:
for (order, seeds, leechers, size, title, link, image) in self.filesList:
title = titleMake(seeds, leechers, size, title)
#log(title)
listitem = xbmcgui.ListItem(title, "", image, '', '')
listitem.setInfo(type='Video', infoLabels={})
contextMenu = [(self.localize('Search Control Window'),
'xbmc.RunScript(%s,)' % os.path.join(__root__, 'controlcenter.py'))]
replaceMenu = False
listitem.addContextMenuItems(contextMenu, replaceItems=replaceMenu)
self.listing.addItem(listitem)
def get_filesList(self, query, addtime = None):
if self.__settings__.getSetting('history')=='true':
HistoryDB().add(query)
searchersList = []
if addtime:
providers=HistoryDB().get_providers(addtime)
if providers:
for searcher in providers:
searchersList.append(searcher)
if not addtime or not searchersList:
searchersList = Searchers().get_active()
filesList=search(query, searchersList)
if self.__settings__.getSetting('sort_search')=='true':
self.__settings__.setSetting('sort_search','1')
if int(self.__settings__.getSetting('sort_search'))==0:
filesList = sorted(filesList, key=lambda x: x[0], reverse=True)
elif int(self.__settings__.getSetting('sort_search'))==2:
filesList = sorted(filesList, key=lambda x: x[4], reverse=False)
log('get_filesList filesList: '+str(filesList))
return filesList
self.drawItem(title, 'search_item', link, image)
def press(self):
#self.filesList = sorted(self.filesList, key=lambda x: x[1], reverse=True)
#self.items()
log(self.listing.getSelectedItem().getLabel())
xbmcgui.Dialog().ok('yyy', 'yyy')
item = self.listing.getSelectedItem()
params = json.loads(item.getLabel2())
mode = params.get('mode')
filename = item.getfilename()
label = item.getLabel()
tdir = params.get('tdir')
self.listing.reset()
if mode == 'search_item':
self.open_torrent(filename)
elif mode == 'torrent_subfolder':
self.open_torrent(filename, tdir)
elif mode == 'torrent_moveup':
self.last_action()
elif mode == 'torrent_play':
action = 'playTorrent'
log('params: '+str(params))
url = self.form_link(action, params)
log('url: '+url)
xbmc.executebuiltin('xbmc.RunPlugin("%s")' % (url))
self.close()
def open_torrent(self, link, tdir = None):
#cache
if link != self.last_link:
self.contentList = get_contentList(link)
self.last_link = link
dirList, contentListNew = cutFolder(self.contentList, tdir)
if not tdir:
self.drawItem('..', 'torrent_moveup', link, isFolder=True)
else:
params = {'mode': 'torrent_subfolder'}
self.drawItem('..', params, link, isFolder=True)
for title in dirList:
self.drawItem(title, {'mode':'torrent_subfolder', 'tdir': title}, link, isFolder=True)
ids_video_result = get_ids_video(contentListNew)
ids_video=''
if len(ids_video_result)>0:
for identifier in ids_video_result:
ids_video = ids_video + str(identifier) + ','
for title, identifier, filesize in contentListNew:
params = {'mode': 'torrent_play', 'url': identifier, 'url2': ids_video.rstrip(',')}
self.drawItem(title, params, link)
def history(self):
self.right_menu('history')
@@ -150,14 +183,42 @@ class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
xbmcgui.Dialog().ok('xxx','xxx')
log('history_search: '+self.listing.getSelectedItem().getLabel())
def right_menu(self, mode='search'):
if mode == 'search':
def right_menu(self, mode='place'):
if not mode == 'place':
self.last_right_buttons_count = self.right_buttons_count
if mode == 'place':
self.button_right1 = pyxbmct.Button("Empty")
self.button_right2 = pyxbmct.Button("Empty")
self.button_right3 = pyxbmct.Button("Empty")
self.button_right4 = pyxbmct.Button("Empty")
self.button_right5 = pyxbmct.Button("Empty")
self.button_right6 = pyxbmct.Button("Empty")
elif mode == 'search':
self.right_buttons_count = 3
self.button_right1.setLabel("Open")
self.connect(self.button_right1, self.press)
self.connect(self.button_right1, self.press)
self.button_right2.setLabel("Open2")
self.button_right3.setLabel("Open3")
elif mode == 'history':
self.right_buttons_count = 5
self.button_right1.setLabel("Search")
self.connect(self.button_right1, self.history_search)
self.connect(self.button_right1, self.history_search)
self.button_right2.setLabel("Open2")
self.button_right3.setLabel("Open3")
self.button_right4.setLabel("Open2")
self.button_right5.setLabel("Open3")
control_list = [self.button_right1, self.button_right2, self.button_right3, self.button_right4, self.button_right5, self.button_right6]
if self.last_right_buttons_count > self.right_buttons_count:
self.removeControls(control_list[self.right_buttons_count:self.last_right_buttons_count])
elif self.last_right_buttons_count < self.right_buttons_count:
for button in control_list[self.last_right_buttons_count:self.right_buttons_count]:
self.placeControl(button, control_list.index(button)+1, 14, 1, 2)
def localize(self, string):
try:
@@ -165,6 +226,29 @@ class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
except:
return string
def drawItem(self, title, params, link, image = None, isFolder = False):
if isinstance(params, str):
params = {'mode': params}
if not image and isFolder:
image = 'DefaultFolder.png'
elif not image:
image = 'DefaultVideo.png'
listitem = xbmcgui.ListItem(title, json.dumps(params), image, image, link)
self.listing.addItem(listitem)
def form_link(self, action, link):
if isinstance(link, dict):
link_url = ''
for key in link.keys():
if link.get(key) and key != 'mode':
link_url = '%s&%s=%s' % (link_url, key, urllib.quote_plus(link.get(key)))
url = '%s?action=%s' % ('plugin://plugin.video.torrenter/', action) + link_url
else:
url = '%s?action=%s&url=%s' % ('plugin://plugin.video.torrenter/', action, urllib.quote_plus(link))
return url
def log(msg):
try:
xbmc.log("### [%s]: %s" % (__plugin__,msg,), level=xbmc.LOGNOTICE )
@@ -195,7 +279,3 @@ if __name__ == "__main__":
dialog.doModal()
del dialog #You need to delete your instance when it is no longer needed
#because underlying xbmcgui classes are not grabage-collected.
'''
items = [(1919, 1919, 52, u'102.66 MiB', u'South.Park.S20E06.HDTV.x264-FUM[ettv]', u'ThePirateBay::magnet:?xt=urn:btih:0792ea51bc16a19893871197fa927ecec7ca25aa&dn=South.Park.S20E06.HDTV.x264-FUM%5Bettv%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (1545, 1545, 31, u'97.26 MiB', u'South.Park.S20E05.HDTV.x264-KILLERS[ettv]', u'ThePirateBay::magnet:?xt=urn:btih:437487c32ce82f050cdbfccfc04e4e20aca0d4cb&dn=South.Park.S20E05.HDTV.x264-KILLERS%5Bettv%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (1265, 1265, 75, u'89.69 MiB', u'South.Park.S20E07.HDTV.x264-FLEET', u'ThePirateBay::magnet:?xt=urn:btih:a122b0b79c4cbacea959e6e032ab540674ce49eb&dn=South.Park.S20E07.HDTV.x264-FLEET&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (1083, 1083, 9, u'99.5 MiB', u'South.Park.S20E03.PROPER.HDTV.x264-KILLERS[ettv]', u'ThePirateBay::magnet:?xt=urn:btih:ed2806f33629ec637caeabcc25ae1e70d5971ebe&dn=South.Park.S20E03.PROPER.HDTV.x264-KILLERS%5Bettv%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (429, 429, 19, u'85.08 MiB', u'South.Park.S20E08.WEBRip.x264-FUM[ettv]', u'ThePirateBay::magnet:?xt=urn:btih:988728720702c55fd1d19cde10f9af720ed934eb&dn=South.Park.S20E08.WEBRip.x264-FUM%5Bettv%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (311, 311, 229, u'251.67 MiB', u'South.Park.S20E08.1080p.HDTV.x264[state]', u'ThePirateBay::magnet:?xt=urn:btih:a5fa25dfccfa43723e34466b47fed2f89dd34072&dn=South.Park.S20E08.1080p.HDTV.x264%5Bstate%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (272, 272, 51, '6.08 \xd0\x93\xd0\x91', '\xd0\xae\xd0\xb6\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbf\xd0\xb0\xd1\x80\xd0\xba / South Park (C\xd0\xb5\xd0\xb7\xd0\xbe\xd0\xbd 18 , \xd0\xa1\xd0\xb5\xd1\x80\xd0\xb8\xd1\x8f 1-10 \xd0\xb8\xd0\xb7 10) [2014, \xd0\x9c\xd1\x83\xd0\xbb\xd1\x8c\xd1\x82\xd1\x81\xd0\xb5\xd1\x80\xd0\xb8\xd0\xb0\xd0\xbb, \xd0\x9a\xd0\xbe\xd0\xbc\xd0\xb5\xd0\xb4\xd0\xb8\xd1\x8f, \xd0\x9f\xd0\xb0\xd1\x80\xd0\xbe\xd0\xb4\xd0\xb8\xd1\x8f, WEB-DL (720p), \xd0\x9f\xd1\x80\xd0\xbe\xd1\x84\xd0\xb5\xd1\x81\xd1\x81\xd0\xb8\xd0\xbe\xd0\xbd\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd1\x8b\xd0\xb9 (\xd0\xb4\xd0\xb2\xd1\x83\xd1\x85\xd0\xb3\xd0\xbe\xd0\xb3\xd0\xbe\xd0\xbb\xd0\xbe\xd1\x81\xd1\x8b\xd0\xb9, \xd0\xb7\xd0\xb0\xd0\xba\xd0\xb0\xd0\xb4\xd1\x80\xd0\xbe\xd0\xb2\xd1\x8b\xd0\xb9) - \xd0\x9a\xd1\x83\xd0\xb1\xd0\xb8\xd0\xba \xd0\xb2 \xd0\x9a\xd1\x83\xd0\xb1\xd0\xb5]', 'RiperAM::http://riperam.orghttp://riperam.org/foreign-multserials/ujniy-park-south-park-cezon-10-seriya-1-iz-10-t111662.html?id=602710', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.RiperAM\\icon.png'), (237, 237, 6, u'367.96 MiB', u'South.Park.S20E03.720p.HDTV.x264-AVS[rarbg]', u'ThePirateBay::magnet:?xt=urn:btih:a6fd5218db8b5445981ce1466a501ae1e72fc538&dn=South.Park.S20E03.720p.HDTV.x264-AVS%5Brarbg%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969', 'C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\addons\\torrenter.searcher.ThePirateBay\\icon.png'), (206, 206, 127, '4.1 \xd0\x93\xd0\x91', '\xd0\xae\xd0\xb6\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\x9f\xd0\xb0\xd1\x80\xd0\xba (19 \xd1\x81\xd0\xb5\xd0\xb7\xd0\xbe\xd0\xbd: 1-10 \xd1\x81\xd0\xb5\xd1\x80\xd0\xb8\xd1\x8f \xd0\xb8\xd0\xb7 10) / South Park [2015, \xd0\x9c\xd1\x83\xd0\xbb\xd1\x8c\xd1\x82\xd1\x81\xd0\xb5\xd1\x80\xd0\xb8\xd0\xb0\xd0Line truncated
'''