aboutsummaryrefslogtreecommitdiffstats
path: root/devscripts
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2022-06-27 01:25:17 +0800
committerJesús <heckyel@hyperbola.info>2022-06-27 01:25:17 +0800
commit16e8548f6a720a78679e417a20a300db2036bf6c (patch)
treeb1247bca3417ce882e4a4d80213f41c20113c1a4 /devscripts
parent4bbf329feb5a820ac21269fa426c95ca14d7af25 (diff)
parente08f72e6759fb6b1102521f0bdb9457038ef7c06 (diff)
downloadhypervideo-pre-16e8548f6a720a78679e417a20a300db2036bf6c.tar.lz
hypervideo-pre-16e8548f6a720a78679e417a20a300db2036bf6c.tar.xz
hypervideo-pre-16e8548f6a720a78679e417a20a300db2036bf6c.zip
updated from upstream | 27/06/2022 at 01:25
Diffstat (limited to 'devscripts')
-rwxr-xr-xdevscripts/bash-completion.py3
-rw-r--r--devscripts/check-porn.py10
-rwxr-xr-xdevscripts/fish-completion.py6
-rw-r--r--devscripts/generate_aes_testdata.py8
-rwxr-xr-xdevscripts/make_contributing.py1
-rw-r--r--devscripts/make_lazy_extractors.py9
-rw-r--r--devscripts/make_readme.py68
-rw-r--r--devscripts/make_supportedsites.py6
-rw-r--r--devscripts/prepare_manpage.py3
-rwxr-xr-xdevscripts/run_tests.sh2
-rwxr-xr-xdevscripts/zsh-completion.py3
11 files changed, 94 insertions, 25 deletions
diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py
index 268e8a2ae..9b4a9d4e2 100755
--- a/devscripts/bash-completion.py
+++ b/devscripts/bash-completion.py
@@ -1,9 +1,12 @@
#!/usr/bin/env python3
+
+# Allow direct execution
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
import yt_dlp
BASH_COMPLETION_FILE = "completions/bash/yt-dlp"
diff --git a/devscripts/check-porn.py b/devscripts/check-porn.py
index 08f663e4b..fc72c3051 100644
--- a/devscripts/check-porn.py
+++ b/devscripts/check-porn.py
@@ -13,9 +13,11 @@ import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from test.helper import gettestcases
-from yt_dlp.utils import compat_urllib_parse_urlparse, compat_urllib_request
+import urllib.parse
+import urllib.request
+
+from test.helper import gettestcases
if len(sys.argv) > 1:
METHOD = 'LIST'
@@ -26,7 +28,7 @@ else:
for test in gettestcases():
if METHOD == 'EURISTIC':
try:
- webpage = compat_urllib_request.urlopen(test['url'], timeout=10).read()
+ webpage = urllib.request.urlopen(test['url'], timeout=10).read()
except Exception:
print('\nFail: {}'.format(test['name']))
continue
@@ -36,7 +38,7 @@ for test in gettestcases():
RESULT = 'porn' in webpage.lower()
elif METHOD == 'LIST':
- domain = compat_urllib_parse_urlparse(test['url']).netloc
+ domain = urllib.parse.urlparse(test['url']).netloc
if not domain:
print('\nFail: {}'.format(test['name']))
continue
diff --git a/devscripts/fish-completion.py b/devscripts/fish-completion.py
index d9c0048e2..5d2f68a48 100755
--- a/devscripts/fish-completion.py
+++ b/devscripts/fish-completion.py
@@ -1,10 +1,14 @@
#!/usr/bin/env python3
-import optparse
+
+# Allow direct execution
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import optparse
+
import yt_dlp
from yt_dlp.utils import shell_quote
diff --git a/devscripts/generate_aes_testdata.py b/devscripts/generate_aes_testdata.py
index c7d83f1a7..7f3c88bcf 100644
--- a/devscripts/generate_aes_testdata.py
+++ b/devscripts/generate_aes_testdata.py
@@ -1,11 +1,15 @@
#!/usr/bin/env python3
-import codecs
+
+# Allow direct execution
import os
-import subprocess
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import codecs
+import subprocess
+
from yt_dlp.aes import aes_encrypt, key_expansion
from yt_dlp.utils import intlist_to_bytes
diff --git a/devscripts/make_contributing.py b/devscripts/make_contributing.py
index 361e17d8c..d74462a3c 100755
--- a/devscripts/make_contributing.py
+++ b/devscripts/make_contributing.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+
import optparse
import re
diff --git a/devscripts/make_lazy_extractors.py b/devscripts/make_lazy_extractors.py
index 8c481bc2d..785d66a6a 100644
--- a/devscripts/make_lazy_extractors.py
+++ b/devscripts/make_lazy_extractors.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python3
+
+# Allow direct execution
import os
-import optparse
import sys
-from inspect import getsource
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+import optparse
+from inspect import getsource
+
NO_ATTR = object()
STATIC_CLASS_PROPERTIES = ['IE_NAME', 'IE_DESC', 'SEARCH_KEY', '_WORKING', '_NETRC_MACHINE', 'age_limit']
CLASS_METHODS = [
@@ -53,7 +56,7 @@ def get_all_ies():
if os.path.exists(PLUGINS_DIRNAME):
os.rename(PLUGINS_DIRNAME, BLOCKED_DIRNAME)
try:
- from yt_dlp.extractor import _ALL_CLASSES
+ from yt_dlp.extractor.extractors import _ALL_CLASSES
finally:
if os.path.exists(BLOCKED_DIRNAME):
os.rename(BLOCKED_DIRNAME, PLUGINS_DIRNAME)
diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py
index fd234bf58..f2e08d7c6 100644
--- a/devscripts/make_readme.py
+++ b/devscripts/make_readme.py
@@ -1,7 +1,12 @@
#!/usr/bin/env python3
-# yt-dlp --help | make_readme.py
-# This must be run in a console of correct width
+"""
+yt-dlp --help | make_readme.py
+This must be run in a console of correct width
+"""
+
+
+import functools
import re
import sys
@@ -10,21 +15,60 @@ README_FILE = 'README.md'
OPTIONS_START = 'General Options:'
OPTIONS_END = 'CONFIGURATION'
EPILOG_START = 'See full documentation'
+ALLOWED_OVERSHOOT = 2
+
+DISABLE_PATCH = object()
+
+
+def take_section(text, start=None, end=None, *, shift=0):
+ return text[
+ text.index(start) + shift if start else None:
+ text.index(end) + shift if end else None
+ ]
-helptext = sys.stdin.read()
-if isinstance(helptext, bytes):
- helptext = helptext.decode()
+def apply_patch(text, patch):
+ return text if patch[0] is DISABLE_PATCH else re.sub(*patch, text)
-start, end = helptext.index(f'\n {OPTIONS_START}'), helptext.index(f'\n{EPILOG_START}')
-options = re.sub(r'(?m)^ (\w.+)$', r'## \1', helptext[start + 1: end + 1])
+
+options = take_section(sys.stdin.read(), f'\n {OPTIONS_START}', f'\n{EPILOG_START}', shift=1)
+
+max_width = max(map(len, options.split('\n')))
+switch_col_width = len(re.search(r'(?m)^\s{5,}', options).group())
+delim = f'\n{" " * switch_col_width}'
+
+PATCHES = (
+ ( # Headings
+ r'(?m)^ (\w.+\n)( (?=\w))?',
+ r'## \1'
+ ),
+ ( # Do not split URLs
+ rf'({delim[:-1]})? (?P<label>\[\S+\] )?(?P<url>https?({delim})?:({delim})?/({delim})?/(({delim})?\S+)+)\s',
+ lambda mobj: ''.join((delim, mobj.group('label') or '', re.sub(r'\s+', '', mobj.group('url')), '\n'))
+ ),
+ ( # Do not split "words"
+ rf'(?m)({delim}\S+)+$',
+ lambda mobj: ''.join((delim, mobj.group(0).replace(delim, '')))
+ ),
+ ( # Allow overshooting last line
+ rf'(?m)^(?P<prev>.+)${delim}(?P<current>.+)$(?!{delim})',
+ lambda mobj: (mobj.group().replace(delim, ' ')
+ if len(mobj.group()) - len(delim) + 1 <= max_width + ALLOWED_OVERSHOOT
+ else mobj.group())
+ ),
+ ( # Avoid newline when a space is available b/w switch and description
+ DISABLE_PATCH, # This creates issues with prepare_manpage
+ r'(?m)^(\s{4}-.{%d})(%s)' % (switch_col_width - 6, delim),
+ r'\1 '
+ ),
+)
with open(README_FILE, encoding='utf-8') as f:
readme = f.read()
-header = readme[:readme.index(f'## {OPTIONS_START}')]
-footer = readme[readme.index(f'# {OPTIONS_END}'):]
-
with open(README_FILE, 'w', encoding='utf-8') as f:
- for part in (header, options, footer):
- f.write(part)
+ f.write(''.join((
+ take_section(readme, end=f'## {OPTIONS_START}'),
+ functools.reduce(apply_patch, PATCHES, options),
+ take_section(readme, f'# {OPTIONS_END}'),
+ )))
diff --git a/devscripts/make_supportedsites.py b/devscripts/make_supportedsites.py
index d8c53c5e1..e46f7af56 100644
--- a/devscripts/make_supportedsites.py
+++ b/devscripts/make_supportedsites.py
@@ -1,10 +1,14 @@
#!/usr/bin/env python3
-import optparse
+
+# Allow direct execution
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import optparse
+
from yt_dlp.extractor import list_extractor_classes
diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py
index df9abe5ae..d12ff4947 100644
--- a/devscripts/prepare_manpage.py
+++ b/devscripts/prepare_manpage.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+
import optparse
import os.path
import re
@@ -23,7 +24,7 @@ yt\-dlp \- A youtube-dl fork with additional features and patches
def main():
parser = optparse.OptionParser(usage='%prog OUTFILE.md')
- options, args = parser.parse_args()
+ _, args = parser.parse_args()
if len(args) != 1:
parser.error('Expected an output filename')
diff --git a/devscripts/run_tests.sh b/devscripts/run_tests.sh
index e9904ae35..d496a092b 100755
--- a/devscripts/run_tests.sh
+++ b/devscripts/run_tests.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env sh
if [ -z $1 ]; then
test_set='test'
diff --git a/devscripts/zsh-completion.py b/devscripts/zsh-completion.py
index 59faea06a..267af5f6e 100755
--- a/devscripts/zsh-completion.py
+++ b/devscripts/zsh-completion.py
@@ -1,9 +1,12 @@
#!/usr/bin/env python3
+
+# Allow direct execution
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
import yt_dlp
ZSH_COMPLETION_FILE = "completions/zsh/_yt-dlp"