summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-01-29 02:19:37 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-01-29 02:19:37 +0100
commitf23019b934446275b97f0c5fecf7709c19e557f9 (patch)
treee8d5a3406a0f618868ca2abaa27c4c905d2efbc0 /module
parentMerge pull request #708 from glukgluk/patch-2 (diff)
downloadpyload-f23019b934446275b97f0c5fecf7709c19e557f9.tar.xz
[JustPremium] Cleanup
Diffstat (limited to 'module')
-rw-r--r--module/plugins/hooks/JustPremium.py110
-rw-r--r--module/plugins/hoster/FreeWayMe.py30
2 files changed, 58 insertions, 82 deletions
diff --git a/module/plugins/hooks/JustPremium.py b/module/plugins/hooks/JustPremium.py
index 2c5788b75..529628406 100644
--- a/module/plugins/hooks/JustPremium.py
+++ b/module/plugins/hooks/JustPremium.py
@@ -1,79 +1,55 @@
# -*- 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.
+from module.linkdict.Hook import Hook
- 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: mazleu
-"""
-from module.plugins.Hook import Hook
-from module.plugins.Account import Account
-from module.plugins.Hoster import Hoster
+class JustPremium(Hook):
+ __name__ = "JustPremium"
+ __type__ = "hook"
+ __version__ = "0.17"
+ __config__ = [("freehosters", "bool", "Allow all freehosters and other unknown sites", False),
+ ("nicehoster" , "str" , "unblock this hosters (comma seperated)" , "Zippyshare.com")]
-class JustPremium(Hook):
- __name__ = "JustPremium"
- __version__ = "0.16"
- __description__ = "If you add multiple links with at least one premium hoster link, all non premium links get removed"
- __config__ = [("activated", "bool", "Activated", "False"),
- ("freehosters","bool", "Allow all freehosters and other unknown sites", "false"),
- ("nicehoster", "str", "unblock this hosters (comma seperated)", "Zippyshare.com")]
+ __description__ = """Remove all not premium links from urls added"""
+ __license__ = "GPLv3"
+ __authors__ = [("mazleu", "mazleica@gmail.com")]
- __author_name__ = ("mazleu")
- __author_mail__ = ("mazleica@gmail.com")
event_list = ["linksAdded"]
+
def coreReady(self) :
- accs=str(self.core.accountManager.getAccountInfos())
- global badhosts
- global hosts
- hosts = ""
- while "[{" in accs:
- startid=accs.rfind("[], ", 0, accs.find("[{"))+2
- endid=accs.find("}]",startid)+2
- hosts=hosts+","+accs[startid+3:accs.find("'",startid+3)]
- accs=accs[0:startid]+accs[endid:]
- badhosts=accs.replace("': [], '",",")[2:-6]
- hosts=hosts[1:]
- hosts=hosts+","+self.getConfig("nicehoster")
- self.logDebug("good hosts:",hosts)
- self.logDebug("bad hosts:",badhosts)
-
-
- def filterLinks(self, t):
- links = self.core.api.checkURLs(t)
- hosterlist =""
- bhosters = [x.strip() for x in badhosts.split(",")]
- ghosters = [x.strip() for x in hosts.split(",")]
- premhoster = False
- for hoster in links:
- self.logDebug(hoster)
- if hoster in ghosters:
- premhoster = True
- self.logDebug ("Found at least one hoster with account")
- if premhoster :
- for hoster in links:
- if self.getConfig("freehosters"):
- if hoster in bhosters:
- self.logInfo("remove links from hoster '%s' " % (hoster))
- for link in links[hoster]:
- t.remove(link)
- self.logDebug("remove link '%s'because hoster was: '%s' " % (link,hoster))
- else:
- if not hoster in ghosters:
- self.logInfo("remove links from hoster '%s' " % (hoster))
- for link in links[hoster]:
- t.remove(link)
- self.logDebug("remove link '%s' because hoster was: '%s' " % (link,hoster))
+ hosts = ""
+ accounts = str(self.core.accountManager.getAccountInfos())
+
+ while "[{" in accounts:
+ startid = accounts.rfind("[], ", 0, accounts.find("[{")) + 2
+ endid = accounts.find("}]", startid) + 2
+ hosts = hosts + "," + accounts[startid+3:accounts.find("'",startid+3)]
+ accounts = accounts[0:startid] + accounts[endid:]
+
+ self.hosts = map(str.strip, (hosts[1:] + "," + self.getConfig("nicehoster")).split(','))
+ self.badhosts = map(str.strip, accounts.replace("': [], '",",")[2:-6].split(','))
+
+ self.logDebug("Hosts: %s" % ", ".join(self.hosts))
+ self.logDebug("Bad hosts: %s" % ", ".join(self.badhosts))
+
+
def linksAdded(self, links, pid):
- self.filterLinks(links)
+ linkdict = self.core.api.checkURLs(links)
+
+ #: Found at least one hoster with account
+ if not any(True for hoster in linkdict if hoster in self.hosts):
+ return
+
+ if self.getConfig("freehosters"):
+ bad_hosters = [hoster for hoster in linkdict.iterkeys() if hoster in self.badhosts]
+ else:
+ bad_hosters = [hoster for hoster in linkdict.iterkeys() if hoster not in self.hosts]
+
+ for hoster in bad_hosters:
+ self.logInfo(_("Remove links of hoster: %s") % hoster)
+ for link in linkdict[hoster]:
+ self.logDebug("Remove link: %s" % link)
+ links.remove(link)
diff --git a/module/plugins/hoster/FreeWayMe.py b/module/plugins/hoster/FreeWayMe.py
index 6d08e1f8d..76ffca505 100644
--- a/module/plugins/hoster/FreeWayMe.py
+++ b/module/plugins/hoster/FreeWayMe.py
@@ -27,27 +27,27 @@ class FreeWayMe(MultiHoster):
for _i in xrange(5):
# try it five times
header = self.load("https://www.free-way.me/load.php",
- get={'multiget': 7,
- 'url' : pyfile.url,
- 'user' : user,
- 'pw' : self.account.getAccountData(user)['password'],
- 'json' : ""}, just_header=True)
- if "location" in header:
- #download
- self.logInfo("Download: " + header['location'])
- headers = self.load(header['location'],just_header=True)
+ get={'multiget': 7,
+ 'url' : pyfile.url,
+ 'user' : user,
+ 'pw' : self.account.getAccountData(user)['password'],
+ 'json' : ""},
+ just_header=True)
+
+ if 'location' in header:
+ headers = self.load(header['location'], just_header=True)
if headers['code'] == 500:
- #error on 2nd stage
- self.logInfo("Free-Way Error [stage2]")
- # todo: handle errors
+ # error on 2nd stage
+ self.logError(_("Error [stage2]"))
else:
# seems to work..
self.download(header['location'])
break
else:
- #error page first stage
- self.logInfo("Free-Way Error [stage1]")
- # todo: handle errors
+ # error page first stage
+ self.logError(_("Error [stage1]"))
+
+ #@TODO: handle errors
getInfo = create_getInfo(FreeWayMe)