Merge pull request #5523 from jaimeMF/remove-format-limit
authorSergey M. <dstftw@gmail.com>
Mon, 27 Apr 2015 11:44:58 +0000 (16:44 +0500)
committerSergey M. <dstftw@gmail.com>
Mon, 27 Apr 2015 11:44:58 +0000 (16:44 +0500)
Remove the --max-quality option

1  2 
README.md
youtube_dl/utils.py

diff --combined README.md
index f67744f0f45a6a60ee937d363f2321ca2e0dbed4,948e0a4b946857d6ae9fbe7d4b699080fa9aca26..e1f30ca47868cb6288c34a7570dd6260325f7329
+++ b/README.md
@@@ -188,7 -188,6 +188,6 @@@ which means you can modify it, redistri
      -f, --format FORMAT              Video format code, see the "FORMAT SELECTION" for all the info
      --all-formats                    Download all available video formats
      --prefer-free-formats            Prefer free video formats unless a specific one is requested
-     --max-quality FORMAT             Highest quality format to download
      -F, --list-formats               List all available formats
      --youtube-skip-dash-manifest     Do not download the DASH manifest on YouTube videos
      --merge-output-format FORMAT     If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv.Ignored if no
@@@ -270,9 -269,9 +269,9 @@@ The simplest case is requesting a speci
  
  If you want to download multiple videos and they don't have the same formats available, you can specify the order of preference using slashes, as in `-f 22/17/18`. You can also filter the video results by putting a condition in brackets, as in `-f "best[height=720]"` (or `-f "[filesize>10M]"`).  This works for filesize, height, width, tbr, abr, vbr, asr, and fps and the comparisons <, <=, >, >=, =, != and for ext, acodec, vcodec, container, and protocol and the comparisons =, != . Formats for which the value is not known are excluded unless you put a question mark (?) after the operator. You can combine format filters, so  `-f "[height <=? 720][tbr>500]"` selects up to 720p videos (or videos where the height is not known) with a bitrate of at least 500 KBit/s. Use commas to download multiple formats, such as `-f 136/137/mp4/bestvideo,140/m4a/bestaudio`. You can merge the video and audio of two formats into a single file using `-f <video-format>+<audio-format>` (requires ffmpeg or avconv), for example `-f bestvideo+bestaudio`.
  
 -Since the end of April 2015 youtube-dl uses `-f bestvideo+bestaudio/best` as default format selection (see #5447, #5456). If ffmpeg or avconv are installed this results in downloading `bestvideo` and `bestaudio` separately and muxing them together into a single file giving the best overall quality available. Otherwise it falls back to `best` and results in downloading best available quality served as a single file. `best` is also needed for videos that don't come from YouTube because they don't provide the audio and video in two different files. If you want to only download some dash formats (for example if you are not interested in getting videos with a resolution higher than 1080p), you can add `-f bestvideo[height<=?1080]+bestaudio/best` to your configuration file.
 +Since the end of April 2015 and version 2015.04.26 youtube-dl uses `-f bestvideo+bestaudio/best` as default format selection (see #5447, #5456). If ffmpeg or avconv are installed this results in downloading `bestvideo` and `bestaudio` separately and muxing them together into a single file giving the best overall quality available. Otherwise it falls back to `best` and results in downloading best available quality served as a single file. `best` is also needed for videos that don't come from YouTube because they don't provide the audio and video in two different files. If you want to only download some dash formats (for example if you are not interested in getting videos with a resolution higher than 1080p), you can add `-f bestvideo[height<=?1080]+bestaudio/best` to your configuration file.
  
 -If you want to preserve the old format selection behavior (pre-April 2015), i.e. you want to download best available quality media served as a single file, you should explicitly specify your choice with `-f best`. You may want to add it to the [configuration file](#configuration) in order not to type it every time you run youtube-dl.
 +If you want to preserve the old format selection behavior (prior to youtube-dl 2015.04.26), i.e. you want to download best available quality media served as a single file, you should explicitly specify your choice with `-f best`. You may want to add it to the [configuration file](#configuration) in order not to type it every time you run youtube-dl.
  
  # VIDEO SELECTION
  
@@@ -324,9 -323,9 +323,9 @@@ YouTube changed their playlist format i
  
  If you have installed youtube-dl with a package manager, pip, setup.py or a tarball, please use that to update. Note that Ubuntu packages do not seem to get updated anymore. Since we are not affiliated with Ubuntu, there is little we can do. Feel free to [report bugs](https://bugs.launchpad.net/ubuntu/+source/youtube-dl/+filebug) to the [Ubuntu packaging guys](mailto:ubuntu-motu@lists.ubuntu.com?subject=outdated%20version%20of%20youtube-dl) - all they have to do is update the package to a somewhat recent version. See above for a way to update.
  
- ### Do I always have to pass in `--max-quality FORMAT`, or `-citw`?
+ ### Do I always have to pass `-citw`?
  
- By default, youtube-dl intends to have the best options (incidentally, if you have a convincing case that these should be different, [please file an issue where you explain that](https://yt-dl.org/bug)). Therefore, it is unnecessary and sometimes harmful to copy long option strings from webpages. In particular, `--max-quality` *limits* the video quality (so if you want the best quality, do NOT pass it in), and the only option out of `-citw` that is regularly useful is `-i`.
+ By default, youtube-dl intends to have the best options (incidentally, if you have a convincing case that these should be different, [please file an issue where you explain that](https://yt-dl.org/bug)). Therefore, it is unnecessary and sometimes harmful to copy long option strings from webpages. In particular, the only option out of `-citw` that is regularly useful is `-i`.
  
  ### Can you please put the -b option back?
  
@@@ -358,22 -357,6 +357,22 @@@ YouTube has switched to a new video inf
  
  YouTube requires an additional signature since September 2012 which is not supported by old versions of youtube-dl. See [above](#how-do-i-update-youtube-dl) for how to update youtube-dl.
  
 +### Video URL contains an ampersand and I'm getting some strange output `[1] 2839` or `'v' is not recognized as an internal or external command` ###
 +
 +That's actually the output from your shell. Since ampersand is one of the special shell characters it's interpreted by shell preventing you from passing the whole URL to youtube-dl. To disable your shell from interpreting the ampersands (or any other special characters) you have to either put the whole URL in quotes or escape them with a backslash (which approach will work depends on your shell).
 +
 +For example if your URL is https://www.youtube.com/watch?t=4&v=BaW_jenozKc you should end up with following command:
 +
 +```youtube-dl 'https://www.youtube.com/watch?t=4&v=BaW_jenozKc'```
 +
 +or
 +
 +```youtube-dl https://www.youtube.com/watch?t=4\&v=BaW_jenozKc```
 +
 +For Windows you have to use the double quotes:
 +
 +```youtube-dl "https://www.youtube.com/watch?t=4&v=BaW_jenozKc"```
 +
  ### ExtractorError: Could not find JS function u'OF'
  
  In February 2015, the new YouTube player contained a character sequence in a string that was misinterpreted by old versions of youtube-dl. See [above](#how-do-i-update-youtube-dl) for how to update youtube-dl.
diff --combined youtube_dl/utils.py
index 7de7742e3c2357b8ed15e68656c0c7ea5ca389d5,c69d3e165fc1fa9b0d19c029ee74ae41a1c49d3f..7d15eab64e8bf7ef779bd3b6bd8a64fbfcd8ece7
@@@ -371,18 -371,6 +371,18 @@@ def unescapeHTML(s)
          r'&([^;]+);', lambda m: _htmlentity_transform(m.group(1)), s)
  
  
 +def get_subprocess_encoding():
 +    if sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
 +        # For subprocess calls, encode with locale encoding
 +        # Refer to http://stackoverflow.com/a/9951851/35070
 +        encoding = preferredencoding()
 +    else:
 +        encoding = sys.getfilesystemencoding()
 +    if encoding is None:
 +        encoding = 'utf-8'
 +    return encoding
 +
 +
  def encodeFilename(s, for_subprocess=False):
      """
      @param s The name of the file
      if sys.version_info >= (3, 0):
          return s
  
 -    if sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
 -        # Pass '' directly to use Unicode APIs on Windows 2000 and up
 -        # (Detecting Windows NT 4 is tricky because 'major >= 4' would
 -        # match Windows 9x series as well. Besides, NT 4 is obsolete.)
 -        if not for_subprocess:
 -            return s
 -        else:
 -            # For subprocess calls, encode with locale encoding
 -            # Refer to http://stackoverflow.com/a/9951851/35070
 -            encoding = preferredencoding()
 -    else:
 -        encoding = sys.getfilesystemencoding()
 -    if encoding is None:
 -        encoding = 'utf-8'
 -    return s.encode(encoding, 'ignore')
 +    # Pass '' directly to use Unicode APIs on Windows 2000 and up
 +    # (Detecting Windows NT 4 is tricky because 'major >= 4' would
 +    # match Windows 9x series as well. Besides, NT 4 is obsolete.)
 +    if not for_subprocess and sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
 +        return s
 +
 +    return s.encode(get_subprocess_encoding(), 'ignore')
 +
 +
 +def decodeFilename(b, for_subprocess=False):
 +
 +    if sys.version_info >= (3, 0):
 +        return b
 +
 +    if not isinstance(b, bytes):
 +        return b
 +
 +    return b.decode(get_subprocess_encoding(), 'ignore')
  
  
  def encodeArgument(s):
      return encodeFilename(s, True)
  
  
 +def decodeArgument(b):
 +    return decodeFilename(b, True)
 +
 +
  def decodeOption(optval):
      if optval is None:
          return optval
@@@ -1128,15 -1109,6 +1128,6 @@@ def shell_quote(args)
      return ' '.join(quoted_args)
  
  
- def takewhile_inclusive(pred, seq):
-     """ Like itertools.takewhile, but include the latest evaluated element
-         (the first element so that Not pred(e)) """
-     for e in seq:
-         yield e
-         if not pred(e):
-             return
  def smuggle_url(url, data):
      """ Pass additional data in a URL for internal use. """
  
@@@ -1819,59 -1791,6 +1810,59 @@@ def match_filter_func(filter_str)
      return _match_func
  
  
 +def parse_dfxp_time_expr(time_expr):
 +    if not time_expr:
 +        return 0.0
 +
 +    mobj = re.match(r'^(?P<time_offset>\d+(?:\.\d+)?)s?$', time_expr)
 +    if mobj:
 +        return float(mobj.group('time_offset'))
 +
 +    mobj = re.match(r'^(\d+):(\d\d):(\d\d(?:\.\d+)?)$', time_expr)
 +    if mobj:
 +        return 3600 * int(mobj.group(1)) + 60 * int(mobj.group(2)) + float(mobj.group(3))
 +
 +
 +def format_srt_time(seconds):
 +    (mins, secs) = divmod(seconds, 60)
 +    (hours, mins) = divmod(mins, 60)
 +    millisecs = (secs - int(secs)) * 1000
 +    secs = int(secs)
 +    return '%02d:%02d:%02d,%03d' % (hours, mins, secs, millisecs)
 +
 +
 +def dfxp2srt(dfxp_data):
 +    _x = functools.partial(xpath_with_ns, ns_map={'ttml': 'http://www.w3.org/ns/ttml'})
 +
 +    def parse_node(node):
 +        str_or_empty = functools.partial(str_or_none, default='')
 +
 +        out = str_or_empty(node.text)
 +
 +        for child in node:
 +            if child.tag == _x('ttml:br'):
 +                out += '\n' + str_or_empty(child.tail)
 +            elif child.tag == _x('ttml:span'):
 +                out += str_or_empty(parse_node(child))
 +            else:
 +                out += str_or_empty(xml.etree.ElementTree.tostring(child))
 +
 +        return out
 +
 +    dfxp = xml.etree.ElementTree.fromstring(dfxp_data.encode('utf-8'))
 +    out = []
 +    paras = dfxp.findall(_x('.//ttml:p'))
 +
 +    for para, index in zip(paras, itertools.count(1)):
 +        out.append('%d\n%s --> %s\n%s\n\n' % (
 +            index,
 +            format_srt_time(parse_dfxp_time_expr(para.attrib.get('begin'))),
 +            format_srt_time(parse_dfxp_time_expr(para.attrib.get('end'))),
 +            parse_node(para)))
 +
 +    return ''.join(out)
 +
 +
  class PerRequestProxyHandler(compat_urllib_request.ProxyHandler):
      def __init__(self, proxies=None):
          # Set default handlers