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="106">Start All</string>
|
||||||
<string id="107">Exit</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 -->
|
<!-- Settings -->
|
||||||
<string id="1000">RPC Settings</string>
|
<string id="1000">RPC Settings</string>
|
||||||
<string id="1001">Host</string>
|
<string id="1001">Host</string>
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import base64
|
import base64
|
||||||
|
import urllib2
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
from basictypes.bytes import Bytes
|
from basictypes.bytes import Bytes
|
||||||
from repeater import Repeater
|
from repeater import Repeater
|
||||||
|
import search
|
||||||
|
|
||||||
_ = sys.modules[ "__main__" ].__language__
|
_ = sys.modules[ "__main__" ].__language__
|
||||||
__settings__ = sys.modules[ "__main__" ].__settings__
|
__settings__ = sys.modules[ "__main__" ].__settings__
|
||||||
|
@ -39,7 +41,6 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
||||||
except:
|
except:
|
||||||
p.close()
|
p.close()
|
||||||
self.close()
|
self.close()
|
||||||
d = xbmcgui.Dialog()
|
|
||||||
(type, e, traceback) = sys.exc_info()
|
(type, e, traceback) = sys.exc_info()
|
||||||
|
|
||||||
message = _(9000) # Unexpected error
|
message = _(9000) # Unexpected error
|
||||||
|
@ -49,17 +50,17 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
||||||
message = _(9002) # Invalid auth
|
message = _(9002) # Invalid auth
|
||||||
else:
|
else:
|
||||||
message = _(9001) # Unable to connect
|
message = _(9001) # Unable to connect
|
||||||
if d.yesno(_(2), message, _(3)):
|
if xbmcgui.Dialog().yesno(_(2), message, _(3)):
|
||||||
__settings__.openSettings()
|
__settings__.openSettings()
|
||||||
elif type is ValueError:
|
elif type is ValueError:
|
||||||
# In python 2.4, urllib2.HTTPDigestAuthHandler will barf up a lung
|
# In python 2.4, urllib2.HTTPDigestAuthHandler will barf up a lung
|
||||||
# if auth fails and the server wants non-digest authentication
|
# if auth fails and the server wants non-digest authentication
|
||||||
message = _(9002) # Invalid auth
|
message = _(9002) # Invalid auth
|
||||||
if d.yesno(_(2), message, _(3)):
|
if xbmcgui.Dialog().yesno(_(2), message, _(3)):
|
||||||
__settings__.openSettings()
|
__settings__.openSettings()
|
||||||
else:
|
else:
|
||||||
message = _(9000) # Unexpected error
|
message = _(9000) # Unexpected error
|
||||||
d.ok(_(2), message)
|
xbmcgui.Dialog().ok(_(2), message)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
p.close()
|
p.close()
|
||||||
|
@ -107,14 +108,51 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
||||||
list = self.getControl(20)
|
list = self.getControl(20)
|
||||||
if (controlID == 11):
|
if (controlID == 11):
|
||||||
# Add torrent
|
# Add torrent
|
||||||
d = xbmcgui.Dialog()
|
engines = [
|
||||||
filename = d.browse(1, _(0), 'files', '.torrent')
|
(_(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:
|
try:
|
||||||
f = open(filename, 'r')
|
f = open(filename, 'r')
|
||||||
data = base64.b64encode(f.read())
|
data = base64.b64encode(f.read())
|
||||||
self.transmission.add(data)
|
self.transmission.add(data)
|
||||||
except:
|
except:
|
||||||
pass
|
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):
|
if (controlID == 12):
|
||||||
# Remove selected torrent
|
# Remove selected torrent
|
||||||
item = list.getSelectedItem()
|
item = list.getSelectedItem()
|
||||||
|
@ -130,7 +168,6 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
|
||||||
# Start selected torrent
|
# Start selected torrent
|
||||||
item = list.getSelectedItem()
|
item = list.getSelectedItem()
|
||||||
if item:
|
if item:
|
||||||
t = int(item.getProperty('TorrentID'))
|
|
||||||
self.transmission.start(int(item.getProperty('TorrentID')))
|
self.transmission.start(int(item.getProperty('TorrentID')))
|
||||||
if (controlID == 15):
|
if (controlID == 15):
|
||||||
# Stop all torrents
|
# Stop all torrents
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
from urllib2 import urlopen
|
from urllib2 import urlopen
|
||||||
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
|
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
|
||||||
|
|
||||||
|
socket.setdefaulttimeout(15)
|
||||||
|
|
||||||
class Search:
|
class Search:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
@ -10,10 +13,10 @@ class Search:
|
||||||
|
|
||||||
class BTJunkie(Search):
|
class BTJunkie(Search):
|
||||||
def __init__(self):
|
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):
|
def search(self, terms):
|
||||||
torrents = []
|
torrents = []
|
||||||
url = self.search_uri.format(terms=terms)
|
url = self.search_uri % '+'.join(terms.split(' '))
|
||||||
f = urlopen(url)
|
f = urlopen(url)
|
||||||
soup = BeautifulStoneSoup(f.read())
|
soup = BeautifulStoneSoup(f.read())
|
||||||
for item in soup.findAll('item'):
|
for item in soup.findAll('item'):
|
||||||
|
@ -27,10 +30,10 @@ class BTJunkie(Search):
|
||||||
return torrents
|
return torrents
|
||||||
class TPB(Search):
|
class TPB(Search):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.search_uri = 'http://thepiratebay.org/search/{terms}/'
|
self.search_uri = 'http://thepiratebay.org/search/%s/'
|
||||||
def search(self, terms):
|
def search(self, terms):
|
||||||
torrents = []
|
torrents = []
|
||||||
url = self.search_uri.format(terms=terms)
|
url = self.search_uri % '+'.join(terms.split(' '))
|
||||||
f = urlopen(url)
|
f = urlopen(url)
|
||||||
soup = BeautifulSoup(f.read())
|
soup = BeautifulSoup(f.read())
|
||||||
for details in soup.findAll('a', {'class': 'detLink'}):
|
for details in soup.findAll('a', {'class': 'detLink'}):
|
||||||
|
|
Loading…
Reference in a new issue