diff options
| author | 2015-01-29 00:00:19 +0100 | |
|---|---|---|
| committer | 2015-01-29 00:00:19 +0100 | |
| commit | 862e1a5d0e144dfd1eb6320992f6f7a646659c2f (patch) | |
| tree | 3e69ebce37491d099fd99707b959e10c32b93a58 | |
| parent | Merge pull request #1093 from Coksnuss/1091-support-prepaid-shareonline-account (diff) | |
| download | pyload-862e1a5d0e144dfd1eb6320992f6f7a646659c2f.tar.xz | |
[YoutubeCom] Fix http://forum.pyload.org/viewtopic.php?f=12&t=3974
| -rw-r--r-- | module/plugins/accounts/ShareonlineBiz.py | 7 | ||||
| -rw-r--r-- | module/plugins/hoster/YoutubeCom.py | 57 | 
2 files changed, 37 insertions, 27 deletions
| diff --git a/module/plugins/accounts/ShareonlineBiz.py b/module/plugins/accounts/ShareonlineBiz.py index e15f0f383..7e05e2e76 100644 --- a/module/plugins/accounts/ShareonlineBiz.py +++ b/module/plugins/accounts/ShareonlineBiz.py @@ -40,7 +40,7 @@ class ShareonlineBiz(Account):          if api['a'].lower() != "not_available":              req.cj.setCookie("share-online.biz", 'a', api['a']) -            premium = api['group'] in ["Premium", "PrePaid"] +            premium = api['group'] in ("Premium", "PrePaid")              validuntil = float(api['expire_date']) @@ -51,7 +51,10 @@ class ShareonlineBiz(Account):          maxtraffic  /= 1024  #@TODO: Remove `/ 1024` in 0.4.10          trafficleft /= 1024  #@TODO: Remove `/ 1024` in 0.4.10 -        return {'premium': premium, 'validuntil': validuntil, 'trafficleft': trafficleft, 'maxtraffic': maxtraffic} +        return {'premium'    : premium, +                'validuntil' : validuntil, +                'trafficleft': trafficleft, +                'maxtraffic' : maxtraffic}      def login(self, user, data, req): diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index 90c6df3c2..5c2489d3c 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -13,40 +13,36 @@ from module.utils import html_unescape  def which(program):      """Works exactly like the unix command which -      Courtesy of http://stackoverflow.com/a/377028/675646""" -    def is_exe(fpath): -        return os.path.isfile(fpath) and os.access(fpath, os.X_OK) +    isExe = lambda x: os.path.isfile(x) and os.access(x, os.X_OK)      fpath, fname = os.path.split(program)      if fpath: -        if is_exe(program): +        if isExe(program):              return program      else:          for path in os.environ['PATH'].split(os.pathsep):              path = path.strip('"')              exe_file = os.path.join(path, program) -            if is_exe(exe_file): +            if isExe(exe_file):                  return exe_file -    return None -  class YoutubeCom(Hoster):      __name__    = "YoutubeCom"      __type__    = "hoster" -    __version__ = "0.40" +    __version__ = "0.41" -    __pattern__ = r'https?://(?:[^/]*\.)?(?:youtube\.com|youtu\.be)/watch.*?[?&]v=.+' -    __config__ = [("quality", "sd;hd;fullhd;240p;360p;480p;720p;1080p;3072p", "Quality Setting", "hd"), -                  ("fmt", "int", "FMT/ITAG Number (5-102, 0 for auto)", 0), -                  (".mp4", "bool", "Allow .mp4", True), -                  (".flv", "bool", "Allow .flv", True), -                  (".webm", "bool", "Allow .webm", False), -                  (".3gp", "bool", "Allow .3gp", False), -                  ("3d", "bool", "Prefer 3D", False)] +    __pattern__ = r'https?://(?:[^/]*\.)?(youtube\.com|youtu\.be)/watch\?(?:.*&)?v=.+' +    __config__ = [("quality", "sd;hd;fullhd;240p;360p;480p;720p;1080p;3072p", "Quality Setting"             , "hd" ), +                  ("fmt"    , "int"                                         , "FMT/ITAG Number (0 for auto)", 0    ), +                  (".mp4"   , "bool"                                        , "Allow .mp4"                  , True ), +                  (".flv"   , "bool"                                        , "Allow .flv"                  , True ), +                  (".webm"  , "bool"                                        , "Allow .webm"                 , False), +                  (".3gp"   , "bool"                                        , "Allow .3gp"                  , False), +                  ("3d"     , "bool"                                        , "Prefer 3D"                   , False)]      __description__ = """Youtube.com hoster plugin"""      __license__     = "GPLv3" @@ -90,7 +86,7 @@ class YoutubeCom(Hoster):      def process(self, pyfile):          pyfile.url = replace_patterns(pyfile.url, self.URL_REPLACEMENTS) -        html = self.load(pyfile.url, decode=True) +        html       = self.load(pyfile.url, decode=True)          if re.search(r'<div id="player-unavailable" class="\s*player-width player-height\s*">', html):              self.offline() @@ -100,32 +96,40 @@ class YoutubeCom(Hoster):          #get config          use3d = self.getConfig("3d") +          if use3d:              quality = {"sd": 82, "hd": 84, "fullhd": 85, "240p": 83, "360p": 82,                         "480p": 82, "720p": 84, "1080p": 85, "3072p": 85}          else:              quality = {"sd": 18, "hd": 22, "fullhd": 37, "240p": 5, "360p": 18,                         "480p": 35, "720p": 22, "1080p": 37, "3072p": 38} +          desired_fmt = self.getConfig("fmt") -        if desired_fmt and desired_fmt not in self.formats: -            self.logWarning(_("FMT %d unknown, using default") % desired_fmt) -            desired_fmt = 0 +          if not desired_fmt:              desired_fmt = quality.get(self.getConfig("quality"), 18) +        elif desired_fmt not in self.formats: +            self.logWarning(_("FMT %d unknown, using default") % desired_fmt) +            desired_fmt = 0 +          #parse available streams -        streams = re.search(r'"url_encoded_fmt_stream_map": "(.*?)",', html).group(1) +        streams = re.search(r'"url_encoded_fmt_stream_map":"(.+?)",', html).group(1)          streams = [x.split('\u0026') for x in streams.split(',')]          streams = [dict((y.split('=', 1)) for y in x) for x in streams]          streams = [(int(x['itag']), unquote(x['url'])) for x in streams] -        #self.logDebug("Found links: %s" % streams) + +        # self.logDebug("Found links: %s" % streams) +          self.logDebug("AVAILABLE STREAMS: %s" % [x[0] for x in streams])          #build dictionary of supported itags (3D/2D)          allowed = lambda x: self.getConfig(self.formats[x][0])          streams = [x for x in streams if x[0] in self.formats and allowed(x[0])] +          if not streams:              self.fail(_("No available stream meets your preferences")) +          fmt_dict = dict([x for x in streams if self.formats[x[0]][4] == use3d] or streams)          self.logDebug("DESIRED STREAM: ITAG:%d (%s) %sfound, %sallowed" % @@ -136,15 +140,18 @@ class YoutubeCom(Hoster):          if desired_fmt in fmt_dict and allowed(desired_fmt):              fmt = desired_fmt          else: -            sel = lambda x: self.formats[x][3]  # select quality index +            sel  = lambda x: self.formats[x][3]  # select quality index              comp = lambda x, y: abs(sel(x) - sel(y))              self.logDebug("Choosing nearest fmt: %s" % [(x, allowed(x), comp(x, desired_fmt)) for x in fmt_dict.keys()]) +              fmt = reduce(lambda x, y: x if comp(x, desired_fmt) <= comp(y, desired_fmt) and                           sel(x) > sel(y) else y, fmt_dict.keys())          self.logDebug("Chosen fmt: %s" % fmt) +          url = fmt_dict[fmt] +          self.logDebug("URL: %s" % url)          #set file name @@ -167,9 +174,9 @@ class YoutubeCom(Hoster):                  m = "0"              pyfile.name += " (starting at %s:%s)" % (m, s) -        pyfile.name += file_suffix -        filename = self.download(url) +        pyfile.name += file_suffix +        filename     = self.download(url)          if ffmpeg and time:              inputfile = filename + "_" | 
