diff options
author | mkaay <mkaay@mkaay.de> | 2011-02-07 20:48:23 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2011-02-07 20:48:23 +0100 |
commit | 6c7725cee8f320ae8de087aaf753169f11c907f9 (patch) | |
tree | 87a1c1fed1158f44ad43734533705badd829cfc2 | |
parent | captchamanager fix (diff) | |
download | pyload-6c7725cee8f320ae8de087aaf753169f11c907f9.tar.xz |
Ev0InFetcher update (thanks to KurrKurr)
-rw-r--r-- | module/FileDatabase.py | 30 | ||||
-rw-r--r-- | module/StorageDatabase.py | 49 | ||||
-rw-r--r-- | module/plugins/PluginStorage.py | 11 | ||||
-rw-r--r-- | module/plugins/hooks/Ev0InFetcher.py | 35 | ||||
-rwxr-xr-x | pyLoadCore.py | 3 |
5 files changed, 82 insertions, 46 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py index 633f210e1..20548c136 100644 --- a/module/FileDatabase.py +++ b/module/FileDatabase.py @@ -532,18 +532,6 @@ class FileHandler: def restartFailed(self): """ restart all failed links """ self.db.restartFailed() - - @lock - @change - def setStorage(self, identifier, key, value): - self.db.setStorage(identifier, key, value) - - @lock - def getStorage(self, identifier, key, default=None): - value = self.db.getStorage(identifier, key) - if value is None: - return default - return value class FileMethods(): @style.queue @@ -842,24 +830,6 @@ class FileMethods(): DatabaseBackend.registerSub(FileMethods) -class StorageMethods(): - @style.queue - def setStorage(self, identifier, key, value): - self.c.execute("SELECT id FROM storage WHERE identifier=? AND key=?", (identifier, key)) - if self.c.fetchone() is not None: - self.c.execute("UPDATE storage SET value=? WHERE identifier=? AND key=?", (value, identifier, key)) - else: - self.c.execute("INSERT INTO storage (identifier, key, value) VALUES (?, ?, ?)", (identifier, key, value)) - - @style.queue - def getStorage(self, identifier, key): - self.c.execute("SELECT value FROM storage WHERE identifier=? AND key=?", (identifier, key)) - row = self.c.fetchone() - if row is not None: - return row[0] - -DatabaseBackend.registerSub(StorageMethods) - if __name__ == "__main__": pypath = "." diff --git a/module/StorageDatabase.py b/module/StorageDatabase.py new file mode 100644 index 000000000..9d3587340 --- /dev/null +++ b/module/StorageDatabase.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: mkaay +""" + +from module.DatabaseBackend import style +from module.DatabaseBackend import DatabaseBackend + +class StorageMethods(): + @style.queue + def setStorage(db, identifier, key, value): + db.c.execute("SELECT id FROM storage WHERE identifier=? AND key=?", (identifier, key)) + if db.c.fetchone() is not None: + db.c.execute("UPDATE storage SET value=? WHERE identifier=? AND key=?", (value, identifier, key)) + else: + db.c.execute("INSERT INTO storage (identifier, key, value) VALUES (?, ?, ?)", (identifier, key, value)) + + @style.queue + def getStorage(db, identifier, key=None): + if key is not None: + db.c.execute("SELECT value FROM storage WHERE identifier=? AND key=?", (identifier, key)) + row = db.c.fetchone() + if row is not None: + return row[0] + else: + db.c.execute("SELECT key, value FROM storage WHERE identifier=?", (identifier, )) + d = {} + if row in db.c: + d[row[0]] = row[1] + return d + + @style.queue + def delStorage(db, identifier, key): + db.c.execute("DELETE FROM storage WHERE identifier=? AND key=?", (identifier, key)) + +DatabaseBackend.registerSub(StorageMethods) diff --git a/module/plugins/PluginStorage.py b/module/plugins/PluginStorage.py index 31a3616f4..02498a446 100644 --- a/module/plugins/PluginStorage.py +++ b/module/plugins/PluginStorage.py @@ -17,8 +17,13 @@ """ class PluginStorage(): - def getStorage(self, key, default=None): - return self.core.files.getStorage(self.__name__, key, default) + def getStorage(self, key=None, default=None): + if key is not None: + return self.core.db.getStorage(self.__name__, key) or default + return self.core.db.getStorage(self.__name__, key) def setStorage(self, key, value): - self.core.files.setStorage(self.__name__, key, value) + self.core.db.setStorage(self.__name__, key, value) + + def delStorage(self, key): + self.core.db.delStorage(self.__name__, key) diff --git a/module/plugins/hooks/Ev0InFetcher.py b/module/plugins/hooks/Ev0InFetcher.py index 59e1c5462..9b9b11337 100644 --- a/module/plugins/hooks/Ev0InFetcher.py +++ b/module/plugins/hooks/Ev0InFetcher.py @@ -36,7 +36,7 @@ class Ev0InFetcher(Hook, PluginStorage): def setup(self): self.interval = self.getConfig("interval") * 60 - + def filterLinks(self, links): results = self.core.pluginManager.parseUrls(links) sortedLinks = {} @@ -63,16 +63,25 @@ class Ev0InFetcher(Hook, PluginStorage): shows = [s.strip() for s in self.getConfig("shows").split(",")] feed = feedparser.parse("http://feeds.feedburner.com/ev0in/%s?format=xml" % self.getConfig("quality")) - currentTime = time() - lastCheck = int(self.getStorage("last_check", 0)) - - for item in feed['items']: - if mktime(item.date_parsed) > lastCheck: - for x in shows: - if x.lower() in normalizefiletitle(item['title']): - links = self.filterLinks(item['description'].split("<br />")) - packagename = item['title'].encode("utf-8") - self.core.log.debug("Ev0InFetcher: new episode %s" % packagename) - self.core.server_methods.add_package(packagename, links, queue=(1 if self.getConfig("queue") else 0)) - self.setStorage("last_check", int(currentTime)) + + showStorage = {} + for show in shows: + showStorage[show] = int(self.getStorage("show_%s_lastfound" % show, 0)) + found = False + for item in feed['items']: + for show, lastfound in showStorage.iteritems(): + if show.lower() in normalizefiletitle(item['title']) and lastfound < int(mktime(item.date_parsed)): + links = self.filterLinks(item['description'].split("<br />")) + packagename = item['title'].encode("utf-8") + self.core.log.info("Ev0InFetcher: new episode '%s' (matched '%s')" % (packagename, show)) + self.core.server_methods.add_package(packagename, links, queue=(1 if self.getConfig("queue") else 0)) + self.setStorage("show_%s_lastfound" % show, int(mktime(item.date_parsed))) + found = True + if not found: + self.core.log.debug("Ev0InFetcher: no new episodes found") + + for show, lastfound in showStorage.iteritems(): + if lastfound > 0 and lastfound + (3600*24*30) < int(time()): + self.delStorage("show_%s_lastfound" % show) + self.core.log.debug("Ev0InFetcher: cleaned '%s' record" % show) diff --git a/pyLoadCore.py b/pyLoadCore.py index 1de5e20eb..6ad45c875 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -62,8 +62,11 @@ from module.Scheduler import Scheduler from module.JsEngine import JsEngine from module.remote.RemoteManager import RemoteManager from module.DatabaseBackend import DatabaseBackend + +#registering db methods from module.FileDatabase import FileHandler from module.UserDatabase import UserMethods +from module.StorageDatabase import StorageMethods from codecs import getwriter if os.name == "nt": |