From 4ec80126459c8d210951d96cb86023ac55be265f Mon Sep 17 00:00:00 2001 From: Stephan Reichholf Date: Thu, 20 Aug 2009 20:22:39 +0000 Subject: [PATCH] no need for brackets when there's no inheritence --- rsdownloader/src/plugin.py | 380 ++++++++++++++++++++++----------------------- 1 file changed, 190 insertions(+), 190 deletions(-) diff --git a/rsdownloader/src/plugin.py b/rsdownloader/src/plugin.py index 84f260b..83692bf 100644 --- a/rsdownloader/src/plugin.py +++ b/rsdownloader/src/plugin.py @@ -29,17 +29,17 @@ from twisted.python import failure from twisted.web.client import getPage from urlparse import urlparse, urlunparse import gettext, re, socket, urllib2 - + ############################################################################## config.plugins.RSDownloader = ConfigSubsection() -config.plugins.RSDownloader.onoff = ConfigYesNo(default=True) -config.plugins.RSDownloader.username = ConfigText(default="", fixed_size=False) -config.plugins.RSDownloader.password = ConfigText(default="", fixed_size=False) -config.plugins.RSDownloader.lists_directory = ConfigText(default="/media/hdd/rs/lists/", fixed_size=False) +config.plugins.RSDownloader.onoff = ConfigYesNo(default=True) +config.plugins.RSDownloader.username = ConfigText(default="", fixed_size=False) +config.plugins.RSDownloader.password = ConfigText(default="", fixed_size=False) +config.plugins.RSDownloader.lists_directory = ConfigText(default="/media/hdd/rs/lists/", fixed_size=False) config.plugins.RSDownloader.downloads_directory = ConfigText(default="/media/hdd/rs/downloads", fixed_size=False) -config.plugins.RSDownloader.ignore_time = ConfigYesNo(default=False) -config.plugins.RSDownloader.start_time = ConfigClock(default=time()) +config.plugins.RSDownloader.ignore_time = ConfigYesNo(default=False) +config.plugins.RSDownloader.start_time = ConfigClock(default=time()) config.plugins.RSDownloader.end_time = ConfigClock(default=time()) config.plugins.RSDownloader.download_monday = ConfigYesNo(default=True) config.plugins.RSDownloader.download_tuesday = ConfigYesNo(default=True) @@ -47,37 +47,37 @@ config.plugins.RSDownloader.download_wednesday = ConfigYesNo(default=True) config.plugins.RSDownloader.download_thursday = ConfigYesNo(default=True) config.plugins.RSDownloader.download_friday = ConfigYesNo(default=True) config.plugins.RSDownloader.download_saturday = ConfigYesNo(default=True) -config.plugins.RSDownloader.download_sunday = ConfigYesNo(default=True) +config.plugins.RSDownloader.download_sunday = ConfigYesNo(default=True) config.plugins.RSDownloader.count_downloads = ConfigInteger(default=3, limits=(1, 6)) config.plugins.RSDownloader.write_log = ConfigYesNo(default=True) config.plugins.RSDownloader.reconnect_fritz = ConfigYesNo(default=False) config.plugins.RSDownloader.autorestart_failed = ConfigYesNo(default=False) -############################################################################## +############################################################################## def localeInit(): lang = language.getLanguage() - environ["LANGUAGE"] = lang[:2] - gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE)) + environ["LANGUAGE"] = lang[:2] + gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE)) gettext.textdomain("enigma2") gettext.bindtextdomain("RSDownloader", "%s%s"%(resolveFilename(SCOPE_PLUGINS), "Extensions/RSDownloader/locale/")) -def _(txt): - t = gettext.dgettext("RSDownloader", txt) - if t == txt: - t = gettext.gettext(txt) +def _(txt): + t = gettext.dgettext("RSDownloader", txt) + if t == txt: + t = gettext.gettext(txt) return t -localeInit() +localeInit() language.addCallback(localeInit) ############################################################################## def writeLog(message): if config.plugins.RSDownloader.write_log.value: - try: - f = open("/tmp/rapidshare.log", "a") - f.write(strftime("%c", localtime(time())) + " - " + message + "\n") + try: + f = open("/tmp/rapidshare.log", "a") + f.write(strftime("%c", localtime(time())) + " - " + message + "\n") f.close() except: pass @@ -106,7 +106,7 @@ def _parse(url): path = "/" return scheme, host, port, path, username, password -class ProgressDownload(): +class ProgressDownload: def __init__(self, url, outputfile, contextFactory=None, *args, **kwargs): scheme, host, port, path, username, password = _parse(url) if username and password: @@ -183,7 +183,7 @@ def reconnect(host='fritz.box', port=49000): ############################################################################## -class RSDownload(): +class RSDownload: def __init__(self, url): writeLog("Adding: %s"%url) self.url = url @@ -324,9 +324,9 @@ class RSDownload(): self.status = _("Checking") self.checkTimer.start(10000, 1) - def getYoutubeDownloadLink(self): - mrl = None - html = get(self.url) + def getYoutubeDownloadLink(self): + mrl = None + html = get(self.url) if html != "": isHDAvailable = False video_id = None @@ -338,27 +338,27 @@ class RSDownload(): if self.name.startswith("YouTube - "): self.name = (self.name[10:]).replace("&", "&") if html.__contains__("isHDAvailable = true"): - isHDAvailable = True - for line in html.split('\n'): - if 'swfArgs' in line: - line = line.strip().split() - x = 0 - for thing in line: - if 'video_id' in thing: - video_id = line[x+1][1:-2] - elif '"t":' == thing: - t = line[x+1][1:-2] + isHDAvailable = True + for line in html.split('\n'): + if 'swfArgs' in line: + line = line.strip().split() + x = 0 + for thing in line: + if 'video_id' in thing: + video_id = line[x+1][1:-2] + elif '"t":' == thing: + t = line[x+1][1:-2] x += 1 if video_id and t: if isHDAvailable == True: mrl = "http://www.youtube.com/get_video?video_id=%s&t=%s&fmt=22" % (video_id, t) else: - mrl = "http://www.youtube.com/get_video?video_id=%s&t=%s&fmt=18" % (video_id, t) + mrl = "http://www.youtube.com/get_video?video_id=%s&t=%s&fmt=18" % (video_id, t) return mrl ############################################################################## -class RS(): +class RS: def __init__(self): self.downloads = [] self.checkTimer = eTimer() @@ -371,9 +371,9 @@ class RS(): return False elif config.plugins.RSDownloader.ignore_time.value: return True - else: - start = config.plugins.RSDownloader.start_time.value - end = config.plugins.RSDownloader.end_time.value + else: + start = config.plugins.RSDownloader.start_time.value + end = config.plugins.RSDownloader.end_time.value t = localtime() weekday = t[6] if weekday == 0 and config.plugins.RSDownloader.download_monday.value == False: @@ -390,31 +390,31 @@ class RS(): return False elif weekday == 6 and config.plugins.RSDownloader.download_sunday.value == False: return False - else: - hour_now = t[3] - minute_now = t[4] - hour_start = start[0] - minute_start = start[1] - hour_end = end[0] - minute_end = end[1] - if start == end: # Same start and end-time - return True - elif hour_end < hour_start: # Different days!!! - if hour_now > hour_start or hour_now < hour_end: - return True - elif hour_now == hour_start and minute_now > minute_start: - return True - elif hour_now == hour_end and minute_now < minute_end: + else: + hour_now = t[3] + minute_now = t[4] + hour_start = start[0] + minute_start = start[1] + hour_end = end[0] + minute_end = end[1] + if start == end: # Same start and end-time + return True + elif hour_end < hour_start: # Different days!!! + if hour_now > hour_start or hour_now < hour_end: + return True + elif hour_now == hour_start and minute_now > minute_start: + return True + elif hour_now == hour_end and minute_now < minute_end: return True else: - return False - elif hour_now > hour_start and hour_now < hour_end: # Same day... - return True - elif hour_now == hour_start and minute_now > minute_start: # Same day, same start-hour... - return True - elif hour_now == hour_end and minute_now < minute_end: # Same day, same end-hour... - return True - else: + return False + elif hour_now > hour_start and hour_now < hour_end: # Same day... + return True + elif hour_now == hour_start and minute_now > minute_start: # Same day, same start-hour... + return True + elif hour_now == hour_end and minute_now < minute_end: # Same day, same end-hour... + return True + else: return False def allDownloadsFinished(self): @@ -459,62 +459,62 @@ class RS(): self.downloads.append(download) return True - def readLists(self): - writeLog("Reading all lists...") - path = config.plugins.RSDownloader.lists_directory.value - if not path.endswith("/"): - path = path + "/" - writeLog("Directory: " + path) - try: - file_list = listdir(path) - writeLog("Count of lists: " + str(len(file_list))) - except: - file_list = [] - writeLog("Could not find any list!") - for x in file_list: + def readLists(self): + writeLog("Reading all lists...") + path = config.plugins.RSDownloader.lists_directory.value + if not path.endswith("/"): + path = path + "/" + writeLog("Directory: " + path) + try: + file_list = listdir(path) + writeLog("Count of lists: " + str(len(file_list))) + except: + file_list = [] + writeLog("Could not find any list!") + for x in file_list: list = path + x - if list.endswith(".txt"): - try: - writeLog("Reading list %s..."%list) + if list.endswith(".txt"): + try: + writeLog("Reading list %s..."%list) f = open(list, "r") - count = 0 - for l in f: - if l.startswith("http://"): + count = 0 + for l in f: + if l.startswith("http://"): if (self.addDownload(l.replace("\n", "").replace("\r", ""))) == True: - count += 1 + count += 1 f.close() if count == 0: writeLog("Empty list or downloads already in download list: %s"%list) else: - writeLog("Added %d files from list %s..."%(count, list)) - except: + writeLog("Added %d files from list %s..."%(count, list)) + except: writeLog("Error while reading list %s!"%list) else: writeLog("No *.txt file: %s!"%list) def cleanLists(self): - writeLog("Cleaning lists...") - path = config.plugins.RSDownloader.lists_directory.value - if not path.endswith("/"): - path = path + "/" - try: - file_list = listdir(path) - except: - file_list = [] - for x in file_list: - list = path + x - try: - f = open(list, "r") - content = f.read() + writeLog("Cleaning lists...") + path = config.plugins.RSDownloader.lists_directory.value + if not path.endswith("/"): + path = path + "/" + try: + file_list = listdir(path) + except: + file_list = [] + for x in file_list: + list = path + x + try: + f = open(list, "r") + content = f.read() f.close() for download in self.downloads: - if download.status == _("Finished") and content.__contains__(download.url): - content = content.replace(download.url, "") - content = content.replace("\n\n", "\n").replace("\r\r", "\r") - f = open(list, "w") - f.write(content) - f.close() - except: + if download.status == _("Finished") and content.__contains__(download.url): + content = content.replace(download.url, "") + content = content.replace("\n\n", "\n").replace("\r\r", "\r") + f = open(list, "w") + f.write(content) + f.close() + except: writeLog("Error while cleaning list %s!"%list) self.startDownloading() @@ -529,27 +529,27 @@ class RS(): self.downloads = tmp self.removeFromLists(url) - def removeFromLists(self, url): - path = config.plugins.RSDownloader.lists_directory.value - if not path.endswith("/"): - path = path + "/" - try: - file_list = listdir(path) - except: - file_list = [] - for x in file_list: - list = path + x - try: - f = open(list, "r") - content = f.read() + def removeFromLists(self, url): + path = config.plugins.RSDownloader.lists_directory.value + if not path.endswith("/"): + path = path + "/" + try: + file_list = listdir(path) + except: + file_list = [] + for x in file_list: + list = path + x + try: + f = open(list, "r") + content = f.read() f.close() - if content.__contains__(url): - content = content.replace(url, "") - content = content.replace("\n\n", "\n").replace("\r\r", "\r") - f = open(list, "w") - f.write(content) - f.close() - except: + if content.__contains__(url): + content = content.replace(url, "") + content = content.replace("\n\n", "\n").replace("\r\r", "\r") + f = open(list, "w") + f.write(content) + f.close() + except: pass def clearFinishedDownload(self, url): @@ -598,62 +598,62 @@ rapidshare = RS() ############################################################################## class ChangedScreen(Screen): - def __init__(self, session, parent=None): - Screen.__init__(self, session, parent) - self.onLayoutFinish.append(self.setScreenTitle) - - def setScreenTitle(self): + def __init__(self, session, parent=None): + Screen.__init__(self, session, parent) + self.onLayoutFinish.append(self.setScreenTitle) + + def setScreenTitle(self): self.setTitle(_("RS Downloader")) ############################################################################## -class RSConfig(ConfigListScreen, ChangedScreen): - skin = """ - - - - - - - - """ - - def __init__(self, session): - ChangedScreen.__init__(self, session) - - self["key_green"] = Label(_("Save")) - - ConfigListScreen.__init__(self, [ - getConfigListEntry(_("Download in the background:"), config.plugins.RSDownloader.onoff), - getConfigListEntry(_("Username:"), config.plugins.RSDownloader.username), - getConfigListEntry(_("Password:"), config.plugins.RSDownloader.password), - getConfigListEntry(_("Lists directory:"), config.plugins.RSDownloader.lists_directory), - getConfigListEntry(_("Downloads directory:"), config.plugins.RSDownloader.downloads_directory), - getConfigListEntry(_("Ignore download times:"), config.plugins.RSDownloader.ignore_time), - getConfigListEntry(_("Allow downloading on monday:"), config.plugins.RSDownloader.download_monday), - getConfigListEntry(_("Allow downloading on tuesday:"), config.plugins.RSDownloader.download_tuesday), - getConfigListEntry(_("Allow downloading on wednesday:"), config.plugins.RSDownloader.download_wednesday), - getConfigListEntry(_("Allow downloading on thursday:"), config.plugins.RSDownloader.download_thursday), - getConfigListEntry(_("Allow downloading on friday:"), config.plugins.RSDownloader.download_friday), - getConfigListEntry(_("Allow downloading on saturday:"), config.plugins.RSDownloader.download_saturday), +class RSConfig(ConfigListScreen, ChangedScreen): + skin = """ + + + + + + + + """ + + def __init__(self, session): + ChangedScreen.__init__(self, session) + + self["key_green"] = Label(_("Save")) + + ConfigListScreen.__init__(self, [ + getConfigListEntry(_("Download in the background:"), config.plugins.RSDownloader.onoff), + getConfigListEntry(_("Username:"), config.plugins.RSDownloader.username), + getConfigListEntry(_("Password:"), config.plugins.RSDownloader.password), + getConfigListEntry(_("Lists directory:"), config.plugins.RSDownloader.lists_directory), + getConfigListEntry(_("Downloads directory:"), config.plugins.RSDownloader.downloads_directory), + getConfigListEntry(_("Ignore download times:"), config.plugins.RSDownloader.ignore_time), + getConfigListEntry(_("Allow downloading on monday:"), config.plugins.RSDownloader.download_monday), + getConfigListEntry(_("Allow downloading on tuesday:"), config.plugins.RSDownloader.download_tuesday), + getConfigListEntry(_("Allow downloading on wednesday:"), config.plugins.RSDownloader.download_wednesday), + getConfigListEntry(_("Allow downloading on thursday:"), config.plugins.RSDownloader.download_thursday), + getConfigListEntry(_("Allow downloading on friday:"), config.plugins.RSDownloader.download_friday), + getConfigListEntry(_("Allow downloading on saturday:"), config.plugins.RSDownloader.download_saturday), getConfigListEntry(_("Allow downloading on sunday:"), config.plugins.RSDownloader.download_sunday), - getConfigListEntry(_("Don't download before:"), config.plugins.RSDownloader.start_time), - getConfigListEntry(_("Don't download after:"), config.plugins.RSDownloader.end_time), - getConfigListEntry(_("Maximal downloads:"), config.plugins.RSDownloader.count_downloads), + getConfigListEntry(_("Don't download before:"), config.plugins.RSDownloader.start_time), + getConfigListEntry(_("Don't download after:"), config.plugins.RSDownloader.end_time), + getConfigListEntry(_("Maximal downloads:"), config.plugins.RSDownloader.count_downloads), getConfigListEntry(_("Write log:"), config.plugins.RSDownloader.write_log), getConfigListEntry(_("Reconnect fritz.Box before downloading:"), config.plugins.RSDownloader.reconnect_fritz), - getConfigListEntry(_("Restart failed after 10 minutes:"), config.plugins.RSDownloader.autorestart_failed)]) - - self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], {"green": self.save, "cancel": self.exit}, -1) - - def save(self): - for x in self["config"].list: - x[1].save() - self.close() - - def exit(self): - for x in self["config"].list: - x[1].cancel() + getConfigListEntry(_("Restart failed after 10 minutes:"), config.plugins.RSDownloader.autorestart_failed)]) + + self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], {"green": self.save, "cancel": self.exit}, -1) + + def save(self): + for x in self["config"].list: + x[1].save() + self.close() + + def exit(self): + for x in self["config"].list: + x[1].cancel() self.close() ############################################################################## @@ -714,7 +714,7 @@ class RSSearch(Screen): tmp = tmp[idx+6:] idx = tmp.index("'") pageNumber = tmp[:idx] - + try: pageNumber = int(pageNumber) if pageNumber > self.maxPage: @@ -963,9 +963,9 @@ class RSMain(ChangedScreen): self.updateList() def addContainer(self): - try: - file_list = listdir(config.plugins.RSDownloader.lists_directory.value) - except: + try: + file_list = listdir(config.plugins.RSDownloader.lists_directory.value) + except: file_list = [] list = [] for file in file_list: @@ -996,19 +996,19 @@ class RSMain(ChangedScreen): ############################################################################## -def autostart(reason, **kwargs): - if reason == 0: - rapidshare.startDownloading() - -############################################################################## - -def main(session, **kwargs): - session.open(RSMain) - -############################################################################## - -def Plugins(**kwargs): +def autostart(reason, **kwargs): + if reason == 0: + rapidshare.startDownloading() + +############################################################################## + +def main(session, **kwargs): + session.open(RSMain) + +############################################################################## + +def Plugins(**kwargs): return [ - PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart), + PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart), PluginDescriptor(name=_("RS Downloader"), description=_("Download files from rapidshare"), where=[PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU], icon="rs.png", fnc=main)] -- 2.7.4