summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2011-01-26 00:37:08 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2011-01-26 00:37:08 +0100
commit623eefac57533009672cc5a46a85c123ed43477d (patch)
tree6b57e371ec6892b08c5334ea59bd3cbdcbef51d8
parentmoved hooks periodical call to scheduler (diff)
downloadpyload-623eefac57533009672cc5a46a85c123ed43477d.tar.xz
added data storage (currently used for plugins), ev0.in rss fetcher, ul.to maxtraffic fix
-rw-r--r--module/FileDatabase.py63
-rw-r--r--module/HookManager.py2
-rw-r--r--module/plugins/PluginStorage.py24
-rw-r--r--module/plugins/accounts/UploadedTo.py2
-rw-r--r--module/plugins/hooks/Ev0InFetcher.py78
5 files changed, 159 insertions, 10 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py
index 631269030..20d67082a 100644
--- a/module/FileDatabase.py
+++ b/module/FileDatabase.py
@@ -41,7 +41,7 @@ try:
except:
import sqlite3
-DB_VERSION = 2
+DB_VERSION = 3
########################################################################
class FileHandler:
@@ -535,6 +535,18 @@ 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 FileDatabaseBackend(Thread):
@@ -551,8 +563,6 @@ class FileDatabaseBackend(Thread):
self.jobs = Queue() # queues for jobs
self.res = Queue()
-
- self._checkVersion()
self.start()
@@ -583,10 +593,15 @@ class FileDatabaseBackend(Thread):
def run(self):
"""main loop, which executes commands"""
-
+ convert = self._checkVersion() #returns None or current version
+
self.conn = sqlite3.connect("files.db")
self.c = self.conn.cursor()
#self.c.execute("PRAGMA synchronous = OFF")
+
+ if convert is not None:
+ self._convertDB(convert)
+
self._createTables()
self.used = 0
@@ -633,19 +648,36 @@ class FileDatabaseBackend(Thread):
v = int(f.read().strip())
f.close()
if v < DB_VERSION:
- self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version."))
- remove("files.version")
- move("files.db", "files.backup.db")
+ if v < 2:
+ self.manager.core.log.warning(_("Filedatabase was deleted due to incompatible version."))
+ remove("files.version")
+ move("files.db", "files.backup.db")
f = open("files.version", "wb")
f.write(str(DB_VERSION))
f.close()
-
+ return v
+
+ def _convertDB(self, v):
+ try:
+ getattr(self, "_convertV%i" % v)()
+ except:
+ self.manager.core.log.error(_("Filedatabase could NOT be converted."))
+
+ #--convert scripts start
+
+ def _convertV2(self):
+ self.c.execute('CREATE TABLE IF NOT EXISTS "storage" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "identifier" TEXT NOT NULL, "key" TEXT NOT NULL, "value" TEXT DEFAULT "")')
+ self.manager.core.log.info(_("Filedatabase was converted from v2 to v3."))
+
+ #--convert scripts end
+
def _createTables(self):
"""create tables for database"""
self.c.execute('CREATE TABLE IF NOT EXISTS "packages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "folder" TEXT, "password" TEXT DEFAULT "", "site" TEXT DEFAULT "", "queue" INTEGER DEFAULT 0 NOT NULL, "packageorder" INTEGER DEFAULT 0 NOT NULL, "priority" INTEGER DEFAULT 0 NOT NULL)')
self.c.execute('CREATE TABLE IF NOT EXISTS "links" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "url" TEXT NOT NULL, "name" TEXT, "size" INTEGER DEFAULT 0 NOT NULL, "status" INTEGER DEFAULT 3 NOT NULL, "plugin" TEXT DEFAULT "BasePlugin" NOT NULL, "error" TEXT DEFAULT "", "linkorder" INTEGER DEFAULT 0 NOT NULL, "package" INTEGER DEFAULT 0 NOT NULL, FOREIGN KEY(package) REFERENCES packages(id))')
self.c.execute('CREATE INDEX IF NOT EXISTS "pIdIndex" ON links(package)')
+ self.c.execute('CREATE TABLE IF NOT EXISTS "storage" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "identifier" TEXT NOT NULL, "key" TEXT NOT NULL, "value" TEXT DEFAULT "")')
self.c.execute('VACUUM')
#----------------------------------------------------------------------
@@ -944,6 +976,21 @@ class FileDatabaseBackend(Thread):
@queue
def restartFailed(self):
self.c.execute("UPDATE links SET status=3,error='' WHERE status IN (8, 9)")
+
+ @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))
+
+ @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]
if __name__ == "__main__":
diff --git a/module/HookManager.py b/module/HookManager.py
index 69e922d14..bc79b3c1c 100644
--- a/module/HookManager.py
+++ b/module/HookManager.py
@@ -77,7 +77,7 @@ class HookManager():
try:
plugin.periodical()
except Exception, e:
- args[0].log.error(_("Error executing hooks: %s") % str(e))
+ self.core.log.error(_("Error executing hooks: %s") % str(e))
if self.core.debug:
traceback.print_exc()
diff --git a/module/plugins/PluginStorage.py b/module/plugins/PluginStorage.py
new file mode 100644
index 000000000..31a3616f4
--- /dev/null
+++ b/module/plugins/PluginStorage.py
@@ -0,0 +1,24 @@
+# -*- 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
+"""
+
+class PluginStorage():
+ def getStorage(self, key, default=None):
+ return self.core.files.getStorage(self.__name__, key, default)
+
+ def setStorage(self, key, value):
+ self.core.files.setStorage(self.__name__, key, value)
diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py
index 94d78d63c..42dcb2d29 100644
--- a/module/plugins/accounts/UploadedTo.py
+++ b/module/plugins/accounts/UploadedTo.py
@@ -36,7 +36,7 @@ class UploadedTo(Account):
traffic = int(self.parseTraffic(raw_traffic))
validuntil = int(mktime(strptime(raw_valid.strip(), "%d-%m-%Y %H:%M")))
- tmp = {"validuntil":validuntil, "trafficleft":traffic, "maxtraffic":100*1024*1024}
+ tmp = {"validuntil":validuntil, "trafficleft":traffic, "maxtraffic":50*1024*1024}
return tmp
def login(self, user, data, req):
diff --git a/module/plugins/hooks/Ev0InFetcher.py b/module/plugins/hooks/Ev0InFetcher.py
new file mode 100644
index 000000000..18524ec5a
--- /dev/null
+++ b/module/plugins/hooks/Ev0InFetcher.py
@@ -0,0 +1,78 @@
+# -*- 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
+"""
+import feedparser
+from time import mktime, time
+
+from module.plugins.Hook import Hook
+from module.plugins.PluginStorage import PluginStorage
+
+class Ev0InFetcher(Hook, PluginStorage):
+ __name__ = "Ev0InFetcher"
+ __version__ = "0.1"
+ __description__ = """checks rss feeds for ev0.in"""
+ __config__ = [("activated", "bool", "Activated", "False"),
+ ("interval", "int", "Check interval in minutes", "10"),
+ ("queue", "bool", "Move new shows directly to Queue", False),
+ ("shows", "str", "Shows to check for (comma seperated)", ""),
+ ("quality", "str", "xvid/x264/rmvb", "xvid"),
+ ("hoster", "str", "Hoster to use (comma seperated)", "NetloadIn,RapidshareCom,MegauploadCom,HotfileCom")]
+ __author_name__ = ("mkaay")
+ __author_mail__ = ("mkaay@mkaay.de")
+
+ def setup(self):
+ self.interval = self.getConfig("interval") * 60
+
+ def filterLinks(self, links):
+ results = self.core.pluginManager.parseUrls(links)
+ sortedLinks = {}
+
+ for url, hoster in results:
+ if not sortedLinks.has_key(hoster):
+ sortedLinks[hoster] = []
+ sortedLinks[hoster].append(url)
+
+ for h in self.getConfig("hoster").split(","):
+ try:
+ return sortedLinks[h.strip()]
+ except:
+ continue
+ return []
+
+ def periodical(self):
+ def normalizefiletitle(filename):
+ filename = filename.replace('.', ' ')
+ filename = filename.replace('_', ' ')
+ filename = filename.lower()
+ return filename
+
+ 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))
+