5 from Components.ActionMap import ActionMap
6 from Components.MenuList import MenuList
7 from RS import rapidshare
8 from RSConfig import config
9 from Screens.MessageBox import MessageBox
10 from Screens.Screen import Screen
11 from twisted.web.client import getPage
13 ##############################################################################
15 class RSSearch(Screen):
17 <screen position="75,75" size="570,425" title="Searching... please wait!">
18 <widget name="list" position="0,0" size="570,425" />
21 def __init__(self, session, searchFor):
22 Screen.__init__(self, session)
23 self.session = session
25 self.searchFor = searchFor.replace(" ", "%2B")
30 self["list"] = MenuList([])
32 self["actions"] = ActionMap(["OkCancelActions", "InfobarChannelSelection"],
34 "historyBack": self.previousPage,
35 "historyNext": self.nextPage,
40 self.onLayoutFinish.append(self.search)
43 if len(self.files) > 0:
44 idx = self["list"].getSelectedIndex()
46 list = ("%s/search.txt" % config.plugins.RSDownloader.lists_directory.value).replace("//", "/")
53 if not content.endswith("\n"):
60 f.write("%s%s\n" % (content, url))
62 self.session.open(MessageBox, (_("Added %s to the download-list.") % url), MessageBox.TYPE_INFO)
64 self.session.open(MessageBox, (_("Error while adding %s to the download-list!") % url), MessageBox.TYPE_ERROR)
67 getPage("http://rapidshare-search-engine.com/index-s_submit=Search&sformval=1&s_type=0&what=1&s=%s&start=%d.html" % (self.searchFor, self.curPage)).addCallback(self.searchCallback).addErrback(self.searchError)
69 def searchCallback(self, html=""):
73 if html.__contains__("Nothing found, sorry."):
74 self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: Nothing found, sorry.")), MessageBox.TYPE_ERROR)
75 self.instance.setTitle(_("Error while searching!"))
78 while tmp.__contains__("goPg('"):
79 idx = tmp.index("goPg('")
82 pageNumber = tmp[:idx]
85 pageNumber = int(pageNumber)
86 if pageNumber > self.maxPage:
87 self.maxPage = pageNumber
91 self.instance.setTitle("Page %d / %d. Push < > to switch the page..." % (self.curPage, self.maxPage))
93 while html.__contains__('title="Download"'):
94 idx = html.index('title="Download"')
96 idx = html.index('value="')
100 idx = html.index('http://rapidshare.com/')
102 idx = html.index('"')
107 urllist = url.split("/")
108 idx = len(urllist) - 1
110 list.append("%s - %s" % (size, name))
112 list.append("%s - %s" % (size, url))
115 self["list"].setList(list)
117 def searchError(self, error=""):
118 self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: %s") % str(error)), MessageBox.TYPE_ERROR)
120 def previousPage(self):
123 self.instance.setTitle("Loading previous page... please wait!")
127 if self.curPage < self.maxPage:
129 self.instance.setTitle("Loading next page... please wait!")