From e948054ea4eb6bbba8091482cca52fd2454322a5 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 7 Apr 2015 19:30:29 +0200 Subject: New plugin: UserAgentSwitcher Fix https://github.com/pyload/pyload/issues/1305 --- module/plugins/hooks/UserAgentSwitcher.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 module/plugins/hooks/UserAgentSwitcher.py (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py new file mode 100644 index 000000000..56c605bac --- /dev/null +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +import pycurl + +from module.plugins.Hook import Hook + + +class UserAgentSwitcher(Hook): + __name__ = "UserAgentSwitcher" + __type__ = "hook" + __version__ = "0.01" + + __config__ = [("ua", "str", "Custom user-agent string", "")] + + __description__ = """Custom user-agent""" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] + + + interval = 0 #@TODO: Remove in 0.4.10 + + + def setup(self): + self.info = {} #@TODO: Remove in 0.4.10 + + + def downloadPreparing(self, pyfile): + ua = self.getConfig('ua') + if ua: + self.logDebug("Use custom user-agent string: " + ua) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua) -- cgit v1.2.3 From 48abd898139b3f40d52b17680c9d5b8a674545c6 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 8 Apr 2015 00:10:43 +0200 Subject: [UserAgentSwitcher] Default activated set to True --- module/plugins/hooks/UserAgentSwitcher.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 56c605bac..31eac9820 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -8,9 +8,10 @@ from module.plugins.Hook import Hook class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.01" + __version__ = "0.02" - __config__ = [("ua", "str", "Custom user-agent string", "")] + __config__ = [("activated", "bool", "Activated" , True ), + ("ua" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" -- cgit v1.2.3 From bc2ec03799dbb8479b8e519bb30eb5bf316dec57 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 8 Apr 2015 03:14:32 +0200 Subject: [UserAgentSwitcher] Fix https://github.com/pyload/pyload/issues/1324 --- module/plugins/hooks/UserAgentSwitcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 31eac9820..b0cf66709 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -8,7 +8,7 @@ from module.plugins.Hook import Hook class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.02" + __version__ = "0.03" __config__ = [("activated", "bool", "Activated" , True ), ("ua" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] @@ -29,4 +29,4 @@ class UserAgentSwitcher(Hook): ua = self.getConfig('ua') if ua: self.logDebug("Use custom user-agent string: " + ua) - pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua.encode('utf-8')) -- cgit v1.2.3 From 77ef36eae8c6d930656c5b060bf2e41b6f7fc743 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 8 Apr 2015 15:10:43 +0200 Subject: [UserAgentSwitcher] Random user-agent feature --- module/plugins/hooks/UserAgentSwitcher.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index b0cf66709..912c2ef09 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -1,17 +1,24 @@ # -*- coding: utf-8 -*- +from __future__ import with_statement + +import os import pycurl +import random from module.plugins.Hook import Hook +from module.utils import fs_encode class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.03" + __version__ = "0.04" __config__ = [("activated", "bool", "Activated" , True ), - ("ua" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] + ("uaf" , "file", "Random user-agents file" , "" ), + ("uar" , "bool", "Random user-agent" , False ), + ("uas" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" @@ -26,7 +33,15 @@ class UserAgentSwitcher(Hook): def downloadPreparing(self, pyfile): - ua = self.getConfig('ua') - if ua: - self.logDebug("Use custom user-agent string: " + ua) - pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua.encode('utf-8')) + uar = self.getConfig('uar') + uaf = fs_encode(self.getConfig('uaf')) + + if uar and os.path.isfile(uaf): + with open(uaf) as f: + uas = random.choice([ua for ua in f.read().splitlines()]) + else: + uas = self.getConfig('uas') + + if uas: + self.logDebug("Use custom user-agent string: " + uas) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, uas.encode('utf-8')) -- cgit v1.2.3 From 41faf73af4deb8dcd73e0c2e55073f1ef7656a7f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 18 May 2015 09:48:07 +0200 Subject: [XFSHoster] Fix https://github.com/pyload/pyload/issues/1296 --- module/plugins/hooks/UserAgentSwitcher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 912c2ef09..0b36e38ec 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -15,10 +15,10 @@ class UserAgentSwitcher(Hook): __type__ = "hook" __version__ = "0.04" - __config__ = [("activated", "bool", "Activated" , True ), - ("uaf" , "file", "Random user-agents file" , "" ), - ("uar" , "bool", "Random user-agent" , False ), - ("uas" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] + __config__ = [("activated", "bool", "Activated" , True ), + ("uaf" , "file", "Random user-agent by file" , "" ), + ("uar" , "bool", "Random user-agent" , False ), + ("uas" , "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" -- cgit v1.2.3 From 339b2e07d78b15ca014ee12f1501cdb235d9b064 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 18 May 2015 11:50:43 +0200 Subject: [SimpleHoster] Fix create_getInfo --- module/plugins/hooks/UserAgentSwitcher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 0b36e38ec..6915fc0f4 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -15,10 +15,10 @@ class UserAgentSwitcher(Hook): __type__ = "hook" __version__ = "0.04" - __config__ = [("activated", "bool", "Activated" , True ), - ("uaf" , "file", "Random user-agent by file" , "" ), - ("uar" , "bool", "Random user-agent" , False ), - ("uas" , "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")] + __config__ = [("activated", "bool", "Activated" , True ), + ("uaf" , "file", "Random user-agent by file", "" ), + ("uar" , "bool", "Random user-agent" , False ), + ("uas" , "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" -- cgit v1.2.3 From c3f05a91cb522e7dabc9dbbc4dd7a32d2cd766b3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 23 May 2015 05:45:09 +0200 Subject: [UserAgentSwitcher] Fixup --- module/plugins/hooks/UserAgentSwitcher.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 6915fc0f4..0a0072e63 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -1,24 +1,18 @@ # -*- coding: utf-8 -*- -from __future__ import with_statement - -import os import pycurl -import random from module.plugins.Hook import Hook -from module.utils import fs_encode +from module.utils import encode class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.04" + __version__ = "0.05" __config__ = [("activated", "bool", "Activated" , True ), - ("uaf" , "file", "Random user-agent by file", "" ), - ("uar" , "bool", "Random user-agent" , False ), - ("uas" , "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] + ("useragent", "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] __description__ = """Custom user-agent""" __license__ = "GPLv3" @@ -33,15 +27,7 @@ class UserAgentSwitcher(Hook): def downloadPreparing(self, pyfile): - uar = self.getConfig('uar') - uaf = fs_encode(self.getConfig('uaf')) - - if uar and os.path.isfile(uaf): - with open(uaf) as f: - uas = random.choice([ua for ua in f.read().splitlines()]) - else: - uas = self.getConfig('uas') - - if uas: - self.logDebug("Use custom user-agent string: " + uas) - pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, uas.encode('utf-8')) + useragent = encode(self.getConfig('useragent')) + if useragent: + self.logDebug("Use custom user-agent string: " + useragent) + pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, useragent) -- cgit v1.2.3 From fac22f3f706f247536ee11c15ae63b0988a2cc6b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 25 May 2015 14:06:56 +0200 Subject: [UserAgentSwitcher] Fixup (2) --- module/plugins/hooks/UserAgentSwitcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 0a0072e63..16d38d2cc 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -9,7 +9,7 @@ from module.utils import encode class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.05" + __version__ = "0.06" __config__ = [("activated", "bool", "Activated" , True ), ("useragent", "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] @@ -27,7 +27,7 @@ class UserAgentSwitcher(Hook): def downloadPreparing(self, pyfile): - useragent = encode(self.getConfig('useragent')) + useragent = self.getConfig('useragent').encode("utf8", "replace") #@TODO: Remove `encode` in 0.4.10 if useragent: self.logDebug("Use custom user-agent string: " + useragent) pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, useragent) -- cgit v1.2.3 From 8fdf78569ba68c8ee4849cbfc144a9fbdac263f5 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 25 May 2015 17:04:49 +0200 Subject: [UserAgentSwitcher] Fixup (3) --- module/plugins/hooks/UserAgentSwitcher.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/plugins/hooks/UserAgentSwitcher.py') diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py index 16d38d2cc..5f9fd5212 100644 --- a/module/plugins/hooks/UserAgentSwitcher.py +++ b/module/plugins/hooks/UserAgentSwitcher.py @@ -3,13 +3,12 @@ import pycurl from module.plugins.Hook import Hook -from module.utils import encode class UserAgentSwitcher(Hook): __name__ = "UserAgentSwitcher" __type__ = "hook" - __version__ = "0.06" + __version__ = "0.07" __config__ = [("activated", "bool", "Activated" , True ), ("useragent", "str" , "Custom user-agent string" , "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0")] -- cgit v1.2.3