Added possibility to search for rapidshare.com files.
authorNabil Hanna <ali@users.schwerkraft.elitedvb.net>
Fri, 14 Nov 2008 18:31:58 +0000 (18:31 +0000)
committerNabil Hanna <ali@users.schwerkraft.elitedvb.net>
Fri, 14 Nov 2008 18:31:58 +0000 (18:31 +0000)
(Using the great http://rapidshare-search-engine.com)

rsdownloader/src/RS.py
rsdownloader/src/RSConfig.py
rsdownloader/src/RSMain.py
rsdownloader/src/RSSearch.py [new file with mode: 0644]

index 750001d..e5f09fd 100644 (file)
@@ -190,7 +190,7 @@ class RS:
                                \r
                                if content.__contains__(file):\r
                                        content = content.replace(file, "")\r
-                                       content = content.replace("\n\n", "\n")\r
+                                       content = content.replace("\n\n", "\n").replace("\r\r", "\r")\r
                                        \r
                                        f = open(list, "w")\r
                                        f.write(content)\r
index f38a663..c427c00 100644 (file)
@@ -11,7 +11,7 @@ from time import time
 \r
 ##############################################################################\r
 \r
-config.plugins.RSDownloader  = ConfigSubsection()\r
+config.plugins.RSDownloader = ConfigSubsection()\r
 config.plugins.RSDownloader.username = ConfigText(default="", fixed_size=False)\r
 config.plugins.RSDownloader.password = ConfigText(default="", fixed_size=False)\r
 config.plugins.RSDownloader.lists_directory = ConfigText(default="/media/cf/rs/lists/", fixed_size=False)\r
index 0940e3c..1c4d8a6 100644 (file)
@@ -10,16 +10,26 @@ from RSConfig import RSConfig, config
 from RSDownloadBrowser import RSDownloadBrowser
 from RSListBrowser import RSListBrowser
 from RSProgress import RSProgress
+from RSSearch import RSSearch
 from Screens.Console import Console
 from Screens.MessageBox import MessageBox
 from Screens.Screen import Screen
+from Tools.Directories import fileExists
+
+if fileExists("/usr/lib/enigma2/python/Screens/LTKeyBoard.pyc"):
+       from Screens.LTKeyBoard import LTKeyBoard
+       LT = True
+else:
+       from Components.Input import Input
+       from Screens.InputBox import InputBox
+       LT = False
 
 ##############################################################################
 
 class RSMain(Screen):
        skin = """
-               <screen position="200,175" size="320,250" title="RS Downloader">
-                       <widget name="list" position="10,10" size="300,230" />
+               <screen position="200,165" size="320,270" title="RS Downloader">
+                       <widget name="list" position="10,10" size="300,250" />
                </screen>"""
 
        def __init__(self, session, args = None):
@@ -35,6 +45,7 @@ class RSMain(Screen):
                        _("Show status..."),
                        _("Show log..."),
                        _("Delete log..."),
+                       _("Use search-engine..."),
                        _("Show info...")])
                
                self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.okClicked, "cancel": self.close}, -1)
@@ -84,5 +95,17 @@ class RSMain(Screen):
                        elif selected == (_("Delete log...")):
                                self.session.open(Console, "RS Downloader", ["rm -f /tmp/rapidshare.log"])
                        
+                       elif selected == (_("Use search-engine...")):
+                               title = _("Search http://rapidshare-search-engine.com for:")
+                               if LT:
+                                       self.session.openWithCallback(self.searchCallback, LTKeyBoard, title=title)
+                               else:
+                                       self.session.openWithCallback(self.searchCallback, InputBox, title=title, text="", maxSize=False, type=Input.TEXT)
+                       
                        elif selected == (_("Show info...")):
-                               self.session.open(MessageBox, (_("RS Downloader\nby AliAbdul\n\nThis plugin allows you to download files from rapidshare in the background. You can use this plugin only with a rapidshare-account!")), MessageBox.TYPE_INFO)
+                               self.session.open(MessageBox, (_("RS Downloader\nby AliAbdul\n\nThis plugin allows you to download files from rapidshare in the background.")), MessageBox.TYPE_INFO)
+
+       def searchCallback(self, callback):
+               if callback is not None and callback != "":
+                       self.session.open(RSSearch, callback)
+
diff --git a/rsdownloader/src/RSSearch.py b/rsdownloader/src/RSSearch.py
new file mode 100644 (file)
index 0000000..2a6c37f
--- /dev/null
@@ -0,0 +1,131 @@
+##
+## RS Downloader
+## by AliAbdul
+##
+from Components.ActionMap import ActionMap
+from Components.MenuList import MenuList
+from RS import rapidshare
+from RSConfig import config
+from Screens.MessageBox import MessageBox
+from Screens.Screen import Screen
+from twisted.web.client import getPage
+
+##############################################################################
+
+class RSSearch(Screen):
+       skin = """
+               <screen position="75,75" size="570,425" title="Searching... please wait!">
+                       <widget name="list" position="0,0" size="570,425" />
+               </screen>"""
+
+       def __init__(self, session, searchFor):
+               Screen.__init__(self, session)
+               self.session = session
+               
+               self.searchFor = searchFor.replace(" ", "%2B")
+               self.maxPage = 1
+               self.curPage = 1
+               self.files = []
+               
+               self["list"] = MenuList([])
+               
+               self["actions"] = ActionMap(["OkCancelActions", "InfobarChannelSelection"],
+                       {
+                               "historyBack": self.previousPage,
+                               "historyNext": self.nextPage,
+                               "ok": self.okClicked,
+                               "cancel": self.close
+                       }, -1)
+               
+               self.onLayoutFinish.append(self.search)
+
+       def okClicked(self):
+               if len(self.files) > 0:
+                       idx = self["list"].getSelectedIndex()
+                       url = self.files[idx]
+                       list = ("%s/search.txt" % config.plugins.RSDownloader.lists_directory.value).replace("//", "/")
+                       
+                       try:
+                               f = open(list, "r")
+                               content = f.read()
+                               f.close()
+                               
+                               if not content.endswith("\n"):
+                                       content += "\n"
+                       except:
+                               content = ""
+                       
+                       try:
+                               f = open(list, "w")
+                               f.write("%s%s\n" % (content, url))
+                               f.close()
+                               self.session.open(MessageBox, (_("Added %s to the download-list.") % url), MessageBox.TYPE_INFO)
+                       except:
+                               self.session.open(MessageBox, (_("Error while adding %s to the download-list!") % url), MessageBox.TYPE_ERROR)
+
+       def search(self):
+               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)
+
+       def searchCallback(self, html=""):
+               list = []
+               files = []
+               
+               if html.__contains__("Nothing found, sorry."):
+                       self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: Nothing found, sorry.")), MessageBox.TYPE_ERROR)
+                       self.instance.setTitle(_("Error while searching!"))
+               else:
+                       tmp = html
+                       while tmp.__contains__("goPg('"):
+                               idx = tmp.index("goPg('")
+                               tmp = tmp[idx+6:]
+                               idx = tmp.index("'")
+                               pageNumber = tmp[:idx]
+                               \r
+                               try:
+                                       pageNumber = int(pageNumber)
+                                       if pageNumber > self.maxPage:
+                                               self.maxPage = pageNumber
+                               except:
+                                       pass
+                               
+                               self.instance.setTitle("Page %d / %d. Push < > to switch the page..." % (self.curPage, self.maxPage))
+                       
+                       while html.__contains__('title="Download"'):
+                               idx = html.index('title="Download"')
+                               html = html[idx:]
+                               idx = html.index('value="')
+                               html = html[idx+7:]
+                               idx = html.index('"')
+                               size = html[:idx]
+                               idx = html.index('http://rapidshare.com/')
+                               html = html[idx:]
+                               idx = html.index('"')
+                               url = html[:idx]
+                               
+                               files.append(url) 
+                               try:
+                                       urllist = url.split("/")
+                                       idx = len(urllist) - 1
+                                       name = urllist[idx]
+                                       list.append("%s - %s" % (size, name))
+                               except:
+                                       list.append("%s - %s" % (size, url))
+               
+               self.files = files
+               self["list"].setList(list)
+
+       def searchError(self, error=""):
+               self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: %s") % str(error)), MessageBox.TYPE_ERROR)
+
+       def previousPage(self):
+               if self.curPage > 1:
+                       self.curPage -= 1
+                       self.instance.setTitle("Loading previous page... please wait!")
+                       self.search()
+
+       def nextPage(self):
+               if self.curPage < self.maxPage:
+                       self.curPage += 1
+                       self.instance.setTitle("Loading next page... please wait!")
+                       self.search()
+