diff options
| author | 2014-12-06 22:47:56 +0100 | |
|---|---|---|
| committer | 2014-12-06 22:47:56 +0100 | |
| commit | f4db1a3ce2692b9f310dac1548c1966bcea319a2 (patch) | |
| tree | 229030d57e3d5a68cfb7245cbc042df16a3c261c /module | |
| parent | [SkipRev] Update (diff) | |
| download | pyload-f4db1a3ce2692b9f310dac1548c1966bcea319a2.tar.xz | |
Plugin code cosmetics (2)
Diffstat (limited to 'module')
| -rw-r--r-- | module/plugins/hoster/DailymotionCom.py | 41 | ||||
| -rw-r--r-- | module/plugins/hoster/MegaCoNz.py | 33 | ||||
| -rw-r--r-- | module/plugins/hoster/YoutubeCom.py | 44 | 
3 files changed, 77 insertions, 41 deletions
| diff --git a/module/plugins/hoster/DailymotionCom.py b/module/plugins/hoster/DailymotionCom.py index 6dd357260..09b2f626d 100644 --- a/module/plugins/hoster/DailymotionCom.py +++ b/module/plugins/hoster/DailymotionCom.py @@ -9,19 +9,17 @@ from module.plugins.Hoster import Hoster  def getInfo(urls): -    result = []  #: [ .. (name, size, status, url) .. ] -    regex = re.compile(DailymotionCom.__pattern__) -    apiurl = "https://api.dailymotion.com/video/" +    result  = [] +    regex   = re.compile(DailymotionCom.__pattern__) +    apiurl  = "https://api.dailymotion.com/video/%s"      request = {"fields": "access_error,status,title"} +      for url in urls: -        id = regex.search(url).group("ID") -        page = getURL(apiurl + id, get=request) +        id   = regex.match(url).group("ID") +        page = getURL(apiurl % id, get=request)          info = json_loads(page) -        if "title" in info: -            name = info['title'] + ".mp4" -        else: -            name = url +        name = info['title'] + ".mp4" if "title" in info else url          if "error" in info or info['access_error']:              status = "offline" @@ -35,6 +33,7 @@ def getInfo(urls):                  status = "offline"          result.append((name, 0, statusMap[status], url)) +      return result @@ -43,8 +42,8 @@ class DailymotionCom(Hoster):      __type__    = "hoster"      __version__ = "0.2" -    __pattern__ = r'https?://(?:www\.)?dailymotion\.com/.*?video/(?P<ID>[\w^_]+)' -    __config__ = [("quality", "Lowest;LD 144p;LD 240p;SD 384p;HQ 480p;HD 720p;HD 1080p;Highest", "Quality", "Highest")] +    __pattern__ = r'https?://(?:www\.)?dailymotion\.com/.*video/(?P<ID>[\w^_]+)' +    __config__  = [("quality", "Lowest;LD 144p;LD 240p;SD 384p;HQ 480p;HD 720p;HD 1080p;Highest", "Quality", "Highest")]      __description__ = """Dailymotion.com hoster plugin"""      __license__     = "GPLv3" @@ -52,29 +51,36 @@ class DailymotionCom(Hoster):      def setup(self): -        self.resumeDownload = self.multiDL = True +        self.resumeDownload = True +        self.multiDL        = True      def getStreams(self):          streams = [] +          for result in re.finditer(r"\"(?P<URL>http:\\/\\/www.dailymotion.com\\/cdn\\/H264-(?P<QF>.*?)\\.*?)\"",                                    self.html):              url = result.group("URL") -            qf = result.group("QF") -            link = url.replace("\\", "") +            qf  = result.group("QF") + +            link    = url.replace("\\", "")              quality = tuple(int(x) for x in qf.split("x")) +              streams.append((quality, link)) +          return sorted(streams, key=lambda x: x[0][::-1])      def getQuality(self):          q = self.getConfig("quality") +          if q == "Lowest":              quality = 0          elif q == "Highest":              quality = -1          else:              quality = int(q.rsplit(" ")[1][:-1]) +          return quality @@ -91,14 +97,18 @@ class DailymotionCom(Hoster):              idx = quality          s = streams[idx] +          self.logInfo(_("Download video quality %sx%s") % s[0]) +          return s[1]      def checkInfo(self, pyfile):          pyfile.name, pyfile.size, pyfile.status, pyfile.url = getInfo([pyfile.url])[0] +          if pyfile.status == 1:              self.offline() +          elif pyfile.status == 6:              self.tempOffline() @@ -111,6 +121,5 @@ class DailymotionCom(Hoster):          streams = self.getStreams()          quality = self.getQuality() -        link = self.getLink(streams, quality) -        self.download(link) +        self.download(self.getLink(streams, quality)) diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 2129fbfc8..385295d42 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -14,6 +14,34 @@ from pycurl import SSL_CIPHER_LIST  from module.common.json_layer import json_loads, json_dumps  from module.plugins.Hoster import Hoster +############################ General errors ################################### +# EINTERNAL            (-1): An internal error has occurred. Please submit a bug report, detailing the exact circumstances in which this error occurred +# EARGS                (-2): You have passed invalid arguments to this command +# EAGAIN               (-3): (always at the request level) A temporary congestion or server malfunction prevented your request from being processed. No data was altered. Retry. Retries must be spaced with exponential backoff +# ERATELIMIT           (-4): You have exceeded your command weight per time quota. Please wait a few seconds, then try again (this should never happen in sane real-life applications) +# +############################ Upload errors #################################### +# EFAILED              (-5): The upload failed. Please restart it from scratch +# ETOOMANY             (-6): Too many concurrent IP addresses are accessing this upload target URL +# ERANGE               (-7): The upload file packet is out of range or not starting and ending on a chunk boundary +# EEXPIRED             (-8): The upload target URL you are trying to access has expired. Please request a fresh one +# +############################ Stream/System errors ############################# +# ENOENT               (-9): Object (typically, node or user) not found +# ECIRCULAR           (-10): Circular linkage attempted +# EACCESS             (-11): Access violation (e.g., trying to write to a read-only share) +# EEXIST              (-12): Trying to create an object that already exists +# EINCOMPLETE         (-13): Trying to access an incomplete resource +# EKEY                (-14): A decryption operation failed (never returned by the API) +# ESID                (-15): Invalid or expired user session, please relogin +# EBLOCKED            (-16): User blocked +# EOVERQUOTA          (-17): Request over quota +# ETEMPUNAVAIL        (-18): Resource temporarily not available, please try again later +# ETOOMANYCONNECTIONS (-19): Too many connections on this resource +# EWRITE              (-20): Write failed +# EREAD               (-21): Read failed +# EAPPKEY             (-22): Invalid application key; request not processed +  class MegaCoNz(Hoster):      __name__    = "MegaCoNz" @@ -26,8 +54,7 @@ class MegaCoNz(Hoster):      __license__     = "GPLv3"      __authors__     = [("RaNaN", "ranan@pyload.org")] - -    API_URL = "https://g.api.mega.co.nz/cs?id=%d" +    API_URL     = "https://g.api.mega.co.nz/cs"      FILE_SUFFIX = ".crypted" @@ -48,7 +75,7 @@ class MegaCoNz(Hoster):          # generate a session id, no idea where to obtain elsewhere          uid = random.randint(10 << 9, 10 ** 10) -        res = self.load(self.API_URL % uid, post=json_dumps([kwargs])) +        res = self.load(self.API_URL, get={'id': uid}, post=json_dumps([kwargs]))          self.logDebug("Api Response: " + res)          return json_loads(res) diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index 565aa63f0..617a30867 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -16,11 +16,11 @@ def which(program):      Courtesy of http://stackoverflow.com/a/377028/675646""" -      def is_exe(fpath):          return os.path.isfile(fpath) and os.access(fpath, os.X_OK)      fpath, fname = os.path.split(program) +      if fpath:          if is_exe(program):              return program @@ -60,27 +60,27 @@ class YoutubeCom(Hoster):      invalidChars = u'\u2605:?><"|\\'      # name, width, height, quality ranking, 3D -    formats = {5: (".flv", 400, 240, 1, False), -               6: (".flv", 640, 400, 4, False), -               17: (".3gp", 176, 144, 0, False), -               18: (".mp4", 480, 360, 2, False), -               22: (".mp4", 1280, 720, 8, False), -               43: (".webm", 640, 360, 3, False), -               34: (".flv", 640, 360, 4, False), -               35: (".flv", 854, 480, 6, False), -               36: (".3gp", 400, 240, 1, False), -               37: (".mp4", 1920, 1080, 9, False), -               38: (".mp4", 4096, 3072, 10, False), -               44: (".webm", 854, 480, 5, False), -               45: (".webm", 1280, 720, 7, False), -               46: (".webm", 1920, 1080, 9, False), -               82: (".mp4", 640, 360, 3, True), -               83: (".mp4", 400, 240, 1, True), -               84: (".mp4", 1280, 720, 8, True), -               85: (".mp4", 1920, 1080, 9, True), -               100: (".webm", 640, 360, 3, True), -               101: (".webm", 640, 360, 4, True), -               102: (".webm", 1280, 720, 8, True)} +    formats = {5  : (".flv" , 400 , 240 , 1 , False), +               6  : (".flv" , 640 , 400 , 4 , False), +               17 : (".3gp" , 176 , 144 , 0 , False), +               18 : (".mp4" , 480 , 360 , 2 , False), +               22 : (".mp4" , 1280, 720 , 8 , False), +               43 : (".webm", 640 , 360 , 3 , False), +               34 : (".flv" , 640 , 360 , 4 , False), +               35 : (".flv" , 854 , 480 , 6 , False), +               36 : (".3gp" , 400 , 240 , 1 , False), +               37 : (".mp4" , 1920, 1080, 9 , False), +               38 : (".mp4" , 4096, 3072, 10, False), +               44 : (".webm", 854 , 480 , 5 , False), +               45 : (".webm", 1280, 720 , 7 , False), +               46 : (".webm", 1920, 1080, 9 , False), +               82 : (".mp4" , 640 , 360 , 3 , True ), +               83 : (".mp4" , 400 , 240 , 1 , True ), +               84 : (".mp4" , 1280, 720 , 8 , True ), +               85 : (".mp4" , 1920, 1080, 9 , True ), +               100: (".webm", 640 , 360 , 3 , True ), +               101: (".webm", 640 , 360 , 4 , True ), +               102: (".webm", 1280, 720 , 8 , True )}      def setup(self): | 
