5 from Components.ActionMap import ActionMap
6 from Components.MenuList import MenuList
7 from RSConfig import config
8 from Screens.MessageBox import MessageBox
9 from Screens.Screen import Screen
10 from twisted.web.client import getPage
12 ##############################################################################
14 class RSSearch(Screen):
16 <screen position="75,75" size="570,425" title="Searching... please wait!">
17 <widget name="list" position="0,0" size="570,425" scrollbarMode="showOnDemand" />
20 def __init__(self, session, searchFor):
21 Screen.__init__(self, session)
22 self.session = session
24 self.searchFor = searchFor.replace(" ", "%2B")
29 self["list"] = MenuList([])
31 self["actions"] = ActionMap(["OkCancelActions", "InfobarChannelSelection"],
33 "historyBack": self.previousPage,
34 "historyNext": self.nextPage,
39 self.onLayoutFinish.append(self.search)
42 if len(self.files) > 0:
43 idx = self["list"].getSelectedIndex()
45 list = ("%s/search.txt" % config.plugins.RSDownloader.lists_directory.value).replace("//", "/")
52 if not content.endswith("\n"):
59 f.write("%s%s\n" % (content, url))
61 self.session.open(MessageBox, (_("Added %s to the download-list.") % url), MessageBox.TYPE_INFO)
63 self.session.open(MessageBox, (_("Error while adding %s to the download-list!") % url), MessageBox.TYPE_ERROR)
66 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)
68 def searchCallback(self, html=""):
72 if html.__contains__("Nothing found, sorry."):
73 self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: Nothing found, sorry.")), MessageBox.TYPE_ERROR)
74 self.instance.setTitle(_("Nothing found, sorry."))
77 while tmp.__contains__("goPg('"):
78 idx = tmp.index("goPg('")
81 pageNumber = tmp[:idx]
84 pageNumber = int(pageNumber)
85 if pageNumber > self.maxPage:
86 self.maxPage = pageNumber
90 self.instance.setTitle("Page %d / %d. Push < > to switch the page..." % (self.curPage, self.maxPage))
92 while html.__contains__('title="Download"'):
93 idx = html.index('title="Download"')
95 idx = html.index('value="')
99 idx = html.index('http://rapidshare.com/')
101 idx = html.index('"')
106 urllist = url.split("/")
107 idx = len(urllist) - 1
109 list.append("%s - %s" % (size, name))
111 list.append("%s - %s" % (size, url))
114 self["list"].setList(list)
116 def searchError(self, error=""):
117 self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: %s") % str(error)), MessageBox.TYPE_ERROR)
119 def previousPage(self):
122 self.instance.setTitle("Loading previous page... please wait!")
126 if self.curPage < self.maxPage:
128 self.instance.setTitle("Loading next page... please wait!")