summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-23 05:45:09 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-05-23 05:45:09 +0200
commitc3f05a91cb522e7dabc9dbbc4dd7a32d2cd766b3 (patch)
tree5b8bf579aa7a8e17f3165d92898a2ad4532c219c
parentTiny code cosmetics (diff)
downloadpyload-c3f05a91cb522e7dabc9dbbc4dd7a32d2cd766b3.tar.xz
[UserAgentSwitcher] Fixup
-rw-r--r--module/plugins/hooks/UserAgentSwitcher.py28
1 files changed, 7 insertions, 21 deletions
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)