From 8f2d73e425db3778a648401b2b406b22d2b80dac Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 4 Jul 2016 16:46:58 -0700 Subject: Add youtube-dl 2016.07.05 --- .gitmodules | 4 + media/gen.rc | 1 + media/youtube-dl/.rev | 1 + media/youtube-dl/gen.rc | 6 + ...Disable-use-of-ctypes-and-dynamic-loading.patch | 230 +++++++ media/youtube-dl/pylibs.txt | 659 +++++++++++++++++++++ media/youtube-dl/src | 1 + 7 files changed, 902 insertions(+) create mode 100644 media/youtube-dl/.rev create mode 100644 media/youtube-dl/gen.rc create mode 100644 media/youtube-dl/patch/0001-Disable-use-of-ctypes-and-dynamic-loading.patch create mode 100644 media/youtube-dl/pylibs.txt create mode 160000 media/youtube-dl/src diff --git a/.gitmodules b/.gitmodules index f9e40b51..b7d9d76d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -146,3 +146,7 @@ path = media/mpv/src url = https://github.com/mpv-player/mpv ignore = all +[submodule "media/youtube-dl/src"] + path = media/youtube-dl/src + url = https://github.com/rg3/youtube-dl + ignore = all diff --git a/media/gen.rc b/media/gen.rc index 7436dadc..2fc7cf2c 100644 --- a/media/gen.rc +++ b/media/gen.rc @@ -2,3 +2,4 @@ subgen alsa-lib subgen alsa-utils subgen ffmpeg subgen mpv +subgen youtube-dl diff --git a/media/youtube-dl/.rev b/media/youtube-dl/.rev new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/media/youtube-dl/.rev @@ -0,0 +1 @@ +1 diff --git a/media/youtube-dl/gen.rc b/media/youtube-dl/gen.rc new file mode 100644 index 00000000..52772d0c --- /dev/null +++ b/media/youtube-dl/gen.rc @@ -0,0 +1,6 @@ +file bin/youtube-dl '$srcdir'/bin/youtube-dl 755 +pylibs=`{grep -v '^#' pylibs.txt} +for(f in $pylibs) + file lib/python3.5/$f '$srcdir'/$f 644 + +fetch git diff --git a/media/youtube-dl/patch/0001-Disable-use-of-ctypes-and-dynamic-loading.patch b/media/youtube-dl/patch/0001-Disable-use-of-ctypes-and-dynamic-loading.patch new file mode 100644 index 00000000..2d877c39 --- /dev/null +++ b/media/youtube-dl/patch/0001-Disable-use-of-ctypes-and-dynamic-loading.patch @@ -0,0 +1,230 @@ +From 1f9fdebfd144eb57964561dad17916fac2117225 Mon Sep 17 00:00:00 2001 +From: Michael Forney +Date: Mon, 4 Jul 2016 16:14:18 -0700 +Subject: [PATCH] Disable use of ctypes and dynamic loading + +--- + youtube_dl/utils.py | 175 ++++------------------------------------------------ + 1 file changed, 11 insertions(+), 164 deletions(-) + +diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py +index d302f39..bdf3c57 100644 +--- a/youtube_dl/utils.py ++++ b/youtube_dl/utils.py +@@ -8,7 +8,6 @@ import binascii + import calendar + import codecs + import contextlib +-import ctypes + import datetime + import email.utils + import errno +@@ -1207,90 +1206,11 @@ def platform_name(): + return res + + +-def _windows_write_string(s, out): +- """ Returns True if the string was written using special methods, +- False if it has yet to be written out.""" +- # Adapted from http://stackoverflow.com/a/3259271/35070 +- +- import ctypes +- import ctypes.wintypes +- +- WIN_OUTPUT_IDS = { +- 1: -11, +- 2: -12, +- } +- +- try: +- fileno = out.fileno() +- except AttributeError: +- # If the output stream doesn't have a fileno, it's virtual +- return False +- except io.UnsupportedOperation: +- # Some strange Windows pseudo files? +- return False +- if fileno not in WIN_OUTPUT_IDS: +- return False +- +- GetStdHandle = ctypes.WINFUNCTYPE( +- ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD)( +- (b'GetStdHandle', ctypes.windll.kernel32)) +- h = GetStdHandle(WIN_OUTPUT_IDS[fileno]) +- +- WriteConsoleW = ctypes.WINFUNCTYPE( +- ctypes.wintypes.BOOL, ctypes.wintypes.HANDLE, ctypes.wintypes.LPWSTR, +- ctypes.wintypes.DWORD, ctypes.POINTER(ctypes.wintypes.DWORD), +- ctypes.wintypes.LPVOID)((b'WriteConsoleW', ctypes.windll.kernel32)) +- written = ctypes.wintypes.DWORD(0) +- +- GetFileType = ctypes.WINFUNCTYPE(ctypes.wintypes.DWORD, ctypes.wintypes.DWORD)((b'GetFileType', ctypes.windll.kernel32)) +- FILE_TYPE_CHAR = 0x0002 +- FILE_TYPE_REMOTE = 0x8000 +- GetConsoleMode = ctypes.WINFUNCTYPE( +- ctypes.wintypes.BOOL, ctypes.wintypes.HANDLE, +- ctypes.POINTER(ctypes.wintypes.DWORD))( +- (b'GetConsoleMode', ctypes.windll.kernel32)) +- INVALID_HANDLE_VALUE = ctypes.wintypes.DWORD(-1).value +- +- def not_a_console(handle): +- if handle == INVALID_HANDLE_VALUE or handle is None: +- return True +- return ((GetFileType(handle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR or +- GetConsoleMode(handle, ctypes.byref(ctypes.wintypes.DWORD())) == 0) +- +- if not_a_console(h): +- return False +- +- def next_nonbmp_pos(s): +- try: +- return next(i for i, c in enumerate(s) if ord(c) > 0xffff) +- except StopIteration: +- return len(s) +- +- while s: +- count = min(next_nonbmp_pos(s), 1024) +- +- ret = WriteConsoleW( +- h, s, count if count else 2, ctypes.byref(written), None) +- if ret == 0: +- raise OSError('Failed to write string') +- if not count: # We just wrote a non-BMP character +- assert written.value == 2 +- s = s[1:] +- else: +- assert written.value > 0 +- s = s[written.value:] +- return True +- +- + def write_string(s, out=None, encoding=None): + if out is None: + out = sys.stderr + assert type(s) == compat_str + +- if sys.platform == 'win32' and encoding is None and hasattr(out, 'fileno'): +- if _windows_write_string(s, out): +- return +- + if ('b' in getattr(out, 'mode', '') or + sys.version_info[0] < 3): # Python 2 lies about mode of sys.stderr + byt = s.encode(encoding or preferredencoding(), 'ignore') +@@ -1320,78 +1240,22 @@ def intlist_to_bytes(xs): + + + # Cross-platform file locking +-if sys.platform == 'win32': +- import ctypes.wintypes +- import msvcrt +- +- class OVERLAPPED(ctypes.Structure): +- _fields_ = [ +- ('Internal', ctypes.wintypes.LPVOID), +- ('InternalHigh', ctypes.wintypes.LPVOID), +- ('Offset', ctypes.wintypes.DWORD), +- ('OffsetHigh', ctypes.wintypes.DWORD), +- ('hEvent', ctypes.wintypes.HANDLE), +- ] +- +- kernel32 = ctypes.windll.kernel32 +- LockFileEx = kernel32.LockFileEx +- LockFileEx.argtypes = [ +- ctypes.wintypes.HANDLE, # hFile +- ctypes.wintypes.DWORD, # dwFlags +- ctypes.wintypes.DWORD, # dwReserved +- ctypes.wintypes.DWORD, # nNumberOfBytesToLockLow +- ctypes.wintypes.DWORD, # nNumberOfBytesToLockHigh +- ctypes.POINTER(OVERLAPPED) # Overlapped +- ] +- LockFileEx.restype = ctypes.wintypes.BOOL +- UnlockFileEx = kernel32.UnlockFileEx +- UnlockFileEx.argtypes = [ +- ctypes.wintypes.HANDLE, # hFile +- ctypes.wintypes.DWORD, # dwReserved +- ctypes.wintypes.DWORD, # nNumberOfBytesToLockLow +- ctypes.wintypes.DWORD, # nNumberOfBytesToLockHigh +- ctypes.POINTER(OVERLAPPED) # Overlapped +- ] +- UnlockFileEx.restype = ctypes.wintypes.BOOL +- whole_low = 0xffffffff +- whole_high = 0x7fffffff ++try: ++ import fcntl + + def _lock_file(f, exclusive): +- overlapped = OVERLAPPED() +- overlapped.Offset = 0 +- overlapped.OffsetHigh = 0 +- overlapped.hEvent = 0 +- f._lock_file_overlapped_p = ctypes.pointer(overlapped) +- handle = msvcrt.get_osfhandle(f.fileno()) +- if not LockFileEx(handle, 0x2 if exclusive else 0x0, 0, +- whole_low, whole_high, f._lock_file_overlapped_p): +- raise OSError('Locking file failed: %r' % ctypes.FormatError()) ++ fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH) + + def _unlock_file(f): +- assert f._lock_file_overlapped_p +- handle = msvcrt.get_osfhandle(f.fileno()) +- if not UnlockFileEx(handle, 0, +- whole_low, whole_high, f._lock_file_overlapped_p): +- raise OSError('Unlocking file failed: %r' % ctypes.FormatError()) +- +-else: +- # Some platforms, such as Jython, is missing fcntl +- try: +- import fcntl ++ fcntl.flock(f, fcntl.LOCK_UN) ++except ImportError: ++ UNSUPPORTED_MSG = 'file locking is not supported on this platform' + +- def _lock_file(f, exclusive): +- fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH) +- +- def _unlock_file(f): +- fcntl.flock(f, fcntl.LOCK_UN) +- except ImportError: +- UNSUPPORTED_MSG = 'file locking is not supported on this platform' +- +- def _lock_file(f, exclusive): +- raise IOError(UNSUPPORTED_MSG) ++ def _lock_file(f, exclusive): ++ raise IOError(UNSUPPORTED_MSG) + +- def _unlock_file(f): +- raise IOError(UNSUPPORTED_MSG) ++ def _unlock_file(f): ++ raise IOError(UNSUPPORTED_MSG) + + + class locked_file(object): +@@ -1580,24 +1444,7 @@ def fix_xml_ampersands(xml_str): + + + def setproctitle(title): +- assert isinstance(title, compat_str) +- +- # ctypes in Jython is not complete +- # http://bugs.jython.org/issue2148 +- if sys.platform.startswith('java'): +- return +- +- try: +- libc = ctypes.cdll.LoadLibrary('libc.so.6') +- except OSError: +- return +- title_bytes = title.encode('utf-8') +- buf = ctypes.create_string_buffer(len(title_bytes)) +- buf.value = title_bytes +- try: +- libc.prctl(15, buf, 0, 0, 0) +- except AttributeError: +- return # Strange libc, just skip this ++ return + + + def remove_start(s, start): +-- +2.9.0 + diff --git a/media/youtube-dl/pylibs.txt b/media/youtube-dl/pylibs.txt new file mode 100644 index 00000000..c8669476 --- /dev/null +++ b/media/youtube-dl/pylibs.txt @@ -0,0 +1,659 @@ +#