mirror of
https://github.com/correl/Transmission-XBMC.git
synced 2024-11-25 11:09:57 +00:00
Implemented search with a basic UI
This commit is contained in:
parent
4d987017f9
commit
7e7f8c85c0
3 changed files with 66 additions and 17 deletions
|
@ -15,6 +15,15 @@
|
|||
<string id="106">Start All</string>
|
||||
<string id="107">Exit</string>
|
||||
|
||||
<!-- Adding / Search -->
|
||||
<string id="200">Browse for torrent file</string>
|
||||
<string id="201">Search BTJunkie.org</string>
|
||||
<string id="202">Search ThePirateBay.org</string>
|
||||
<string id="290">Searching...</string>
|
||||
<string id="291">No results found</string>
|
||||
<string id="292">Could not connect to search site</string>
|
||||
<string id="293">Could not download torrent data</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string id="1000">RPC Settings</string>
|
||||
<string id="1001">Host</string>
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
import os
|
||||
import sys
|
||||
import base64
|
||||
import urllib2
|
||||
import xbmc
|
||||
import xbmcgui
|
||||
from basictypes.bytes import Bytes
|
||||
from repeater import Repeater
|
||||
import search
|
||||
|
||||
_ = sys.modules[ "__main__" ].__language__
|
||||
__settings__ = sys.modules[ "__main__" ].__settings__
|
||||
|
@ -39,7 +41,6 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
except:
|
||||
p.close()
|
||||
self.close()
|
||||
d = xbmcgui.Dialog()
|
||||
(type, e, traceback) = sys.exc_info()
|
||||
|
||||
message = _(9000) # Unexpected error
|
||||
|
@ -49,17 +50,17 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
message = _(9002) # Invalid auth
|
||||
else:
|
||||
message = _(9001) # Unable to connect
|
||||
if d.yesno(_(2), message, _(3)):
|
||||
if xbmcgui.Dialog().yesno(_(2), message, _(3)):
|
||||
__settings__.openSettings()
|
||||
elif type is ValueError:
|
||||
# In python 2.4, urllib2.HTTPDigestAuthHandler will barf up a lung
|
||||
# if auth fails and the server wants non-digest authentication
|
||||
message = _(9002) # Invalid auth
|
||||
if d.yesno(_(2), message, _(3)):
|
||||
if xbmcgui.Dialog().yesno(_(2), message, _(3)):
|
||||
__settings__.openSettings()
|
||||
else:
|
||||
message = _(9000) # Unexpected error
|
||||
d.ok(_(2), message)
|
||||
xbmcgui.Dialog().ok(_(2), message)
|
||||
|
||||
return False
|
||||
p.close()
|
||||
|
@ -107,14 +108,51 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
list = self.getControl(20)
|
||||
if (controlID == 11):
|
||||
# Add torrent
|
||||
d = xbmcgui.Dialog()
|
||||
filename = d.browse(1, _(0), 'files', '.torrent')
|
||||
try:
|
||||
f = open(filename, 'r')
|
||||
data = base64.b64encode(f.read())
|
||||
self.transmission.add(data)
|
||||
except:
|
||||
pass
|
||||
engines = [
|
||||
(_(200), None),
|
||||
(_(201), search.BTJunkie),
|
||||
(_(202), search.TPB),
|
||||
]
|
||||
selected = xbmcgui.Dialog().select(_(0), [i[0] for i in engines])
|
||||
if selected < 0:
|
||||
return
|
||||
engine = engines[selected][1]
|
||||
if not engine:
|
||||
filename = xbmcgui.Dialog().browse(1, _(0), 'files', '.torrent')
|
||||
try:
|
||||
f = open(filename, 'r')
|
||||
data = base64.b64encode(f.read())
|
||||
self.transmission.add(data)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
kb = xbmc.Keyboard('', engines[selected][0])
|
||||
kb.doModal()
|
||||
if not kb.isConfirmed():
|
||||
return
|
||||
terms = kb.getText()
|
||||
p = xbmcgui.DialogProgress()
|
||||
p.create(_(0), _(290))
|
||||
try:
|
||||
results = engine().search(terms)
|
||||
except:
|
||||
p.close()
|
||||
xbmcgui.Dialog().ok(_(0), _(292))
|
||||
return
|
||||
p.close()
|
||||
if not results:
|
||||
xbmcgui.Dialog().ok(_(0), _(291))
|
||||
return
|
||||
selected = xbmcgui.Dialog().select(_(0), ['[S:%d L:%d] %s' % (t['seeds'], t['leechers'], t['name']) for t in results])
|
||||
if selected < 0:
|
||||
return
|
||||
try:
|
||||
f = urllib2.urlopen(results[selected]['url'])
|
||||
data = base64.b64encode(f.read())
|
||||
self.transmission.add(data)
|
||||
except:
|
||||
xbmcgui.Dialog().ok(_(0), _(293))
|
||||
return
|
||||
if (controlID == 12):
|
||||
# Remove selected torrent
|
||||
item = list.getSelectedItem()
|
||||
|
@ -130,7 +168,6 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
|||
# Start selected torrent
|
||||
item = list.getSelectedItem()
|
||||
if item:
|
||||
t = int(item.getProperty('TorrentID'))
|
||||
self.transmission.start(int(item.getProperty('TorrentID')))
|
||||
if (controlID == 15):
|
||||
# Stop all torrents
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import re
|
||||
import socket
|
||||
from urllib2 import urlopen
|
||||
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
|
||||
|
||||
socket.setdefaulttimeout(15)
|
||||
|
||||
class Search:
|
||||
def __init__(self):
|
||||
return NotImplemented
|
||||
|
@ -10,10 +13,10 @@ class Search:
|
|||
|
||||
class BTJunkie(Search):
|
||||
def __init__(self):
|
||||
self.search_uri = 'http://btjunkie.org/rss.xml?query={terms}&o=52'
|
||||
self.search_uri = 'http://btjunkie.org/rss.xml?query=%s&o=52'
|
||||
def search(self, terms):
|
||||
torrents = []
|
||||
url = self.search_uri.format(terms=terms)
|
||||
url = self.search_uri % '+'.join(terms.split(' '))
|
||||
f = urlopen(url)
|
||||
soup = BeautifulStoneSoup(f.read())
|
||||
for item in soup.findAll('item'):
|
||||
|
@ -27,10 +30,10 @@ class BTJunkie(Search):
|
|||
return torrents
|
||||
class TPB(Search):
|
||||
def __init__(self):
|
||||
self.search_uri = 'http://thepiratebay.org/search/{terms}/'
|
||||
self.search_uri = 'http://thepiratebay.org/search/%s/'
|
||||
def search(self, terms):
|
||||
torrents = []
|
||||
url = self.search_uri.format(terms=terms)
|
||||
url = self.search_uri % '+'.join(terms.split(' '))
|
||||
f = urlopen(url)
|
||||
soup = BeautifulSoup(f.read())
|
||||
for details in soup.findAll('a', {'class': 'detLink'}):
|
||||
|
|
Loading…
Reference in a new issue