aboutsummaryrefslogtreecommitdiff
path: root/devscripts
diff options
context:
space:
mode:
Diffstat (limited to 'devscripts')
-rw-r--r--devscripts/__init__.py1
-rwxr-xr-xdevscripts/bash-completion.py12
-rw-r--r--devscripts/buildserver.py4
-rw-r--r--devscripts/check-porn.py12
-rwxr-xr-xdevscripts/cli_to_api.py83
-rw-r--r--devscripts/create-github-release.py42
-rwxr-xr-xdevscripts/fish-completion.py12
-rw-r--r--devscripts/generate_aes_testdata.py1
-rwxr-xr-xdevscripts/gh-pages/add-version.py15
-rwxr-xr-xdevscripts/gh-pages/generate-download.py40
-rwxr-xr-xdevscripts/gh-pages/update-copyright.py19
-rwxr-xr-xdevscripts/gh-pages/update-feed.py15
-rwxr-xr-xdevscripts/gh-pages/update-sites.py12
-rwxr-xr-xdevscripts/install_srelay.sh8
-rw-r--r--devscripts/lazy_load_template.py2
-rwxr-xr-xdevscripts/make_contributing.py10
-rw-r--r--devscripts/make_issue_template.py17
-rw-r--r--devscripts/make_lazy_extractors.py94
-rwxr-xr-xdevscripts/make_readme.py15
-rw-r--r--devscripts/make_supportedsites.py16
-rw-r--r--devscripts/prepare_manpage.py39
-rwxr-xr-xdevscripts/release.sh23
-rw-r--r--devscripts/run_tests.bat17
-rwxr-xr-xdevscripts/run_tests.sh22
-rw-r--r--devscripts/show-downloads-statistics.py47
-rw-r--r--devscripts/utils.py62
-rwxr-xr-xdevscripts/zsh-completion.py9
27 files changed, 490 insertions, 159 deletions
diff --git a/devscripts/__init__.py b/devscripts/__init__.py
new file mode 100644
index 000000000..750dbdca7
--- /dev/null
+++ b/devscripts/__init__.py
@@ -0,0 +1 @@
+# Empty file needed to make devscripts.utils properly importable from outside
diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py
index ce68f26f9..7db396a77 100755
--- a/devscripts/bash-completion.py
+++ b/devscripts/bash-completion.py
@@ -5,8 +5,12 @@ import os
from os.path import dirname as dirn
import sys
-sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
+
import youtube_dl
+from youtube_dl.compat import compat_open as open
+
+from utils import read_file
BASH_COMPLETION_FILE = "youtube-dl.bash-completion"
BASH_COMPLETION_TEMPLATE = "devscripts/bash-completion.in"
@@ -18,12 +22,12 @@ def build_completion(opt_parser):
for option in group.option_list:
# for every long flag
opts_flag.append(option.get_opt_string())
- with open(BASH_COMPLETION_TEMPLATE) as f:
- template = f.read()
- with open(BASH_COMPLETION_FILE, "w") as f:
+ template = read_file(BASH_COMPLETION_TEMPLATE)
+ with open(BASH_COMPLETION_FILE, "w", encoding='utf-8') as f:
# just using the special char
filled_template = template.replace("{{flags}}", " ".join(opts_flag))
f.write(filled_template)
+
parser = youtube_dl.parseOpts()[0]
build_completion(parser)
diff --git a/devscripts/buildserver.py b/devscripts/buildserver.py
index fc99c3213..4a4295ba9 100644
--- a/devscripts/buildserver.py
+++ b/devscripts/buildserver.py
@@ -322,7 +322,7 @@ class GITBuilder(GITInfoBuilder):
class YoutubeDLBuilder(object):
- authorizedUsers = ['fraca7', 'phihag', 'rg3', 'FiloSottile']
+ authorizedUsers = ['fraca7', 'phihag', 'rg3', 'FiloSottile', 'ytdl-org']
def __init__(self, **kwargs):
if self.repoName != 'youtube-dl':
@@ -424,8 +424,6 @@ class BuildHTTPRequestHandler(compat_http_server.BaseHTTPRequestHandler):
self.send_header('Content-Length', len(msg))
self.end_headers()
self.wfile.write(msg)
- except HTTPError as e:
- self.send_response(e.code, str(e))
else:
self.send_response(500, 'Unknown build method "%s"' % action)
else:
diff --git a/devscripts/check-porn.py b/devscripts/check-porn.py
index 7a219ebe9..740f04de0 100644
--- a/devscripts/check-porn.py
+++ b/devscripts/check-porn.py
@@ -14,7 +14,7 @@ import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from test.helper import get_testcases
+from test.helper import gettestcases
from youtube_dl.utils import compat_urllib_parse_urlparse
from youtube_dl.utils import compat_urllib_request
@@ -24,7 +24,7 @@ if len(sys.argv) > 1:
else:
METHOD = 'EURISTIC'
-for test in get_testcases():
+for test in gettestcases():
if METHOD == 'EURISTIC':
try:
webpage = compat_urllib_request.urlopen(test['url'], timeout=10).read()
@@ -45,12 +45,12 @@ for test in get_testcases():
RESULT = ('.' + domain + '\n' in LIST or '\n' + domain + '\n' in LIST)
- if RESULT and ('info_dict' not in test or 'age_limit' not in test['info_dict'] or
- test['info_dict']['age_limit'] != 18):
+ if RESULT and ('info_dict' not in test or 'age_limit' not in test['info_dict']
+ or test['info_dict']['age_limit'] != 18):
print('\nPotential missing age_limit check: {0}'.format(test['name']))
- elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict'] and
- test['info_dict']['age_limit'] == 18):
+ elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict']
+ and test['info_dict']['age_limit'] == 18):
print('\nPotential false negative: {0}'.format(test['name']))
else:
diff --git a/devscripts/cli_to_api.py b/devscripts/cli_to_api.py
new file mode 100755
index 000000000..9fb1d2ba8
--- /dev/null
+++ b/devscripts/cli_to_api.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+from __future__ import unicode_literals
+
+"""
+This script displays the API parameters corresponding to a yt-dl command line
+
+Example:
+$ ./cli_to_api.py -f best
+{u'format': 'best'}
+$
+"""
+
+# Allow direct execution
+import os
+import sys
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import youtube_dl
+from types import MethodType
+
+
+def cli_to_api(*opts):
+ YDL = youtube_dl.YoutubeDL
+
+ # to extract the parsed options, break out of YoutubeDL instantiation
+
+ # return options via this Exception
+ class ParseYTDLResult(Exception):
+ def __init__(self, result):
+ super(ParseYTDLResult, self).__init__('result')
+ self.opts = result
+
+ # replacement constructor that raises ParseYTDLResult
+ def ytdl_init(ydl, ydl_opts):
+ super(YDL, ydl).__init__(ydl_opts)
+ raise ParseYTDLResult(ydl_opts)
+
+ # patch in the constructor
+ YDL.__init__ = MethodType(ytdl_init, YDL)
+
+ # core parser
+ def parsed_options(argv):
+ try:
+ youtube_dl._real_main(list(argv))
+ except ParseYTDLResult as result:
+ return result.opts
+
+ # from https://github.com/yt-dlp/yt-dlp/issues/5859#issuecomment-1363938900
+ default = parsed_options([])
+
+ def neq_opt(a, b):
+ if a == b:
+ return False
+ if a is None and repr(type(object)).endswith(".utils.DateRange'>"):
+ return '0001-01-01 - 9999-12-31' != '{0}'.format(b)
+ return a != b
+
+ diff = dict((k, v) for k, v in parsed_options(opts).items() if neq_opt(default[k], v))
+ if 'postprocessors' in diff:
+ diff['postprocessors'] = [pp for pp in diff['postprocessors'] if pp not in default['postprocessors']]
+ return diff
+
+
+def main():
+ from pprint import PrettyPrinter
+
+ pprint = PrettyPrinter()
+ super_format = pprint.format
+
+ def format(object, context, maxlevels, level):
+ if repr(type(object)).endswith(".utils.DateRange'>"):
+ return '{0}: {1}>'.format(repr(object)[:-2], object), True, False
+ return super_format(object, context, maxlevels, level)
+
+ pprint.format = format
+
+ pprint.pprint(cli_to_api(*sys.argv))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/devscripts/create-github-release.py b/devscripts/create-github-release.py
index 3b8021e74..320bcfc27 100644
--- a/devscripts/create-github-release.py
+++ b/devscripts/create-github-release.py
@@ -1,19 +1,20 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-import base64
import json
import mimetypes
import netrc
import optparse
import os
+import re
import sys
-sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
from youtube_dl.compat import (
compat_basestring,
- compat_input,
compat_getpass,
compat_print,
compat_urllib_request,
@@ -22,11 +23,12 @@ from youtube_dl.utils import (
make_HTTPS_handler,
sanitized_Request,
)
+from utils import read_file
class GitHubReleaser(object):
- _API_URL = 'https://api.github.com/repos/rg3/youtube-dl/releases'
- _UPLOADS_URL = 'https://uploads.github.com/repos/rg3/youtube-dl/releases/%s/assets?name=%s'
+ _API_URL = 'https://api.github.com/repos/ytdl-org/youtube-dl/releases'
+ _UPLOADS_URL = 'https://uploads.github.com/repos/ytdl-org/youtube-dl/releases/%s/assets?name=%s'
_NETRC_MACHINE = 'github.com'
def __init__(self, debuglevel=0):
@@ -38,28 +40,20 @@ class GitHubReleaser(object):
try:
info = netrc.netrc().authenticators(self._NETRC_MACHINE)
if info is not None:
- self._username = info[0]
- self._password = info[2]
+ self._token = info[2]
compat_print('Using GitHub credentials found in .netrc...')
return
else:
compat_print('No GitHub credentials found in .netrc')
except (IOError, netrc.NetrcParseError):
compat_print('Unable to parse .netrc')
- self._username = compat_input(
- 'Type your GitHub username or email address and press [Return]: ')
- self._password = compat_getpass(
- 'Type your GitHub password and press [Return]: ')
+ self._token = compat_getpass(
+ 'Type your GitHub PAT (personal access token) and press [Return]: ')
def _call(self, req):
if isinstance(req, compat_basestring):
req = sanitized_Request(req)
- # Authorizing manually since GitHub does not response with 401 with
- # WWW-Authenticate header set (see
- # https://developer.github.com/v3/#basic-authentication)
- b64 = base64.b64encode(
- ('%s:%s' % (self._username, self._password)).encode('utf-8')).decode('ascii')
- req.add_header('Authorization', 'Basic %s' % b64)
+ req.add_header('Authorization', 'token %s' % self._token)
response = self._opener.open(req).read().decode('utf-8')
return json.loads(response)
@@ -90,16 +84,22 @@ class GitHubReleaser(object):
def main():
- parser = optparse.OptionParser(usage='%prog VERSION BUILDPATH')
+ parser = optparse.OptionParser(usage='%prog CHANGELOG VERSION BUILDPATH')
options, args = parser.parse_args()
- if len(args) != 2:
+ if len(args) != 3:
parser.error('Expected a version and a build directory')
- version, build_path = args
+ changelog_file, version, build_path = args
+
+ changelog = read_file(changelog_file)
+
+ mobj = re.search(r'(?s)version %s\n{2}(.+?)\n{3}' % version, changelog)
+ body = mobj.group(1) if mobj else ''
releaser = GitHubReleaser()
- new_release = releaser.create_release(version, name='youtube-dl %s' % version)
+ new_release = releaser.create_release(
+ version, name='youtube-dl %s' % version, body=body)
release_id = new_release['id']
for asset in os.listdir(build_path):
diff --git a/devscripts/fish-completion.py b/devscripts/fish-completion.py
index 41629d87d..ef8a39e0b 100755
--- a/devscripts/fish-completion.py
+++ b/devscripts/fish-completion.py
@@ -6,10 +6,13 @@ import os
from os.path import dirname as dirn
import sys
-sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
+
import youtube_dl
from youtube_dl.utils import shell_quote
+from utils import read_file, write_file
+
FISH_COMPLETION_FILE = 'youtube-dl.fish'
FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
@@ -38,11 +41,10 @@ def build_completion(opt_parser):
complete_cmd.extend(EXTRA_ARGS.get(long_option, []))
commands.append(shell_quote(complete_cmd))
- with open(FISH_COMPLETION_TEMPLATE) as f:
- template = f.read()
+ template = read_file(FISH_COMPLETION_TEMPLATE)
filled_template = template.replace('{{commands}}', '\n'.join(commands))
- with open(FISH_COMPLETION_FILE, 'w') as f:
- f.write(filled_template)
+ write_file(FISH_COMPLETION_FILE, filled_template)
+
parser = youtube_dl.parseOpts()[0]
build_completion(parser)
diff --git a/devscripts/generate_aes_testdata.py b/devscripts/generate_aes_testdata.py
index 2e389fc8e..e3df42cc2 100644
--- a/devscripts/generate_aes_testdata.py
+++ b/devscripts/generate_aes_testdata.py
@@ -23,6 +23,7 @@ def openssl_encode(algo, key, iv):
out, _ = prog.communicate(secret_msg)
return out
+
iv = key = [0x20, 0x15] + 14 * [0]
r = openssl_encode('aes-128-cbc', key, iv)
diff --git a/devscripts/gh-pages/add-version.py b/devscripts/gh-pages/add-version.py
index 867ea0048..b84908f85 100755
--- a/devscripts/gh-pages/add-version.py
+++ b/devscripts/gh-pages/add-version.py
@@ -6,16 +6,21 @@ import sys
import hashlib
import os.path
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(dirn(os.path.abspath(__file__)))))
+
+from devscripts.utils import read_file, write_file
+from youtube_dl.compat import compat_open as open
if len(sys.argv) <= 1:
print('Specify the version number as parameter')
sys.exit()
version = sys.argv[1]
-with open('update/LATEST_VERSION', 'w') as f:
- f.write(version)
+write_file('update/LATEST_VERSION', version)
-versions_info = json.load(open('update/versions.json'))
+versions_info = json.loads(read_file('update/versions.json'))
if 'signature' in versions_info:
del versions_info['signature']
@@ -39,5 +44,5 @@ for key, filename in filenames.items():
versions_info['versions'][version] = new_version
versions_info['latest'] = version
-with open('update/versions.json', 'w') as jsonf:
- json.dump(versions_info, jsonf, indent=4, sort_keys=True)
+with open('update/versions.json', 'w', encoding='utf-8') as jsonf:
+ json.dumps(versions_info, jsonf, indent=4, sort_keys=True)
diff --git a/devscripts/gh-pages/generate-download.py b/devscripts/gh-pages/generate-download.py
index 392e3ba21..3e38e9299 100755
--- a/devscripts/gh-pages/generate-download.py
+++ b/devscripts/gh-pages/generate-download.py
@@ -1,31 +1,29 @@
#!/usr/bin/env python3
from __future__ import unicode_literals
-import hashlib
-import urllib.request
import json
+import os.path
+import sys
-versions_info = json.load(open('update/versions.json'))
-version = versions_info['latest']
-URL = versions_info['versions'][version]['bin'][0]
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
-data = urllib.request.urlopen(URL).read()
+from utils import read_file, write_file
+
+versions_info = json.loads(read_file('update/versions.json'))
+version = versions_info['latest']
+version_dict = versions_info['versions'][version]
# Read template page
-with open('download.html.in', 'r', encoding='utf-8') as tmplf:
- template = tmplf.read()
+template = read_file('download.html.in')
-md5sum = hashlib.md5(data).hexdigest()
-sha1sum = hashlib.sha1(data).hexdigest()
-sha256sum = hashlib.sha256(data).hexdigest()
template = template.replace('@PROGRAM_VERSION@', version)
-template = template.replace('@PROGRAM_URL@', URL)
-template = template.replace('@PROGRAM_MD5SUM@', md5sum)
-template = template.replace('@PROGRAM_SHA1SUM@', sha1sum)
-template = template.replace('@PROGRAM_SHA256SUM@', sha256sum)
-template = template.replace('@EXE_URL@', versions_info['versions'][version]['exe'][0])
-template = template.replace('@EXE_SHA256SUM@', versions_info['versions'][version]['exe'][1])
-template = template.replace('@TAR_URL@', versions_info['versions'][version]['tar'][0])
-template = template.replace('@TAR_SHA256SUM@', versions_info['versions'][version]['tar'][1])
-with open('download.html', 'w', encoding='utf-8') as dlf:
- dlf.write(template)
+template = template.replace('@PROGRAM_URL@', version_dict['bin'][0])
+template = template.replace('@PROGRAM_SHA256SUM@', version_dict['bin'][1])
+template = template.replace('@EXE_URL@', version_dict['exe'][0])
+template = template.replace('@EXE_SHA256SUM@', version_dict['exe'][1])
+template = template.replace('@TAR_URL@', version_dict['tar'][0])
+template = template.replace('@TAR_SHA256SUM@', version_dict['tar'][1])
+
+write_file('download.html', template)
diff --git a/devscripts/gh-pages/update-copyright.py b/devscripts/gh-pages/update-copyright.py
index e6c3abc8d..444595c48 100755
--- a/devscripts/gh-pages/update-copyright.py
+++ b/devscripts/gh-pages/update-copyright.py
@@ -5,17 +5,22 @@ from __future__ import with_statement, unicode_literals
import datetime
import glob
-import io # For Python 2 compatibility
import os
import re
+import sys
-year = str(datetime.datetime.now().year)
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(dirn(os.path.abspath(__file__)))))
+
+from devscripts.utils import read_file, write_file
+from youtube_dl import compat_str
+
+year = compat_str(datetime.datetime.now().year)
for fn in glob.glob('*.html*'):
- with io.open(fn, encoding='utf-8') as f:
- content = f.read()
- newc = re.sub(r'(?P<copyright>Copyright © 2006-)(?P<year>[0-9]{4})', 'Copyright © 2006-' + year, content)
+ content = read_file(fn)
+ newc = re.sub(r'(?P<copyright>Copyright © 2011-)(?P<year>[0-9]{4})', 'Copyright © 2011-' + year, content)
if content != newc:
tmpFn = fn + '.part'
- with io.open(tmpFn, 'wt', encoding='utf-8') as outf:
- outf.write(newc)
+ write_file(tmpFn, newc)
os.rename(tmpFn, fn)
diff --git a/devscripts/gh-pages/update-feed.py b/devscripts/gh-pages/update-feed.py
index e93eb60fb..13a367d34 100755
--- a/devscripts/gh-pages/update-feed.py
+++ b/devscripts/gh-pages/update-feed.py
@@ -2,15 +2,21 @@
from __future__ import unicode_literals
import datetime
-import io
import json
+import os.path
import textwrap
+import sys
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
+
+from utils import write_file
atom_template = textwrap.dedent("""\
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
- <link rel="self" href="http://rg3.github.io/youtube-dl/update/releases.atom" />
+ <link rel="self" href="http://ytdl-org.github.io/youtube-dl/update/releases.atom" />
<title>youtube-dl releases</title>
<id>https://yt-dl.org/feed/youtube-dl-updates-feed</id>
<updated>@TIMESTAMP@</updated>
@@ -21,7 +27,7 @@ entry_template = textwrap.dedent("""
<entry>
<id>https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@</id>
<title>New version @VERSION@</title>
- <link href="http://rg3.github.io/youtube-dl" />
+ <link href="http://ytdl-org.github.io/youtube-dl" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
Downloads available at <a href="https://yt-dl.org/downloads/@VERSION@/">https://yt-dl.org/downloads/@VERSION@/</a>
@@ -72,5 +78,4 @@ for v in versions:
entries_str = textwrap.indent(''.join(entries), '\t')
atom_template = atom_template.replace('@ENTRIES@', entries_str)
-with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
- atom_file.write(atom_template)
+write_file('update/releases.atom', atom_template)
diff --git a/devscripts/gh-pages/update-sites.py b/devscripts/gh-pages/update-sites.py
index 503c1372f..06a8a474c 100755
--- a/devscripts/gh-pages/update-sites.py
+++ b/devscripts/gh-pages/update-sites.py
@@ -5,15 +5,17 @@ import sys
import os
import textwrap
+dirn = os.path.dirname
+
# We must be able to import youtube_dl
-sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(dirn(os.path.abspath(__file__)))))
import youtube_dl
+from devscripts.utils import read_file, write_file
def main():
- with open('supportedsites.html.in', 'r', encoding='utf-8') as tmplf:
- template = tmplf.read()
+ template = read_file('supportedsites.html.in')
ie_htmls = []
for ie in youtube_dl.list_extractors(age_limit=None):
@@ -29,8 +31,8 @@ def main():
template = template.replace('@SITES@', textwrap.indent('\n'.join(ie_htmls), '\t'))
- with open('supportedsites.html', 'w', encoding='utf-8') as sitesf:
- sitesf.write(template)
+ write_file('supportedsites.html', template)
+
if __name__ == '__main__':
main()
diff --git a/devscripts/install_srelay.sh b/devscripts/install_srelay.sh
deleted file mode 100755
index 33ce8a3f7..000000000
--- a/devscripts/install_srelay.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-
-mkdir -p tmp && cd tmp
-wget -N http://downloads.sourceforge.net/project/socks-relay/socks-relay/srelay-0.4.8/srelay-0.4.8b6.tar.gz
-tar zxvf srelay-0.4.8b6.tar.gz
-cd srelay-0.4.8b6
-./configure
-make
diff --git a/devscripts/lazy_load_template.py b/devscripts/lazy_load_template.py
index 2e6e6641b..c4e5fc1f4 100644
--- a/devscripts/lazy_load_template.py
+++ b/devscripts/lazy_load_template.py
@@ -1,4 +1,4 @@
-# encoding: utf-8
+# coding: utf-8
from __future__ import unicode_literals
import re
diff --git a/devscripts/make_contributing.py b/devscripts/make_contributing.py
index 5e454a429..5a9eb194f 100755
--- a/devscripts/make_contributing.py
+++ b/devscripts/make_contributing.py
@@ -1,10 +1,11 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-import io
import optparse
import re
+from utils import read_file, write_file
+
def main():
parser = optparse.OptionParser(usage='%prog INFILE OUTFILE')
@@ -14,8 +15,7 @@ def main():
infile, outfile = args
- with io.open(infile, encoding='utf-8') as inf:
- readme = inf.read()
+ readme = read_file(infile)
bug_text = re.search(
r'(?s)#\s*BUGS\s*[^\n]*\s*(.*?)#\s*COPYRIGHT', readme).group(1)
@@ -25,8 +25,8 @@ def main():
out = bug_text + dev_text
- with io.open(outfile, 'w', encoding='utf-8') as outf:
- outf.write(out)
+ write_file(outfile, out)
+
if __name__ == '__main__':
main()
diff --git a/devscripts/make_issue_template.py b/devscripts/make_issue_template.py
index b7ad23d83..65fa8169f 100644
--- a/devscripts/make_issue_template.py
+++ b/devscripts/make_issue_template.py
@@ -1,8 +1,11 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-import io
import optparse
+import os.path
+import sys
+
+from utils import read_file, read_version, write_file
def main():
@@ -13,17 +16,11 @@ def main():
infile, outfile = args
- with io.open(infile, encoding='utf-8') as inf:
- issue_template_tmpl = inf.read()
-
- # Get the version from youtube_dl/version.py without importing the package
- exec(compile(open('youtube_dl/version.py').read(),
- 'youtube_dl/version.py', 'exec'))
+ issue_template_tmpl = read_file(infile)
- out = issue_template_tmpl % {'version': locals()['__version__']}
+ out = issue_template_tmpl % {'version': read_version()}
- with io.open(outfile, 'w', encoding='utf-8') as outf:
- outf.write(out)
+ write_file(outfile, out)
if __name__ == '__main__':
main()
diff --git a/devscripts/make_lazy_extractors.py b/devscripts/make_lazy_extractors.py
index b5a8b9190..5b8b123a4 100644
--- a/devscripts/make_lazy_extractors.py
+++ b/devscripts/make_lazy_extractors.py
@@ -3,26 +3,50 @@ from __future__ import unicode_literals, print_function
from inspect import getsource
import os
from os.path import dirname as dirn
+import re
import sys
print('WARNING: Lazy loading extractors is an experimental feature that may not always work', file=sys.stderr)
-sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
lazy_extractors_filename = sys.argv[1]
if os.path.exists(lazy_extractors_filename):
os.remove(lazy_extractors_filename)
+# Py2: may be confused by leftover lazy_extractors.pyc
+if sys.version_info[0] < 3:
+ for c in ('c', 'o'):
+ try:
+ os.remove(lazy_extractors_filename + 'c')
+ except OSError:
+ pass
+
+from devscripts.utils import read_file, write_file
+from youtube_dl.compat import compat_register_utf8
+
+compat_register_utf8()
from youtube_dl.extractor import _ALL_CLASSES
-from youtube_dl.extractor.common import InfoExtractor
+from youtube_dl.extractor.common import InfoExtractor, SearchInfoExtractor
+
+module_template = read_file('devscripts/lazy_load_template.py')
+
+
+def get_source(m):
+ return re.sub(r'(?m)^\s*#.*\n', '', getsource(m))
-with open('devscripts/lazy_load_template.py', 'rt') as f:
- module_template = f.read()
-module_contents = [module_template + '\n' + getsource(InfoExtractor.suitable)]
+module_contents = [
+ module_template,
+ get_source(InfoExtractor.suitable),
+ get_source(InfoExtractor._match_valid_url) + '\n',
+ 'class LazyLoadSearchExtractor(LazyLoadExtractor):\n pass\n',
+ # needed for suitable() methods of Youtube extractor (see #28780)
+ 'from youtube_dl.utils import parse_qs, variadic\n',
+]
ie_template = '''
-class {name}(LazyLoadExtractor):
+class {name}({bases}):
_VALID_URL = {valid_url!r}
_module = '{module}'
'''
@@ -34,30 +58,74 @@ make_valid_template = '''
'''
+def get_base_name(base):
+ if base is InfoExtractor:
+ return 'LazyLoadExtractor'
+ elif base is SearchInfoExtractor:
+ return 'LazyLoadSearchExtractor'
+ else:
+ return base.__name__
+
+
def build_lazy_ie(ie, name):
valid_url = getattr(ie, '_VALID_URL', None)
s = ie_template.format(
name=name,
+ bases=', '.join(map(get_base_name, ie.__bases__)),
valid_url=valid_url,
module=ie.__module__)
if ie.suitable.__func__ is not InfoExtractor.suitable.__func__:
- s += '\n' + getsource(ie.suitable)
+ s += '\n' + get_source(ie.suitable)
if hasattr(ie, '_make_valid_url'):
# search extractors
s += make_valid_template.format(valid_url=ie._make_valid_url())
return s
+
+# find the correct sorting and add the required base classes so that subclasses
+# can be correctly created
+classes = _ALL_CLASSES[:-1]
+ordered_cls = []
+while classes:
+ for c in classes[:]:
+ bases = set(c.__bases__) - set((object, InfoExtractor, SearchInfoExtractor))
+ stop = False
+ for b in bases:
+ if b not in classes and b not in ordered_cls:
+ if b.__name__ == 'GenericIE':
+ exit()
+ classes.insert(0, b)
+ stop = True
+ if stop:
+ break
+ if all(b in ordered_cls for b in bases):
+ ordered_cls.append(c)
+ classes.remove(c)
+ break
+ordered_cls.append(_ALL_CLASSES[-1])
+
names = []
-for ie in list(sorted(_ALL_CLASSES[:-1], key=lambda cls: cls.ie_key())) + _ALL_CLASSES[-1:]:
- name = ie.ie_key() + 'IE'
+for ie in ordered_cls:
+ name = ie.__name__
src = build_lazy_ie(ie, name)
module_contents.append(src)
- names.append(name)
+ if ie in _ALL_CLASSES:
+ names.append(name)
module_contents.append(
'_ALL_CLASSES = [{0}]'.format(', '.join(names)))
-module_src = '\n'.join(module_contents) + '\n'
+module_src = '\n'.join(module_contents)
+
+write_file(lazy_extractors_filename, module_src + '\n')
-with open(lazy_extractors_filename, 'wt') as f:
- f.write(module_src)
+# work around JVM byte code module limit in Jython
+if sys.platform.startswith('java') and sys.version_info[:2] == (2, 7):
+ import subprocess
+ from youtube_dl.compat import compat_subprocess_get_DEVNULL
+ # if Python 2.7 is available, use it to compile the module for Jython
+ try:
+ # if Python 2.7 is available, use it to compile the module for Jython
+ subprocess.check_call(['python2.7', '-m', 'py_compile', lazy_extractors_filename], stdout=compat_subprocess_get_DEVNULL())
+ except Exception:
+ pass
diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py
index 8fbce0796..7a5b04dcc 100755
--- a/devscripts/make_readme.py
+++ b/devscripts/make_readme.py
@@ -1,8 +1,14 @@
from __future__ import unicode_literals
-import io
-import sys
+import os.path
import re
+import sys
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
+
+from utils import read_file
+from youtube_dl.compat import compat_open as open
README_FILE = 'README.md'
helptext = sys.stdin.read()
@@ -10,8 +16,7 @@ helptext = sys.stdin.read()
if isinstance(helptext, bytes):
helptext = helptext.decode('utf-8')
-with io.open(README_FILE, encoding='utf-8') as f:
- oldreadme = f.read()
+oldreadme = read_file(README_FILE)
header = oldreadme[:oldreadme.index('# OPTIONS')]
footer = oldreadme[oldreadme.index('# CONFIGURATION'):]
@@ -20,7 +25,7 @@ options = helptext[helptext.index(' General Options:') + 19:]
options = re.sub(r'(?m)^ (\w.+)$', r'## \1', options)
options = '# OPTIONS\n' + options + '\n'
-with io.open(README_FILE, 'w', encoding='utf-8') as f:
+with open(README_FILE, 'w', encoding='utf-8') as f:
f.write(header)
f.write(options)
f.write(footer)
diff --git a/devscripts/make_supportedsites.py b/devscripts/make_supportedsites.py
index 8cb4a4638..c424d18d7 100644
--- a/devscripts/make_supportedsites.py
+++ b/devscripts/make_supportedsites.py
@@ -1,17 +1,19 @@
#!/usr/bin/env python
from __future__ import unicode_literals
-import io
import optparse
-import os
+import os.path
import sys
-
# Import youtube_dl
-ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
-sys.path.insert(0, ROOT_DIR)
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
+
import youtube_dl
+from utils import write_file
+
def main():
parser = optparse.OptionParser(usage='%prog OUTFILE.md')
@@ -38,8 +40,8 @@ def main():
' - ' + md + '\n'
for md in gen_ies_md(ies))
- with io.open(outfile, 'w', encoding='utf-8') as outf:
- outf.write(out)
+ write_file(outfile, out)
+
if __name__ == '__main__':
main()
diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py
index e3f6339b5..0090ada3e 100644
--- a/devscripts/prepare_manpage.py
+++ b/devscripts/prepare_manpage.py
@@ -1,14 +1,14 @@
from __future__ import unicode_literals
-import io
import optparse
import os.path
import re
+from utils import read_file, write_file
+
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
README_FILE = os.path.join(ROOT_DIR, 'README.md')
-
-PREFIX = '''%YOUTUBE-DL(1)
+PREFIX = r'''%YOUTUBE-DL(1)
# NAME
@@ -29,8 +29,7 @@ def main():
outfile, = args
- with io.open(README_FILE, encoding='utf-8') as f:
- readme = f.read()
+ readme = read_file(README_FILE)
readme = re.sub(r'(?s)^.*?(?=# DESCRIPTION)', '', readme)
readme = re.sub(r'\s+youtube-dl \[OPTIONS\] URL \[URL\.\.\.\]', '', readme)
@@ -38,8 +37,7 @@ def main():
readme = filter_options(readme)
- with io.open(outfile, 'w', encoding='utf-8') as outf:
- outf.write(readme)
+ write_file(outfile, readme)
def filter_options(readme):
@@ -54,21 +52,26 @@ def filter_options(readme):
if in_options:
if line.lstrip().startswith('-'):
- option, description = re.split(r'\s{2,}', line.lstrip())
- split_option = option.split(' ')
-
- if not split_option[-1].startswith('-'): # metavar
- option = ' '.join(split_option[:-1] + ['*%s*' % split_option[-1]])
-
- # Pandoc's definition_lists. See http://pandoc.org/README.html
- # for more information.
- ret += '\n%s\n: %s\n' % (option, description)
- else:
- ret += line.lstrip() + '\n'
+ split = re.split(r'\s{2,}', line.lstrip())
+ # Description string may start with `-` as well. If there is
+ # only one piece then it's a description bit not an option.
+ if len(split) > 1:
+ option, description = split
+ split_option = option.split(' ')
+
+ if not split_option[-1].startswith('-'): # metavar
+ option = ' '.join(split_option[:-1] + ['*%s*' % split_option[-1]])
+
+ # Pandoc's definition_lists. See http://pandoc.org/README.html
+ # for more information.
+ ret += '\n%s\n: %s\n' % (option, description)
+ continue
+ ret += line.lstrip() + '\n'
else:
ret += line + '\n'
return ret
+
if __name__ == '__main__':
main()
diff --git a/devscripts/release.sh b/devscripts/release.sh
index 87e8eda50..f2411c927 100755
--- a/devscripts/release.sh
+++ b/devscripts/release.sh
@@ -15,6 +15,7 @@
set -e
skip_tests=true
+gpg_sign_commits=""
buildserver='localhost:8142'
while true
@@ -24,6 +25,10 @@ case "$1" in
skip_tests=false
shift
;;
+ --gpg-sign-commits|-S)
+ gpg_sign_commits="-S"
+ shift
+ ;;
--buildserver)
buildserver="$2"
shift 2
@@ -55,6 +60,9 @@ if ! type pandoc >/dev/null 2>/dev/null; then echo 'ERROR: pandoc is missing'; e
if ! python3 -c 'import rsa' 2>/dev/null; then echo 'ERROR: python3-rsa is missing'; exit 1; fi
if ! python3 -c 'import wheel' 2>/dev/null; then echo 'ERROR: wheel is missing'; exit 1; fi
+read -p "Is ChangeLog up to date? (y/n) " -n 1
+if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
+
/bin/echo -e "\n### First of all, testing..."
make clean
if $skip_tests ; then
@@ -66,10 +74,13 @@ fi
/bin/echo -e "\n### Changing version in version.py..."
sed -i "s/__version__ = '.*'/__version__ = '$version'/" youtube_dl/version.py
+/bin/echo -e "\n### Changing version in ChangeLog..."
+sed -i "s/<unreleased>/$version/" ChangeLog
+
/bin/echo -e "\n### Committing documentation, templates and youtube_dl/version.py..."
-make README.md CONTRIBUTING.md .github/ISSUE_TEMPLATE.md supportedsites
-git add README.md CONTRIBUTING.md .github/ISSUE_TEMPLATE.md docs/supportedsites.md youtube_dl/version.py
-git commit -m "release $version"
+make README.md CONTRIBUTING.md issuetemplates supportedsites
+git add README.md CONTRIBUTING.md .github/ISSUE_TEMPLATE/1_broken_site.md .github/ISSUE_TEMPLATE/2_site_support_request.md .github/ISSUE_TEMPLATE/3_site_feature_request.md .github/ISSUE_TEMPLATE/4_bug_report.md .github/ISSUE_TEMPLATE/5_feature_request.md .github/ISSUE_TEMPLATE/6_question.md docs/supportedsites.md youtube_dl/version.py ChangeLog
+git commit $gpg_sign_commits -m "release $version"
/bin/echo -e "\n### Now tagging, signing and pushing..."
git tag -s -m "Release $version" "$version"
@@ -85,7 +96,7 @@ git push origin "$version"
REV=$(git rev-parse HEAD)
make youtube-dl youtube-dl.tar.gz
read -p "VM running? (y/n) " -n 1
-wget "http://$buildserver/build/rg3/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe
+wget "http://$buildserver/build/ytdl-org/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe
mkdir -p "build/$version"
mv youtube-dl youtube-dl.exe "build/$version"
mv youtube-dl.tar.gz "build/$version/youtube-dl-$version.tar.gz"
@@ -99,7 +110,7 @@ RELEASE_FILES="youtube-dl youtube-dl.exe youtube-dl-$version.tar.gz"
for f in $RELEASE_FILES; do gpg --passphrase-repeat 5 --detach-sig "build/$version/$f"; done
ROOT=$(pwd)
-python devscripts/create-github-release.py $version "$ROOT/build/$version"
+python devscripts/create-github-release.py ChangeLog $version "$ROOT/build/$version"
ssh ytdl@yt-dl.org "sh html/update_latest.sh $version"
@@ -116,7 +127,7 @@ git clone --branch gh-pages --single-branch . build/gh-pages
"$ROOT/devscripts/gh-pages/update-copyright.py"
"$ROOT/devscripts/gh-pages/update-sites.py"
git add *.html *.html.in update
- git commit -m "release $version"
+ git commit $gpg_sign_commits -m "release $version"
git push "$ROOT" gh-pages
git push "$ORIGIN_URL" gh-pages
)
diff --git a/devscripts/run_tests.bat b/devscripts/run_tests.bat
new file mode 100644
index 000000000..79359b5a7
--- /dev/null
+++ b/devscripts/run_tests.bat
@@ -0,0 +1,17 @@
+@echo off
+
+rem Keep this list in sync with the `offlinetest` target in Makefile
+set DOWNLOAD_TESTS="age_restriction^|download^|iqiyi_sdk_interpreter^|socks^|subtitles^|write_annotations^|youtube_lists^|youtube_signature"
+
+if "%YTDL_TEST_SET%" == "core" (
+ set test_set="-I test_("%DOWNLOAD_TESTS%")\.py"
+ set multiprocess_args=""
+) else if "%YTDL_TEST_SET%" == "download" (
+ set test_set="-I test_(?!"%DOWNLOAD_TESTS%").+\.py"
+ set multiprocess_args="--processes=4 --process-timeout=540"
+) else (
+ echo YTDL_TEST_SET is not set or invalid
+ exit /b 1
+)
+
+nosetests test --verbose %test_set:"=% %multiprocess_args:"=%
diff --git a/devscripts/run_tests.sh b/devscripts/run_tests.sh
new file mode 100755
index 000000000..dd37a80f5
--- /dev/null
+++ b/devscripts/run_tests.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# Keep this list in sync with the `offlinetest` target in Makefile
+DOWNLOAD_TESTS="age_restriction|download|iqiyi_sdk_interpreter|socks|subtitles|write_annotations|youtube_lists|youtube_signature"
+
+test_set=""
+multiprocess_args=""
+
+case "$YTDL_TEST_SET" in
+ core)
+ test_set="-I test_($DOWNLOAD_TESTS)\.py"
+ ;;
+ download)
+ test_set="-I test_(?!$DOWNLOAD_TESTS).+\.py"
+ multiprocess_args="--processes=4 --process-timeout=540"
+ ;;
+ *)
+ break
+ ;;
+esac
+
+nosetests test --verbose $test_set $multiprocess_args
diff --git a/devscripts/show-downloads-statistics.py b/devscripts/show-downloads-statistics.py
new file mode 100644
index 000000000..6c8d1cc2d
--- /dev/null
+++ b/devscripts/show-downloads-statistics.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+from __future__ import unicode_literals
+
+import itertools
+import json
+import os
+import re
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from youtube_dl.compat import (
+ compat_print,
+ compat_urllib_request,
+)
+from youtube_dl.utils import format_bytes
+
+
+def format_size(bytes):
+ return '%s (%d bytes)' % (format_bytes(bytes), bytes)
+
+
+total_bytes = 0
+
+for page in itertools.count(1):
+ releases = json.loads(compat_urllib_request.urlopen(
+ 'https://api.github.com/repos/ytdl-org/youtube-dl/releases?page=%s' % page
+ ).read().decode('utf-8'))
+
+ if not releases:
+ break
+
+ for release in releases:
+ compat_print(release['name'])
+ for asset in release['assets']:
+ asset_name = asset['name']
+ total_bytes += asset['download_count'] * asset['size']
+ if all(not re.match(p, asset_name) for p in (
+ r'^youtube-dl$',
+ r'^youtube-dl-\d{4}\.\d{2}\.\d{2}(?:\.\d+)?\.tar\.gz$',
+ r'^youtube-dl\.exe$')):
+ continue
+ compat_print(
+ ' %s size: %s downloads: %d'
+ % (asset_name, format_size(asset['size']), asset['download_count']))
+
+compat_print('total downloads traffic: %s' % format_size(total_bytes))
diff --git a/devscripts/utils.py b/devscripts/utils.py
new file mode 100644
index 000000000..2d072d2e0
--- /dev/null
+++ b/devscripts/utils.py
@@ -0,0 +1,62 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+import argparse
+import functools
+import os.path
+import subprocess
+import sys
+
+dirn = os.path.dirname
+
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
+
+from youtube_dl.compat import (
+ compat_kwargs,
+ compat_open as open,
+)
+
+
+def read_file(fname):
+ with open(fname, encoding='utf-8') as f:
+ return f.read()
+
+
+def write_file(fname, content, mode='w'):
+ with open(fname, mode, encoding='utf-8') as f:
+ return f.write(content)
+
+
+def read_version(fname='youtube_dl/version.py'):
+ """Get the version without importing the package"""
+ exec(compile(read_file(fname), fname, 'exec'))
+ return locals()['__version__']
+
+
+def get_filename_args(has_infile=False, default_outfile=None):
+ parser = argparse.ArgumentParser()
+ if has_infile:
+ parser.add_argument('infile', help='Input file')
+ kwargs = {'nargs': '?', 'default': default_outfile} if default_outfile else {}
+ kwargs['help'] = 'Output file'
+ parser.add_argument('outfile', **compat_kwargs(kwargs))
+
+ opts = parser.parse_args()
+ if has_infile:
+ return opts.infile, opts.outfile
+ return opts.outfile
+
+
+def compose_functions(*functions):
+ return lambda x: functools.reduce(lambda y, f: f(y), functions, x)
+
+
+def run_process(*args, **kwargs):
+ kwargs.setdefault('text', True)
+ kwargs.setdefault('check', True)
+ kwargs.setdefault('capture_output', True)
+ if kwargs['text']:
+ kwargs.setdefault('encoding', 'utf-8')
+ kwargs.setdefault('errors', 'replace')
+ kwargs = compat_kwargs(kwargs)
+ return subprocess.run(args, **kwargs)
diff --git a/devscripts/zsh-completion.py b/devscripts/zsh-completion.py
index 04728e8e2..ebd552fcb 100755
--- a/devscripts/zsh-completion.py
+++ b/devscripts/zsh-completion.py
@@ -7,6 +7,8 @@ import sys
sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
import youtube_dl
+from utils import read_file, write_file
+
ZSH_COMPLETION_FILE = "youtube-dl.zsh"
ZSH_COMPLETION_TEMPLATE = "devscripts/zsh-completion.in"
@@ -34,15 +36,14 @@ def build_completion(opt_parser):
flags = [opt.get_opt_string() for opt in opts]
- with open(ZSH_COMPLETION_TEMPLATE) as f:
- template = f.read()
+ template = read_file(ZSH_COMPLETION_TEMPLATE)
template = template.replace("{{fileopts}}", "|".join(fileopts))
template = template.replace("{{diropts}}", "|".join(diropts))
template = template.replace("{{flags}}", " ".join(flags))
- with open(ZSH_COMPLETION_FILE, "w") as f:
- f.write(template)
+ write_file(ZSH_COMPLETION_FILE, template)
+
parser = youtube_dl.parseOpts()[0]
build_completion(parser)