Skip to content

Commit

Permalink
mock youtube.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kuriho committed Jun 6, 2023
1 parent 54e5e37 commit ca3118d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ jobs:
yt_dlp/extractor/commonmistakes.py
yt_dlp/extractor/commonprotocols.py
yt_dlp/extractor/extractors.py
yt_dlp/extractor/generic.py
yt_dlp/extractor/openload.py
yt_dlp/extractor/tver.py
- name: Check status
run: |
#don't check modded files
git update-index --assume-unchanged lib/yt_dlp/extractor/_extractors.py
git update-index --assume-unchanged lib/yt_dlp/extractor/generic.py
git update-index --assume-unchanged lib/yt_dlp/extractor/youtube.py
if [[ -z $(git status --porcelain) ]]; then
echo "clean=true" >> $GITHUB_ENV
Expand All @@ -59,7 +60,7 @@ jobs:
#don't track modded files
git update-index --assume-unchanged lib/yt_dlp/extractor/_extractors.py
git update-index --assume-unchanged lib/yt_dlp/extractor/generic.py
git update-index --assume-unchanged lib/yt_dlp/extractor/youtube.py
git add -A
git commit -m "yt_dlp: ${{ env.commit_upstream }}"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _By removing all extractors that are irrelevant to TVer.jp, yt-dlp-tver not only
If this approach ultimately proves to be a poor decision, I can still take solace in the fact that I gained valuable knowledge about GitHub Actions along the way.

## Modifications
Besides removing all extractors that aren't necessary for extracting a valid stream manifest URL from TVer.jp, there had to be made some minor changes to [_extractors.py](lib/yt_dlp/extractor/_extractors.py) and (sadly) [generic.py](https://gist.github.com/kuriho/6030dbda5bb07dc8f307d78d2770457e/revisions?diff=unified).
Besides removing all extractors that aren't necessary for extracting a valid stream manifest URL from TVer.jp, there had to be made some minor changes to [_extractors.py](lib/yt_dlp/extractor/_extractors.py) and [youtube.py](lib/yt_dlp/extractor/youtube.py).

## CI pipeline
<img src="https://github.com/kuriho/script.module.yt-dlp-tver/blob/master/media/ci.png?raw=true" alt="drawing" width="600"/>
Expand Down
11 changes: 10 additions & 1 deletion lib/yt_dlp/extractor/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .common import InfoExtractor # isort: split
from .commonprotocols import RtmpIE
from .youtube import YoutubeIE
from ..compat import compat_etree_fromstring
from ..utils import (
KNOWN_EXTENSIONS,
Expand Down Expand Up @@ -2634,6 +2635,8 @@ def _extract_embeds(self, url, webpage, *, urlh=None, info_dict={}):
if isinstance(src_type, str):
src_type = src_type.lower()
ext = determine_ext(src).lower()
if src_type == 'video/youtube':
return [self.url_result(src, YoutubeIE.ie_key())]
if src_type == 'application/dash+xml' or ext == 'mpd':
fmts, subs = self._extract_mpd_formats_and_subtitles(
src, video_id, mpd_id='dash', fatal=False)
Expand Down Expand Up @@ -2703,6 +2706,8 @@ def _extract_embeds(self, url, webpage, *, urlh=None, info_dict={}):
}, json_ld)]

def check_video(vurl):
if YoutubeIE.suitable(vurl):
return True
if RtmpIE.suitable(vurl):
return True
vpath = urllib.parse.urlparse(vurl).path
Expand Down Expand Up @@ -2814,6 +2819,10 @@ def filter_video(urls):
video_url = urllib.parse.urljoin(url, video_url)
video_id = urllib.parse.unquote(os.path.basename(video_url))

# Sometimes, jwplayer extraction will result in a YouTube URL
if YoutubeIE.suitable(video_url):
entries.append(self.url_result(video_url, 'Youtube'))
continue

video_id = os.path.splitext(video_id)[0]
headers = {
Expand Down Expand Up @@ -2875,4 +2884,4 @@ def filter_video(urls):
# 'url' results don't have a title
if e.get('title') is not None:
e['title'] = '%s (%d)' % (e['title'], num)
return entries
return entries
6 changes: 6 additions & 0 deletions lib/yt_dlp/extractor/youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .common import InfoExtractor

class YoutubeIE(InfoExtractor):
@classmethod
def suitable(cls, url):
return False

0 comments on commit ca3118d

Please sign in to comment.