6 from base64 import encodestring
7 from Components.ActionMap import ActionMap
8 from Components.config import config, ConfigInteger, ConfigText, ConfigYesNo, ConfigClock, ConfigSubsection, getConfigListEntry
9 from Components.ConfigList import ConfigListScreen
10 from Components.Label import Label
11 from Components.Language import language
12 from Components.MenuList import MenuList
13 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaTest
14 from Components.ScrollLabel import ScrollLabel
15 from enigma import eListboxPythonMultiContent, eTimer, gFont, RT_HALIGN_CENTER, RT_HALIGN_RIGHT
16 from os import environ, listdir, remove
17 from Plugins.Plugin import PluginDescriptor
18 from Screens.ChoiceBox import ChoiceBox
19 from Screens.MessageBox import MessageBox
20 from Screens.Screen import Screen
21 from Screens.VirtualKeyBoard import VirtualKeyBoard
22 from time import localtime, sleep, strftime, time
23 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE, SCOPE_LANGUAGE, SCOPE_PLUGINS
24 from Tools.Downloader import HTTPProgressDownloader
25 from Tools.LoadPixmap import LoadPixmap
26 from twisted.internet import reactor
27 from twisted.python import failure
28 from twisted.web.client import getPage
29 from urlparse import urlparse, urlunparse
30 import gettext, re, socket, urllib2
32 ##############################################################################
34 config.plugins.RSDownloader = ConfigSubsection()
35 config.plugins.RSDownloader.onoff = ConfigYesNo(default=True)
\r
36 config.plugins.RSDownloader.username = ConfigText(default="", fixed_size=False)
\r
37 config.plugins.RSDownloader.password = ConfigText(default="", fixed_size=False)
\r
38 config.plugins.RSDownloader.lists_directory = ConfigText(default="/media/hdd/rs/lists/", fixed_size=False)
\r
39 config.plugins.RSDownloader.downloads_directory = ConfigText(default="/media/hdd/rs/downloads", fixed_size=False)
40 config.plugins.RSDownloader.ignore_time = ConfigYesNo(default=False)
\r
41 config.plugins.RSDownloader.start_time = ConfigClock(default=time())
\r
42 config.plugins.RSDownloader.end_time = ConfigClock(default=time())
43 config.plugins.RSDownloader.download_monday = ConfigYesNo(default=True)
44 config.plugins.RSDownloader.download_tuesday = ConfigYesNo(default=True)
45 config.plugins.RSDownloader.download_wednesday = ConfigYesNo(default=True)
46 config.plugins.RSDownloader.download_thursday = ConfigYesNo(default=True)
47 config.plugins.RSDownloader.download_friday = ConfigYesNo(default=True)
48 config.plugins.RSDownloader.download_saturday = ConfigYesNo(default=True)
49 config.plugins.RSDownloader.download_sunday = ConfigYesNo(default=True)
\r
50 config.plugins.RSDownloader.count_downloads = ConfigInteger(default=3, limits=(1, 6))
51 config.plugins.RSDownloader.write_log = ConfigYesNo(default=True)
52 config.plugins.RSDownloader.reconnect_fritz = ConfigYesNo(default=False)
54 ##############################################################################
\r
57 lang = language.getLanguage()
58 environ["LANGUAGE"] = lang[:2]
\r
59 gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
\r
60 gettext.textdomain("enigma2")
61 gettext.bindtextdomain("RSDownloader", "%s%s"%(resolveFilename(SCOPE_PLUGINS), "Extensions/RSDownloader/locale/"))
64 t = gettext.dgettext("RSDownloader", txt)
\r
66 t = gettext.gettext(txt)
\r
70 language.addCallback(localeInit)
72 ##############################################################################
74 def writeLog(message):
75 if config.plugins.RSDownloader.write_log.value:
\r
76 log_file = "/tmp/rapidshare.log"
78 f = open(log_file, "r")
\r
83 log = log + strftime("%c", localtime(time())) + " - " + message + "\n"
85 f = open(log_file, "w")
\r
91 ##############################################################################
95 parsed = urlparse(url)
97 path = urlunparse(('','') + parsed[2:])
98 host, port = parsed[1], 80
100 username, host = host.split('@')
102 username, password = username.split(':')
109 host, port = host.split(':')
113 return scheme, host, port, path, username, password
115 class ProgressDownload():
116 def __init__(self, url, outputfile, contextFactory=None, *args, **kwargs):
117 scheme, host, port, path, username, password = _parse(url)
118 if username and password:
119 url = scheme + '://' + host + ':' + str(port) + path
120 basicAuth = encodestring("%s:%s"%(username, password))
121 authHeader = "Basic " + basicAuth.strip()
122 AuthHeaders = {"Authorization": authHeader}
123 if kwargs.has_key("headers"):
124 kwargs["headers"].update(AuthHeaders)
126 kwargs["headers"] = AuthHeaders
127 self.factory = HTTPProgressDownloader(url, outputfile, *args, **kwargs)
128 self.connection = reactor.connectTCP(host, port, self.factory)
131 return self.factory.deferred
134 self.connection.disconnect()
136 def addProgress(self, progress_callback):
137 self.factory.progress_callback = progress_callback
139 ##############################################################################
143 data = urllib2.urlopen(url)
150 return urllib2.urlopen(url, data).read()
154 def matchGet(rex, string):
155 match = re.search(rex, string)
157 if len(match.groups()) == 0:
158 return string[match.span()[0]:match.span()[1]]
159 if len(match.groups()) == 1:
160 return match.groups()[0]
164 ##############################################################################
166 def reconnect(host='fritz.box', port=49000):
167 http_body = '\r\n'.join((
168 '<?xml version="1.0" encoding="utf-8"?>',
169 '<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">',
171 ' <u:ForceTermination xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"/>',
174 http_data = '\r\n'.join((
175 'POST /upnp/control/WANIPConn1 HTTP/1.1',
176 'Host: %s:%d'%(host, port),
177 'SoapAction: urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination',
178 'Content-Type: text/xml; charset="utf-8"',
179 'Content-Length: %d'%len(http_body),
183 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
184 s.connect((host, port))
190 ##############################################################################
193 def __init__(self, url):
194 writeLog("Adding: %s"%url)
197 self.downloading = False
200 self.status = _("Waiting")
201 self.name = self.url.split("/")[-1]
203 self.freeDownloadUrl = ""
204 self.freeDownloadTimer = eTimer()
205 self.freeDownloadTimer.callback.append(self.freeDownloadStart)
207 self.finishCallbacks = []
210 writeLog("Downloading: %s"%self.url)
211 self.downloading = True
214 username = config.plugins.RSDownloader.username.value
215 password = config.plugins.RSDownloader.password.value
216 if self.url.__contains__("rapidshare.com") and username == "" and password == "":
217 writeLog("Free RS-Download: %s"%self.url)
218 self.status = _("Checking")
219 if config.plugins.RSDownloader.reconnect_fritz.value:
223 url = matchGet('<form[^>]+action="([^"]+)', data)
225 writeLog("Failed: %s"%self.url)
226 self.httpFailed(True, "Failed to get download page url: %s"%self.url)
228 data = post(url, "dl.start=Free")
229 seconds = matchGet('var c=([0-9]+)', data)
231 self.httpFailed(True, "Failed to get download page url: %s"%self.url)
233 writeLog("Free RS-download... must wait %s seconds: %s"%(seconds, self.url))
234 self.status = "%s %s"%(_("Waiting"), seconds)
235 url = matchGet('"dlf" action="([^"]+)', data)
237 self.httpFailed(True, "Failed to get download page url: %s"%self.url)
239 self.freeDownloadUrl = url
240 self.freeDownloadTimer.start((int(seconds) + 2) * 1000, 1)
242 if self.url.__contains__("rapidshare.com"):
243 url = self.url.replace("http://", "http://" + username + ":" + password + "@")
246 self.status = _("Downloading")
247 self.download = ProgressDownload(url, ("%s/%s"%(config.plugins.RSDownloader.downloads_directory.value, self.name)).replace("//", "/").replace(".html", ""))
248 self.download.addProgress(self.httpProgress)
249 self.download.start().addCallback(self.httpFinished).addErrback(self.httpFailed)
251 def freeDownloadStart(self):
252 self.status = _("Downloading")
253 self.download = ProgressDownload(self.freeDownloadUrl, ("%s/%s"%(config.plugins.RSDownloader.downloads_directory.value, self.name)).replace("//", "/").replace(".html", ""))
254 self.download.addProgress(self.httpProgress)
255 self.download.start().addCallback(self.httpFinished).addErrback(self.httpFailed)
257 def httpProgress(self, recvbytes, totalbytes):
259 self.size = int((totalbytes / 1024) / 1024)
260 self.progress = int(100.0 * float(recvbytes) / float(totalbytes))
261 if self.progress == 100:
262 writeLog("Finished: %s"%self.url)
263 self.status = _("Finished")
264 self.execFinishCallbacks()
266 def httpFinished(self, string=""):
267 self.downloading = False
268 if string is not None:
269 writeLog("Failed: %s"%self.url)
270 writeLog("Error: %s"%string)
271 self.status = _("Failed")
272 self.execFinishCallbacks()
274 def execFinishCallbacks(self):
275 for x in self.finishCallbacks:
278 def httpFailed(self, failure=None, error=""):
279 self.downloading = False
282 error = failure.getErrorMessage()
283 if error != "" and not error.startswith("[Errno 2]"):
284 writeLog("Failed: %s"%self.url)
285 writeLog("Error: %s"%error)
286 self.status = _("Failed")
287 self.execFinishCallbacks()
291 self.downloading = False
292 self.status = _("Waiting")
294 writeLog("Stopping download: %s"%self.url)
297 ##############################################################################
302 self.checkTimer = eTimer()
303 self.checkTimer.callback.append(self.startDownloading)
304 self.checkTimer.start(5000*60, False)
306 def mayDownload(self):
307 if config.plugins.RSDownloader.onoff.value == False:
308 writeLog("RS Downloader is turned off...")
310 elif config.plugins.RSDownloader.ignore_time.value:
313 start = config.plugins.RSDownloader.start_time.value
\r
314 end = config.plugins.RSDownloader.end_time.value
\r
317 if weekday == 0 and config.plugins.RSDownloader.download_monday.value == False:
319 elif weekday == 1 and config.plugins.RSDownloader.download_tuesday.value == False:
321 elif weekday == 2 and config.plugins.RSDownloader.download_wednesday.value == False:
323 elif weekday == 3 and config.plugins.RSDownloader.download_thursday.value == False:
325 elif weekday == 4 and config.plugins.RSDownloader.download_friday.value == False:
327 elif weekday == 5 and config.plugins.RSDownloader.download_saturday.value == False:
329 elif weekday == 6 and config.plugins.RSDownloader.download_sunday.value == False:
334 hour_start = start[0]
\r
335 minute_start = start[1]
\r
337 minute_end = end[1]
\r
338 if start == end: # Same start and end-time
\r
340 elif hour_end < hour_start: # Different days!!!
\r
341 if hour_now > hour_start or hour_now < hour_end:
\r
343 elif hour_now == hour_start and minute_now > minute_start:
\r
345 elif hour_now == hour_end and minute_now < minute_end:
\r
347 elif hour_now > hour_start and hour_now < hour_end: # Same day...
\r
349 elif hour_now == hour_start and minute_now > minute_start: # Same day, same start-hour...
\r
351 elif hour_now == hour_end and minute_now < minute_end: # Same day, same end-hour...
\r
356 def startDownloading(self):
357 if self.mayDownload() == True:
360 for download in self.downloads:
361 if download.downloading == True:
362 downloadCount += 1 # Count the downloaded files
363 if config.plugins.RSDownloader.username.value == "" and config.plugins.RSDownloader.password.value == "" and downloadCount == 0: # Allow one download if without account
364 for download in self.downloads:
365 if download.downloading == False and download.status.startswith(_("Waiting")):
366 download.start() # Start first download in the list
369 mayDownloadCount = config.plugins.RSDownloader.count_downloads.value - downloadCount
370 for download in self.downloads:
371 if download.downloading == False:
372 if mayDownloadCount > 0 and download.status == _("Waiting"):
374 mayDownloadCount -= 1
376 def addDownload(self, url):
378 for download in self.downloads:
379 if download.url == url:
384 download = RSDownload(url)
385 download.finishCallbacks.append(self.cleanLists)
386 self.downloads.append(download)
387 self.startDownloading()
390 def readLists(self):
\r
391 writeLog("Reading all lists...")
\r
392 path = config.plugins.RSDownloader.lists_directory.value
\r
393 if not path.endswith("/"):
\r
395 writeLog("Directory: " + path)
\r
397 file_list = listdir(path)
\r
398 writeLog("Count of lists: " + str(len(file_list)))
\r
401 writeLog("Could not find any list!")
\r
402 for x in file_list:
\r
405 writeLog("Reading list %s..."%list)
\r
409 if l.startswith("http://"):
\r
410 self.addDownload(l.replace("\n", "").replace("\r", ""))
414 writeLog("Empty list: %s"%list)
416 writeLog("Added %d files from list %s..."%(count, list))
\r
418 writeLog("Error while reading list %s!"%list)
419 def cleanLists(self):
420 writeLog("Cleaning lists...")
\r
421 path = config.plugins.RSDownloader.lists_directory.value
\r
422 if not path.endswith("/"):
\r
425 file_list = listdir(path)
\r
428 for x in file_list:
\r
431 f = open(list, "r")
\r
434 for download in self.downloads:
435 if download.status == _("Finished") and content.__contains__(download.url):
\r
436 content = content.replace(download.url, "")
\r
437 content = content.replace("\n\n", "\n").replace("\r\r", "\r")
\r
438 f = open(list, "w")
\r
442 writeLog("Error while cleaning list %s!"%list)
443 self.startDownloading()
445 def removeDownload(self, url):
447 for download in self.downloads:
448 if download.url == url:
454 self.removeFromLists(url)
456 def removeFromLists(self, url):
\r
457 path = config.plugins.RSDownloader.lists_directory.value
\r
458 if not path.endswith("/"):
\r
461 file_list = listdir(path)
\r
464 for x in file_list:
\r
467 f = open(list, "r")
\r
470 if content.__contains__(url):
\r
471 content = content.replace(url, "")
\r
472 content = content.replace("\n\n", "\n").replace("\r\r", "\r")
\r
473 f = open(list, "w")
\r
479 def clearFinishedDownload(self, url):
481 for x in self.downloads:
483 del self.downloads[idx]
488 def clearFinishedDownloads(self):
490 for download in self.downloads:
491 if download.status != _("Finished"):
496 def deleteFailedDownloads(self):
498 for download in self.downloads:
499 if download.status == _("Failed"):
500 self.removeFromLists(download.url)
506 def restartFailedDownloads(self):
508 for download in self.downloads:
509 if download.status == _("Failed"):
510 download.download = None
511 download.downloading = False
512 download.progress = 0
514 download.status = _("Waiting")
518 self.startDownloading()
522 ##############################################################################
524 class ChangedScreen(Screen):
525 def __init__(self, session, parent=None):
\r
526 Screen.__init__(self, session, parent)
\r
527 self.onLayoutFinish.append(self.setScreenTitle)
\r
529 def setScreenTitle(self):
\r
530 self.setTitle(_("RS Downloader"))
532 ##############################################################################
534 class RSConfig(ConfigListScreen, ChangedScreen):
\r
536 <screen position="center,center" size="560,450" title="RS Downloader">
\r
537 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" transparent="1" alphatest="on" />
\r
538 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" transparent="1" alphatest="on" />
\r
539 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" transparent="1" alphatest="on" />
\r
540 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" transparent="1" alphatest="on" />
\r
541 <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
\r
542 <widget name="config" position="0,45" size="560,400" scrollbarMode="showOnDemand" />
\r
545 def __init__(self, session):
\r
546 ChangedScreen.__init__(self, session)
\r
548 self["key_green"] = Label(_("Save"))
\r
550 ConfigListScreen.__init__(self, [
\r
551 getConfigListEntry(_("Download in the background:"), config.plugins.RSDownloader.onoff),
\r
552 getConfigListEntry(_("Username:"), config.plugins.RSDownloader.username),
\r
553 getConfigListEntry(_("Password:"), config.plugins.RSDownloader.password),
\r
554 getConfigListEntry(_("Lists directory:"), config.plugins.RSDownloader.lists_directory),
\r
555 getConfigListEntry(_("Downloads directory:"), config.plugins.RSDownloader.downloads_directory),
\r
556 getConfigListEntry(_("Ignore download times:"), config.plugins.RSDownloader.ignore_time),
\r
557 getConfigListEntry(_("Allow downloading on monday:"), config.plugins.RSDownloader.download_monday),
\r
558 getConfigListEntry(_("Allow downloading on tuesday:"), config.plugins.RSDownloader.download_tuesday),
\r
559 getConfigListEntry(_("Allow downloading on wednesday:"), config.plugins.RSDownloader.download_wednesday),
\r
560 getConfigListEntry(_("Allow downloading on thursday:"), config.plugins.RSDownloader.download_thursday),
\r
561 getConfigListEntry(_("Allow downloading on friday:"), config.plugins.RSDownloader.download_friday),
\r
562 getConfigListEntry(_("Allow downloading on saturday:"), config.plugins.RSDownloader.download_saturday),
\r
563 getConfigListEntry(_("Allow downloading on sunday:"), config.plugins.RSDownloader.download_sunday),
564 getConfigListEntry(_("Don't download before:"), config.plugins.RSDownloader.start_time),
\r
565 getConfigListEntry(_("Don't download after:"), config.plugins.RSDownloader.end_time),
\r
566 getConfigListEntry(_("Maximal downloads:"), config.plugins.RSDownloader.count_downloads),
\r
567 getConfigListEntry(_("Write log:"), config.plugins.RSDownloader.write_log),
568 getConfigListEntry(_("Reconnect fritz.Box before downloading:"), config.plugins.RSDownloader.reconnect_fritz)])
\r
570 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], {"green": self.save, "cancel": self.exit}, -1)
\r
573 for x in self["config"].list:
\r
578 for x in self["config"].list:
\r
582 ##############################################################################
584 class RSSearch(Screen):
586 <screen position="center,center" size="560,450" title="Searching... please wait!">
587 <widget name="list" position="0,0" size="570,450" scrollbarMode="showOnDemand" />
590 def __init__(self, session, searchFor):
591 Screen.__init__(self, session)
592 self.session = session
594 self.searchFor = searchFor.replace(" ", "%2B")
599 self["list"] = MenuList([])
601 self["actions"] = ActionMap(["OkCancelActions", "InfobarChannelSelection"],
603 "historyBack": self.previousPage,
604 "historyNext": self.nextPage,
605 "ok": self.okClicked,
609 self.onLayoutFinish.append(self.search)
612 if len(self.files) > 0:
613 idx = self["list"].getSelectedIndex()
614 url = self.files[idx]
615 list = ("%s/search.txt" % config.plugins.RSDownloader.lists_directory.value).replace("//", "/")
620 if not content.endswith("\n"):
626 f.write("%s%s\n" % (content, url))
628 self.session.open(MessageBox, (_("Added %s to the download-list.") % url), MessageBox.TYPE_INFO)
630 self.session.open(MessageBox, (_("Error while adding %s to the download-list!") % url), MessageBox.TYPE_ERROR)
633 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)
635 def searchCallback(self, html=""):
639 if html.__contains__("Nothing found, sorry."):
640 self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: Nothing found, sorry.")), MessageBox.TYPE_ERROR)
641 self.instance.setTitle(_("Nothing found, sorry."))
644 while tmp.__contains__("goPg('"):
645 idx = tmp.index("goPg('")
648 pageNumber = tmp[:idx]
651 pageNumber = int(pageNumber)
652 if pageNumber > self.maxPage:
653 self.maxPage = pageNumber
657 self.instance.setTitle(_("Page %d / %d. Push < > to switch the page...")%(self.curPage, self.maxPage))
659 while html.__contains__('title="Download"'):
660 idx = html.index('title="Download"')
662 idx = html.index('value="')
664 idx = html.index('"')
666 idx = html.index('http://rapidshare.com/')
668 idx = html.index('"')
673 urllist = url.split("/")
674 idx = len(urllist) - 1
676 list.append("%s - %s"%(size, name))
678 list.append("%s - %s"%(size, url))
681 self["list"].setList(list)
683 def searchError(self, error=""):
684 self.session.open(MessageBox, (_("Error while searching http://rapidshare-search-engine.com!\n\nError: %s")%str(error)), MessageBox.TYPE_ERROR)
686 def previousPage(self):
689 self.instance.setTitle(_("Loading previous page... please wait!"))
693 if self.curPage < self.maxPage:
695 self.instance.setTitle(_("Loading next page... please wait!"))
698 ##############################################################################
700 class RSLogScreen(ChangedScreen):
702 <screen position="center,center" size="560,450" title="RS Downloader">
703 <widget name="label" position="0,0" size="560,450" font="Regular;20" />
706 def __init__(self, session):
707 ChangedScreen.__init__(self, session)
710 f = open("/tmp/rapidshare.log")
715 self["label"] = ScrollLabel(log)
717 self["actions"] = ActionMap(["WizardActions"],
721 "up": self["label"].pageUp,
722 "down": self["label"].pageDown,
723 "left": self["label"].pageUp,
724 "right": self["label"].pageDown
727 ##############################################################################
729 class RSList(MenuList):
730 def __init__(self, list):
731 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
732 self.l.setItemHeight(25)
733 self.l.setFont(0, gFont("Regular", 20))
735 ##############################################################################
737 def RSListEntry(download):
739 res.append(MultiContentEntryText(pos=(0, 0), size=(170, 25), font=0, text=download.name))
740 res.append(MultiContentEntryText(pos=(175, 0), size=(75, 25), font=0, text="%d%s"%(download.size, "MB"), flags=RT_HALIGN_CENTER))
741 res.append(MultiContentEntryPixmapAlphaTest(pos=(260, 9), size=(84, 7), png=LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/progress_bg.png"))))
742 res.append(MultiContentEntryPixmapAlphaTest(pos=(260, 10), size=(int(0.84 * download.progress), 5), png=LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/progress_small.png"))))
743 res.append(MultiContentEntryText(pos=(360, 0), size=(60, 25), font=0, text="%d%s"%(download.progress, "%"), flags=RT_HALIGN_CENTER))
744 res.append(MultiContentEntryText(pos=(420, 0), size=(140, 25), font=0, text=download.status, flags=RT_HALIGN_RIGHT))
747 ##############################################################################
749 class RSMain(ChangedScreen):
751 <screen position="center,center" size="560,450" title="RS Downloader">
752 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" transparent="1" alphatest="on" />
753 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" transparent="1" alphatest="on" />
754 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" transparent="1" alphatest="on" />
755 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" transparent="1" alphatest="on" />
756 <widget name="key_red" position="0,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
757 <widget name="key_green" position="140,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
758 <widget name="key_yellow" position="280,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
759 <widget name="key_blue" position="420,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
760 <widget name="list" position="0,40" size="560,400" scrollbarMode="showNever" />
763 def __init__(self, session):
764 ChangedScreen.__init__(self, session)
765 self.session = session
767 self["key_red"] = Label(_("Delete"))
768 self["key_green"] = Label(_("Search"))
769 self["key_yellow"] = Label(_("Add"))
770 self["key_blue"] = Label(_("Config"))
771 self["list"] = RSList([])
773 self.refreshTimer = eTimer()
774 self.refreshTimer.callback.append(self.updateList)
776 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "InfobarMenuActions"],
778 "mainMenu": self.menu,
779 "cancel": self.close,
781 "green": self.search,
786 self.onLayoutFinish.append(self.updateList)
790 #TODO: Add sort list functions
791 list.append((_("Delete download"), self.delete))
792 list.append((_("Use search engine"), self.search))
793 list.append((_("Add downloads from txt files"), self.add))
794 list.append((_("Delete failed downloads"), self.deleteFailed))
795 list.append((_("Restart failed downloads"), self.restartFailed))
796 list.append((_("Clear finished downloads"), self.clearFinished))
797 list.append((_("Show log"), self.showLog))
798 list.append((_("Delete log"), self.deleteLog))
799 list.append((_("Close plugin"), self.close))
800 self.session.openWithCallback(self.menuCallback, ChoiceBox, title=_("Please choose a function..."), list=list)
802 def menuCallback(self, callback=None):
803 if callback is not None:
806 def deleteFailed(self):
807 rapidshare.deleteFailedDownloads()
809 def restartFailed(self):
810 rapidshare.restartFailedDownloads()
812 def clearFinished(self):
813 rapidshare.clearFinishedDownloads()
816 self.session.open(RSLogScreen)
820 remove("/tmp/rapidshare.log")
824 def updateList(self):
826 for download in rapidshare.downloads:
827 list.append(RSListEntry(download))
828 self["list"].setList(list)
829 self.refreshTimer.start(2000, 1)
832 cur = self["list"].getCurrent()
835 if cur.status == _("Finished"):
836 rapidshare.clearFinishedDownload(cur.url)
838 self.session.openWithCallback(self.deleteCallback, MessageBox, (_("Delete %s?")%cur.name))
840 def deleteCallback(self, callback):
842 rapidshare.removeDownload(self["list"].getCurrent()[0].url)
843 self.refreshTimer.stop()
847 self.session.openWithCallback(self.searchCallback, VirtualKeyBoard, title=_("Search http://rapidshare-search-engine.com for:"))
849 def searchCallback(self, callback):
850 if callback is not None and callback != "":
851 self.session.openWithCallback(self.searchScreenCallback, RSSearch, callback)
854 def searchScreenCallback(self):
855 self.refreshTimer.stop()
859 self.refreshTimer.stop()
860 rapidshare.readLists()
864 self.session.openWithCallback(self.configCallback, RSConfig)
866 def configCallback(self):
867 if config.plugins.RSDownloader.onoff.value:
868 rapidshare.startDownloading()
870 for download in rapidshare.downloads:
871 if download.downloading:
875 ##############################################################################
877 def autostart(reason, **kwargs):
\r
879 rapidshare.startDownloading()
\r
881 ##############################################################################
\r
883 def main(session, **kwargs):
\r
884 session.open(RSMain)
\r
886 ##############################################################################
\r
888 def Plugins(**kwargs):
\r
890 PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart),
\r
891 PluginDescriptor(name=_("RS Downloader"), description=_("Download files from rapidshare"), where=[PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU], icon="rs.png", fnc=main)]