diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d2701a9e..40f07eae 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -63,6 +63,14 @@ jobs: python -m pip install --upgrade --target=./Contents/Libraries/Shared -r \ requirements.txt --no-warn-script-location + - name: Patch youtube-dl + shell: bash + working-directory: Contents/Libraries/Shared/youtube_dl + run: | + patch_dir=${{ github.workspace }}/patches + git apply -v --ignore-whitespace "${patch_dir}/youtube_dl-compat.patch" + git apply -v --ignore-whitespace "${patch_dir}/youtube_dl-extractor.patch" + - name: Install npm packages working-directory: Themerr-plex.bundle run: | @@ -92,6 +100,7 @@ jobs: "-xr!Themerr-plex.bundle/DOCKER_README.md" \ "-xr!Themerr-plex.bundle/Dockerfile" \ "-xr!Themerr-plex.bundle/docs" \ + "-xr!Themerr-plex.bundle/patches" \ "-xr!Themerr-plex.bundle/scripts" \ "-xr!Themerr-plex.bundle/tests" \ a "./Themerr-plex.bundle.zip" "Themerr-plex.bundle" diff --git a/Dockerfile b/Dockerfile index bdcb9513..65bf6b15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,17 @@ python2 -m pip --no-python-version-warning --disable-pip-version-check install - python2 ./scripts/build_plist.py _BUILD +# patch youtube-dl +WORKDIR /build/Contents/Libraries/Shared/youtube_dl +RUN <<_YOUTUBE_DL_PATCH +#!/bin/bash +set -e +patch_dir=/build/patches +git apply -v --ignore-whitespace "${patch_dir}/youtube_dl-compat.patch" +git apply -v --ignore-whitespace "${patch_dir}/youtube_dl-extractor.patch" +_YOUTUBE_DL_PATCH +WORKDIR /build + # setup npm and dependencies RUN <<_NPM #!/bin/bash @@ -61,6 +72,7 @@ _NPM RUN <<_CLEAN #!/bin/bash set -e +rm -rf ./patches/ rm -rf ./scripts/ # list contents ls -a diff --git a/patches/youtube_dl-compat.patch b/patches/youtube_dl-compat.patch new file mode 100644 index 00000000..9c878397 --- /dev/null +++ b/patches/youtube_dl-compat.patch @@ -0,0 +1,38 @@ +diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py +index 3c526a78d..6e2a92d92 100644 +--- a/youtube_dl/compat.py ++++ b/youtube_dl/compat.py +@@ -58,18 +58,22 @@ except ImportError: # Python 2 + + # Also fix up lack of method arg in old Pythons + try: +- _req = compat_urllib_request.Request +- _req('http://127.0.0.1', method='GET') ++ type(compat_urllib_request.Request('http://127.0.0.1', method='GET')) + except TypeError: +- class _request(object): +- def __new__(cls, url, *args, **kwargs): +- method = kwargs.pop('method', None) +- r = _req(url, *args, **kwargs) +- if method: +- r.get_method = types.MethodType(lambda _: method, r) +- return r +- +- compat_urllib_request.Request = _request ++ def _add_init_method_arg(cls): ++ init = cls.__init__ ++ ++ def wrapped_init(self, *args, **kwargs): ++ method = kwargs.pop('method', 'GET') ++ init(self, *args, **kwargs) ++ if self.has_data() and method == 'GET': ++ method = 'POST' ++ self.get_method = types.MethodType(lambda _: method, self) ++ ++ cls.__init__ = wrapped_init ++ ++ _add_init_method_arg(compat_urllib_request.Request) ++ del _add_init_method_arg + + + try: diff --git a/patches/youtube_dl-extractor.patch b/patches/youtube_dl-extractor.patch new file mode 100644 index 00000000..384e6fd9 --- /dev/null +++ b/patches/youtube_dl-extractor.patch @@ -0,0 +1,25 @@ +diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py +index 9c419c002..3bf483c1c 100644 +--- a/youtube_dl/extractor/youtube.py ++++ b/youtube_dl/extractor/youtube.py +@@ -260,16 +260,10 @@ class YoutubeBaseInfoExtractor(InfoExtractor): + cookies = self._get_cookies('https://www.youtube.com/') + if cookies.get('__Secure-3PSID'): + return +- consent_id = None +- consent = cookies.get('CONSENT') +- if consent: +- if 'YES' in consent.value: +- return +- consent_id = self._search_regex( +- r'PENDING\+(\d+)', consent.value, 'consent', default=None) +- if not consent_id: +- consent_id = random.randint(100, 999) +- self._set_cookie('.youtube.com', 'CONSENT', 'YES+cb.20210328-17-p0.en+FX+%s' % consent_id) ++ socs = cookies.get('SOCS') ++ if socs and not socs.value.startswith('CAA'): # not consented ++ return ++ self._set_cookie('.youtube.com', 'SOCS', 'CAI', secure=True) # accept all (required for mixes) + + def _real_initialize(self): + self._initialize_consent() diff --git a/requirements.txt b/requirements.txt index 38fbd8ab..e14a70f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,8 +13,10 @@ werkzeug==1.0.1;python_version<"3" # youtube_dl is not capable or willing to create a new release so have to install from git # youtube_dl==2021.12.17 # dependabot cannot update this -# git+https://github.com/ytdl-org/youtube-dl.git@26035bde46c0acc30dc053618451d9aeca4b7709#egg=youtube_dl -https://github.com/ytdl-org/youtube-dl/archive/26035bde46c0acc30dc053618451d9aeca4b7709.zip#egg=youtube_dl +# git+https://github.com/ytdl-org/youtube-dl.git@1720c04dc56fa0d2caa0a455b1acbd569347482e#egg=youtube_dl +# https://github.com/ytdl-org/youtube-dl/archive/1720c04dc56fa0d2caa0a455b1acbd569347482e.zip#egg=youtube_dl +https://github.com/ytdl-org/youtube-dl/archive/00ef748cc0e35ee60efd0f7a00e373ab8d1af86b.zip#egg=youtube_dl +# https://github.com/reenignearcher/youtube-dl/archive/fix-urllib2-missing-attribute.zip#egg=youtube_dl # required for websocket to pass tests pysocks==1.7.1;python_version<"3"