X-Git-Url: https://git.rapsys.eu/youtubedl/blobdiff_plain/b8d8e13c1f9e4d3cdd7d41c5c9d711a36dd5f9c3..32569172c58bbc32bcc4fdb64af8615f98c4cccb:/youtube-dl.1 diff --git a/youtube-dl.1 b/youtube-dl.1 index 38c41e2..cb8f218 100644 --- a/youtube-dl.1 +++ b/youtube-dl.1 @@ -1,4 +1,7 @@ +.\" Automatically generated by Pandoc 2.1.3 +.\" .TH "YOUTUBE\-DL" "1" "" "" "" +.hy .SH NAME .PP youtube\-dl \- download videos from youtube.com or other video platforms @@ -11,7 +14,7 @@ youtube\-dl \- download videos from youtube.com or other video platforms YouTube.com and a few more sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and it is not platform specific. -It should work on your Unix box, on Windows or on Mac OS X. +It should work on your Unix box, on Windows or on macOS. It is released to the public domain, which means you can modify it, redistribute it or use it however you like. .SH OPTIONS @@ -113,7 +116,7 @@ Do not emit color codes in output .TP .B \-\-proxy \f[I]URL\f[] Use the specified HTTP/HTTPS/SOCKS proxy. -To enable experimental SOCKS proxy, specify a proper scheme. +To enable SOCKS proxy, specify a proper scheme. For example socks5://127.0.0.1:1080/. Pass in an empty string (\-\-proxy "") for direct connection .RS @@ -138,13 +141,37 @@ Make all connections via IPv4 Make all connections via IPv6 .RS .RE +.SS Geo Restriction: .TP .B \-\-geo\-verification\-proxy \f[I]URL\f[] Use this proxy to verify the IP address for some geo\-restricted sites. -The default proxy specified by \-\-proxy (or none, if the options is not +The default proxy specified by \-\-proxy (or none, if the option is not present) is used for the actual downloading. .RS .RE +.TP +.B \-\-geo\-bypass +Bypass geographic restriction via faking X\-Forwarded\-For HTTP header +.RS +.RE +.TP +.B \-\-no\-geo\-bypass +Do not bypass geographic restriction via faking X\-Forwarded\-For HTTP +header +.RS +.RE +.TP +.B \-\-geo\-bypass\-country \f[I]CODE\f[] +Force bypass geographic restriction with explicitly provided two\-letter +ISO 3166\-2 country code +.RS +.RE +.TP +.B \-\-geo\-bypass\-ip\-block \f[I]IP_BLOCK\f[] +Force bypass geographic restriction with explicitly provided IP block in +CIDR notation +.RS +.RE .SS Video Selection: .TP .B \-\-playlist\-start \f[I]NUMBER\f[] @@ -223,16 +250,18 @@ Do not download any videos with more than COUNT views .TP .B \-\-match\-filter \f[I]FILTER\f[] Generic video filter. -Specify any key (see help for \-o for a list of available keys) to match -if the key is present, !key to check if the key is not present,key > -NUMBER (like "comment_count > 12", also works with >=, <, <=, !=, =) to -compare against a number, and & to require multiple matches. +Specify any key (see the "OUTPUT TEMPLATE" for a list of available keys) +to match if the key is present, !key to check if the key is not present, +key > NUMBER (like "comment_count > 12", also works with >=, <, <=, !=, +=) to compare against a number, key = \[aq]LITERAL\[aq] (like "uploader += \[aq]Mike Smith\[aq]", also works with !=) to match against a string +literal and & to require multiple matches. Values which are not known are excluded unless you put a question mark -(?) after the operator.For example, to only match videos that have been -liked more than 100 times and disliked less than 50 times (or the -dislike functionality is not available at the given service), but who -also have a description, use \-\-match\-filter "like_count > 100 & -dislike_count 100 & dislike_count [0\-9]+)\[aq] \ \ \ \ _TEST\ =\ { -\ \ \ \ \ \ \ \ \[aq]url\[aq]:\ \[aq]http://yourextractor.com/watch/42\[aq], +\ \ \ \ \ \ \ \ \[aq]url\[aq]:\ \[aq]https://yourextractor.com/watch/42\[aq], \ \ \ \ \ \ \ \ \[aq]md5\[aq]:\ \[aq]TODO:\ md5\ sum\ of\ the\ first\ 10241\ bytes\ of\ the\ video\ file\ (use\ \-\-test)\[aq], \ \ \ \ \ \ \ \ \[aq]info_dict\[aq]:\ { \ \ \ \ \ \ \ \ \ \ \ \ \[aq]id\[aq]:\ \[aq]42\[aq], @@ -1985,23 +2084,34 @@ If you decide to add more than one test, then rename \f[C]_TEST\f[] to The tests will then be named \f[C]TestDownload.test_YourExtractor\f[], \f[C]TestDownload.test_YourExtractor_1\f[], \f[C]TestDownload.test_YourExtractor_2\f[], etc. +Note that tests with \f[C]only_matching\f[] key in test\[aq]s dict are +not counted in. .IP " 7." 4 Have a look at \f[C]youtube_dl/extractor/common.py\f[] (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/common.py) for possible helper methods and a detailed description of what your extractor should and may -return (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/common.py#L74-L252). +return (https://github.com/rg3/youtube-dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extractor/common.py#L94-L303). Add tests and code for as many as you want. .IP " 8." 4 -Make sure your code follows youtube\-dl coding -conventions (#youtube-dl-coding-conventions) and check the code with -flake8 (https://pypi.python.org/pypi/flake8). -Also make sure your code works under all Python (http://www.python.org/) -versions claimed supported by youtube\-dl, namely 2.6, 2.7, and 3.2+. +Make sure your code follows youtube\-dl coding conventions and check the +code with +flake8 (http://flake8.pycqa.org/en/latest/index.html#quickstart): +.RS 4 +.IP +.nf +\f[C] +\ $\ flake8\ youtube_dl/extractor/yourextractor.py +\f[] +.fi +.RE .IP " 9." 4 -When the tests pass, add (http://git-scm.com/docs/git-add) the new files -and commit (http://git-scm.com/docs/git-commit) them and -push (http://git-scm.com/docs/git-push) the result, like this: +Make sure your code works under all Python (https://www.python.org/) +versions claimed supported by youtube\-dl, namely 2.6, 2.7, and 3.2+. +.IP "10." 4 +When the tests pass, add (https://git-scm.com/docs/git-add) the new +files and commit (https://git-scm.com/docs/git-commit) them and +push (https://git-scm.com/docs/git-push) the result, like this: .RS 4 .IP .nf @@ -2013,7 +2123,7 @@ $\ git\ push\ origin\ yourextractor \f[] .fi .RE -.IP "10." 4 +.IP "11." 4 Finally, create a pull request (https://help.github.com/articles/creating-a-pull-request). We\[aq]ll then review and merge it. @@ -2043,7 +2153,7 @@ update at all. .PP For extraction to work youtube\-dl relies on metadata your extractor extracts and provides to youtube\-dl expressed by an information -dictionary (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/common.py#L75-L257) +dictionary (https://github.com/rg3/youtube-dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extractor/common.py#L94-L303) or simply \f[I]info dict\f[]. Only the following meta fields in the \f[I]info dict\f[] are considered mandatory for a successful extraction process by youtube\-dl: @@ -2064,7 +2174,7 @@ extraction does not make any sense without and if any of them fail to be extracted then the extractor is considered completely broken. .PP Any -field (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/common.py#L149-L257) +field (https://github.com/rg3/youtube-dl/blob/7f41a598b3fba1bcab2817de64a08941200aa3c8/youtube_dl/extractor/common.py#L188-L303) apart from the aforementioned ones are considered \f[B]optional\f[]. That means that extraction should be \f[B]tolerant\f[] to situations when sources for these fields can potentially be unavailable (even if @@ -2185,9 +2295,37 @@ title\ =\ meta.get(\[aq]title\[aq])\ or\ self._og_search_title(webpage) .PP This code will try to extract from \f[C]meta\f[] first and if it fails it will try extracting \f[C]og:title\f[] from a \f[C]webpage\f[]. -.SS Make regular expressions flexible +.SS Regular expressions +.SS Don\[aq]t capture groups you don\[aq]t use +.PP +Capturing group must be an indication that it\[aq]s used somewhere in +the code. +Any group that is not used must be non capturing. +.SS Example +.PP +Don\[aq]t capture id attribute name here since you can\[aq]t use it for +anything anyway. +.PP +Correct: +.IP +.nf +\f[C] +r\[aq](?:id|ID)=(?P\\d+)\[aq] +\f[] +.fi +.PP +Incorrect: +.IP +.nf +\f[C] +r\[aq](id|ID)=(?P\\d+)\[aq] +\f[] +.fi +.SS Make regular expressions relaxed and flexible .PP -When using regular expressions try to write them fuzzy and flexible. +When using regular expressions try to write them fuzzy, relaxed and +flexible, skipping insignificant parts that are more likely to change, +allowing both single and double quotes for quoted values and so on. .SS Example .PP Say you need to extract \f[C]title\f[] from the following HTML code: @@ -2230,11 +2368,64 @@ title\ =\ self._search_regex( \ \ \ \ webpage,\ \[aq]title\[aq],\ group=\[aq]title\[aq]) \f[] .fi +.SS Long lines policy +.PP +There is a soft limit to keep lines of code under 80 characters long. +This means it should be respected if possible and if it does not make +readability and code maintenance worse. +.PP +For example, you should \f[B]never\f[] split long string literals like +URLs or some other often copied entities over multiple lines to fit this +limit: +.PP +Correct: +.IP +.nf +\f[C] +\[aq]https://www.youtube.com/watch?v=FqZTN594JQw&list=PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4\[aq] +\f[] +.fi +.PP +Incorrect: +.IP +.nf +\f[C] +\[aq]https://www.youtube.com/watch?v=FqZTN594JQw&list=\[aq] +\[aq]PLMYEtVRpaqY00V9W81Cwmzp6N6vZqfUKD4\[aq] +\f[] +.fi .SS Use safe conversion functions .PP -Wrap all extracted numeric data into safe functions from \f[C]utils\f[]: +Wrap all extracted numeric data into safe functions from +\f[C]youtube_dl/utils.py\f[] (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/utils.py): \f[C]int_or_none\f[], \f[C]float_or_none\f[]. Use them for string to number conversions as well. +.PP +Use \f[C]url_or_none\f[] for safe URL processing. +.PP +Use \f[C]try_get\f[] for safe metadata extraction from parsed JSON. +.PP +Explore +\f[C]youtube_dl/utils.py\f[] (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/utils.py) +for more useful convenience functions. +.SS More examples +.SS Safely extract optional description from parsed JSON +.IP +.nf +\f[C] +description\ =\ try_get(response,\ lambda\ x:\ x[\[aq]result\[aq]][\[aq]video\[aq]][0][\[aq]summary\[aq]],\ compat_str) +\f[] +.fi +.SS Safely extract more optional metadata +.IP +.nf +\f[C] +video\ =\ try_get(response,\ lambda\ x:\ x[\[aq]result\[aq]][\[aq]video\[aq]][0],\ dict)\ or\ {} +description\ =\ video.get(\[aq]summary\[aq]) +duration\ =\ float_or_none(video.get(\[aq]durationMs\[aq]),\ scale=1000) +view_count\ =\ int_or_none(video.get(\[aq]views\[aq])) +\f[] +.fi .SH EMBEDDING YOUTUBE\-DL .PP youtube\-dl makes the best effort to be a good command\-line program, @@ -2252,13 +2443,13 @@ import\ youtube_dl ydl_opts\ =\ {} with\ youtube_dl.YoutubeDL(ydl_opts)\ as\ ydl: -\ \ \ \ ydl.download([\[aq]http://www.youtube.com/watch?v=BaW_jenozKc\[aq]]) +\ \ \ \ ydl.download([\[aq]https://www.youtube.com/watch?v=BaW_jenozKc\[aq]]) \f[] .fi .PP Most likely, you\[aq]ll want to use various options. For a list of options available, have a look at -\f[C]youtube_dl/YoutubeDL.py\f[] (https://github.com/rg3/youtube-dl/blob/master/youtube_dl/YoutubeDL.py#L129-L279). +\f[C]youtube_dl/YoutubeDL.py\f[] (https://github.com/rg3/youtube-dl/blob/3e4cedf9e8cd3157df2457df7274d0c842421945/youtube_dl/YoutubeDL.py#L137-L312). For a start, if you want to intercept youtube\-dl\[aq]s output, set a \f[C]logger\f[] object. .PP @@ -2299,7 +2490,7 @@ ydl_opts\ =\ { \ \ \ \ \[aq]progress_hooks\[aq]:\ [my_hook], } with\ youtube_dl.YoutubeDL(ydl_opts)\ as\ ydl: -\ \ \ \ ydl.download([\[aq]http://www.youtube.com/watch?v=BaW_jenozKc\[aq]]) +\ \ \ \ ydl.download([\[aq]https://www.youtube.com/watch?v=BaW_jenozKc\[aq]]) \f[] .fi .SH BUGS @@ -2311,10 +2502,10 @@ GitHub fails to accept the bug report), please do not send bug reports via personal email. For discussions, join us in the IRC channel #youtube\-dl (irc://chat.freenode.net/#youtube-dl) on freenode -(webchat (http://webchat.freenode.net/?randomnick=1&channels=youtube-dl)). +(webchat (https://webchat.freenode.net/?randomnick=1&channels=youtube-dl)). .PP \f[B]Please include the full output of youtube\-dl when run with -\f[C]\-v\f[]\f[], i.e. +\f[BC]\-v\f[B]\f[], i.e. \f[B]add\f[] \f[C]\-v\f[] flag to \f[B]your command line\f[], copy the \f[B]whole\f[] output and post it in the issue body wrapped in ``` for better formatting. @@ -2325,7 +2516,7 @@ It should look similar to this: $\ youtube\-dl\ \-v\ [debug]\ System\ config:\ [] [debug]\ User\ config:\ [] -[debug]\ Command\-line\ args:\ [u\[aq]\-v\[aq],\ u\[aq]http://www.youtube.com/watch?v=BaW_jenozKcj\[aq]] +[debug]\ Command\-line\ args:\ [u\[aq]\-v\[aq],\ u\[aq]https://www.youtube.com/watch?v=BaW_jenozKcj\[aq]] [debug]\ Encodings:\ locale\ cp1251,\ fs\ mbcs,\ out\ cp866,\ pref\ cp1251 [debug]\ youtube\-dl\ version\ 2015.12.06 [debug]\ Git\ HEAD:\ 135392e @@ -2390,11 +2581,11 @@ command\-line) or upload the \f[C]\&.dump\f[] files you get when you add .PP \f[B]Site support requests must contain an example URL\f[]. An example URL is a URL you might want to download, like -\f[C]http://www.youtube.com/watch?v=BaW_jenozKc\f[]. +\f[C]https://www.youtube.com/watch?v=BaW_jenozKc\f[]. There should be an obvious video present. Except under very special circumstances, the main page of a video service (e.g. -\f[C]http://www.youtube.com/\f[]) is \f[I]not\f[] an example URL. +\f[C]https://www.youtube.com/\f[]) is \f[I]not\f[] an example URL. .SS Are you using the latest version? .PP Before reporting any issue, type \f[C]youtube\-dl\ \-U\f[].