mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-06-06 04:52:41 +09:00
Compare commits
5 Commits
1c01efc558
...
0db6cc7dce
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0db6cc7dce | ||
![]() |
4e714f9df1 | ||
![]() |
c1ea7f5a24 | ||
![]() |
a784be7395 | ||
![]() |
991ac059a4 |
@ -32,7 +32,7 @@ class BokeCCBaseIE(InfoExtractor):
|
||||
|
||||
|
||||
class BokeCCIE(BokeCCBaseIE):
|
||||
_IE_DESC = 'CC视频'
|
||||
IE_DESC = 'CC视频'
|
||||
_VALID_URL = r'https?://union\.bokecc\.com/playvideo\.bo\?(?P<query>.*)'
|
||||
|
||||
_TESTS = [{
|
||||
|
@ -9,7 +9,7 @@ from ..utils import (
|
||||
|
||||
|
||||
class CloudyIE(InfoExtractor):
|
||||
_IE_DESC = 'cloudy.ec'
|
||||
IE_DESC = 'cloudy.ec'
|
||||
_VALID_URL = r'https?://(?:www\.)?cloudy\.ec/(?:v/|embed\.php\?.*?\bid=)(?P<id>[A-Za-z0-9]+)'
|
||||
_TESTS = [{
|
||||
'url': 'https://www.cloudy.ec/v/af511e2527aac',
|
||||
|
@ -422,6 +422,8 @@ class InfoExtractor(object):
|
||||
_GEO_COUNTRIES = None
|
||||
_GEO_IP_BLOCKS = None
|
||||
_WORKING = True
|
||||
# supply this in public subclasses: used in supported sites list, etc
|
||||
# IE_DESC = 'short description of IE'
|
||||
|
||||
def __init__(self, downloader=None):
|
||||
"""Constructor. Receives an optional downloader."""
|
||||
|
@ -1701,3 +1701,4 @@ from .zingmp3 import (
|
||||
)
|
||||
from .zoom import ZoomIE
|
||||
from .zype import ZypeIE
|
||||
from .invidious import InvidiousIE, InvidiousPlaylistIE
|
||||
|
217
youtube_dl/extractor/invidious.py
Normal file
217
youtube_dl/extractor/invidious.py
Normal file
@ -0,0 +1,217 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import compat_urllib_parse
|
||||
|
||||
INSTANCES = [
|
||||
'y.com.sb',
|
||||
'yt.artemislena.eu'
|
||||
]
|
||||
|
||||
INSTANCES_HOST_REGEX = '(?:' + '|'.join([instance.replace('.', r'\.') for instance in INSTANCES]) + ')'
|
||||
|
||||
|
||||
class InvidiousIE(InfoExtractor):
|
||||
_VALID_URL = r'(?:https?://)?(?:www\.)?' + INSTANCES_HOST_REGEX + r'/watch\?v=(?P<id>.+)'
|
||||
_TESTS = [
|
||||
{
|
||||
'url': 'https://y.com.sb/watch?v=xKTygGa6hg0',
|
||||
'info_dict': {
|
||||
'id': 'xKTygGa6hg0',
|
||||
'ext': 'mp4',
|
||||
'title': 'Coding in C++ - Creating a Player Controller - CRYENGINE Summer Academy S1E5 - [Tutorial]',
|
||||
'uploader': 'CRYENGINE',
|
||||
'uploader_id': 'UCtaXcIVFp8HEpthm7qwtKCQ',
|
||||
'description': 'md5:7aa75816d40ffccdbf3e15a90b05fca3',
|
||||
}
|
||||
},
|
||||
{
|
||||
'url': 'https://yt.artemislena.eu/watch?v=BaW_jenozKc',
|
||||
'md5': '5515885fed58607bfae88f7d2090bc93',
|
||||
'info_dict': {
|
||||
'id': 'BaW_jenozKc',
|
||||
'ext': 'mp4',
|
||||
'title': 'youtube-dl test video "\'/\\ä↭𝕐',
|
||||
'uploader': 'Philipp Hagemeister',
|
||||
'uploader_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
|
||||
'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
|
||||
'description': 'test chars: "\'/\\ä↭𝕐\ntest URL: https://github.com/rg3/youtube-dl/issues/1892\n\nThis is a test video for youtube-dl.\n\nFor more information, contact phihag@phihag.de .',
|
||||
'tags': ['youtube-dl'],
|
||||
'duration': 10,
|
||||
'view_count': int,
|
||||
'like_count': int,
|
||||
'dislike_count': int,
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
def __init__(self, downloader=None):
|
||||
super().__init__(downloader)
|
||||
|
||||
# type is either 'video' or 'audio'
|
||||
# ext is the file extension
|
||||
@staticmethod
|
||||
def _get_additional_format_data(format_type, bitrate, resolution, fps):
|
||||
out = {}
|
||||
|
||||
try:
|
||||
type_and_ext, codecs = format_type.split(';')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
type_, ext = type_and_ext.split('/')
|
||||
# codec = codecs.split('"')[1]
|
||||
out['ext'] = ext
|
||||
# if type_ == 'audio':
|
||||
# out['acodec'] = codec
|
||||
# elif type_ == 'video':
|
||||
# out['vcodec'] = codec
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
bitrate = float(bitrate) / 1000
|
||||
# if type_ == 'audio':
|
||||
# out['abr'] = bitrate
|
||||
# elif type_ == 'video':
|
||||
# out['vbr'] = bitrate
|
||||
# out['tbr'] = bitrate
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
if type_ == 'audio':
|
||||
out['resolution'] = type_and_ext + ' @ ' + str(bitrate) + 'k - audio only'
|
||||
elif type_ == 'video':
|
||||
out['resolution'] = resolution + ' - ' + type_and_ext + ' @ ' + str(fps) + 'fps - video only'
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return out
|
||||
|
||||
def _patch_url(self, url):
|
||||
return compat_urllib_parse.urlparse(url)._replace(netloc=self.url_netloc).geturl()
|
||||
|
||||
def _get_formats(self, api_response):
|
||||
all_formats = []
|
||||
|
||||
# Video/audio only
|
||||
for format_ in api_response.get('adaptiveFormats') or []:
|
||||
all_formats.append({
|
||||
'url': self._patch_url(format_['url']),
|
||||
'format_id': format_.get('itag'),
|
||||
# 'fps': format_.get('fps'),
|
||||
# 'container': format_.get('container')
|
||||
} | InvidiousIE._get_additional_format_data(format_.get('type'), format_.get('bitrate'), format_.get('resolution'), format_.get('fps')))
|
||||
|
||||
# Both video and audio
|
||||
for format_ in api_response.get('formatStreams') or []:
|
||||
all_formats.append({
|
||||
'url': self._patch_url(format_['url']),
|
||||
'format_id': format_.get('itag'),
|
||||
# 'fps': format_.get('fps'),
|
||||
# 'container': format_.get('container')
|
||||
} | InvidiousIE._get_additional_format_data(format_.get('type'), format_.get('bitrate'), format_.get('resolution'), format_.get('fps')))
|
||||
|
||||
return all_formats
|
||||
|
||||
def _get_thumbnails(self, api_response):
|
||||
thumbnails = []
|
||||
video_thumbnails = api_response.get('videoThumbnails') or []
|
||||
|
||||
for inversed_quality, thumbnail in enumerate(video_thumbnails):
|
||||
thumbnails.append({
|
||||
'id': thumbnail.get('quality'),
|
||||
'url': thumbnail.get('url'),
|
||||
'quality': len(video_thumbnails) - inversed_quality,
|
||||
'width': thumbnail.get('width'),
|
||||
'height': thumbnail.get('height')
|
||||
})
|
||||
|
||||
return thumbnails
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
webpage = None
|
||||
|
||||
# host_url will contain `http[s]://example.com` where `example.com` is the used invidious instance.
|
||||
url_parsed = compat_urllib_parse.urlparse(url)
|
||||
self.url_netloc = url_parsed.netloc
|
||||
host_url = url_parsed.scheme + '://' + url_parsed.netloc
|
||||
|
||||
api_response = self._download_json(host_url + '/api/v1/videos/' + video_id, video_id)
|
||||
|
||||
def download_webpage_and(fn, fatal=True):
|
||||
global webpage
|
||||
if webpage is None:
|
||||
webpage = self._download_webpage(url, video_id, fatal=fatal)
|
||||
return fn()
|
||||
|
||||
out = {
|
||||
'id': video_id,
|
||||
'title': api_response.get('title') or download_webpage_and(lambda: self._og_search_title(webpage)),
|
||||
'description': api_response.get('description') or download_webpage_and(lambda: self._og_search_description(webpage)),
|
||||
|
||||
'release_timestamp': api_response.get('published'),
|
||||
|
||||
'uploader': api_response.get('author'),
|
||||
'uploader_id': api_response.get('authorId'),
|
||||
'channel': api_response.get('author'),
|
||||
'channel_id': api_response.get('authorId'),
|
||||
'channel_url': host_url + api_response.get('authorUrl'),
|
||||
|
||||
'duration': api_response.get('lengthSeconds'),
|
||||
|
||||
'view_count': api_response.get('viewCount'),
|
||||
'like_count': api_response.get('likeCount'),
|
||||
'dislike_count': api_response.get('dislikeCount'),
|
||||
|
||||
# 'isFamilyFriendly': 18 if api_response.get('isFamilyFriendly') == False else None
|
||||
|
||||
'tags': api_response.get('keywords'),
|
||||
'is_live': api_response.get('liveNow'),
|
||||
|
||||
'formats': self._get_formats(api_response),
|
||||
'thumbnails': self._get_thumbnails(api_response)
|
||||
}
|
||||
|
||||
if api_response.get('isFamilyFriendly') is False:
|
||||
out['age_limit'] = 18
|
||||
|
||||
return out
|
||||
|
||||
|
||||
class InvidiousPlaylistIE(InfoExtractor):
|
||||
_VALID_URL = r'(?:https?://)?(?:www\.)?' + INSTANCES_HOST_REGEX + r'/playlist\?list=(?P<id>.+)'
|
||||
_TEST = {
|
||||
'url': 'https://yt.artemislena.eu/playlist?list=PLowKtXNTBypGqImE405J2565dvjafglHU',
|
||||
'md5': 'de4a9175071169961fe7cf2b6740da12',
|
||||
'info_dict': {
|
||||
'id': 'HyznrdDSSGM',
|
||||
'ext': 'mp4',
|
||||
'title': '8-bit computer update',
|
||||
'uploader': 'Ben Eater',
|
||||
'uploader_id': 'UCS0N5baNlQWJCUrhCEo8WlA',
|
||||
'description': 'An update on my plans to build another 8-bit computer from scratch and make videos of the whole process! Buy a kit and build your own! https://eater.net/8bit/kits\n\nSupport me on Patreon: https://www.patreon.com/beneater',
|
||||
}
|
||||
}
|
||||
|
||||
def _get_entries(self, api_response):
|
||||
return [InvidiousIE(self._downloader)._real_extract(self.host_url + '/watch?v=' + video['videoId'])
|
||||
for video in api_response['videos']]
|
||||
|
||||
def _real_extract(self, url):
|
||||
playlist_id = self._match_id(url)
|
||||
|
||||
# host_url will contain `http[s]://example.com` where `example.com` is the used invidious instance.
|
||||
url_parsed = compat_urllib_parse.urlparse(url)
|
||||
self.host_url = url_parsed.scheme + '://' + url_parsed.netloc
|
||||
|
||||
api_response = self._download_json(self.host_url + '/api/v1/playlists/' + playlist_id, playlist_id)
|
||||
return InfoExtractor.playlist_result(self._get_entries(api_response), playlist_id, api_response.get('title'), api_response.get('description')) | {
|
||||
'release_timestamp': api_response.get('updated'),
|
||||
|
||||
'uploader': api_response.get('author'),
|
||||
'uploader_id': api_response.get('authorId'),
|
||||
}
|
@ -35,15 +35,6 @@ from ..utils import (
|
||||
|
||||
class ITVBaseIE(InfoExtractor):
|
||||
|
||||
def _search_nextjs_data(self, webpage, video_id, **kw):
|
||||
transform_source = kw.pop('transform_source', None)
|
||||
fatal = kw.pop('fatal', True)
|
||||
return self._parse_json(
|
||||
self._search_regex(
|
||||
r'''<script\b[^>]+\bid=('|")__NEXT_DATA__\1[^>]*>(?P<js>[^<]+)</script>''',
|
||||
webpage, 'next.js data', group='js', fatal=fatal, **kw),
|
||||
video_id, transform_source=transform_source, fatal=fatal)
|
||||
|
||||
def __handle_request_webpage_error(self, err, video_id=None, errnote=None, fatal=True):
|
||||
if errnote is False:
|
||||
return False
|
||||
@ -109,7 +100,9 @@ class ITVBaseIE(InfoExtractor):
|
||||
|
||||
class ITVIE(ITVBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?itv\.com/(?:(?P<w>watch)|hub)/[^/]+/(?(w)[\w-]+/)(?P<id>\w+)'
|
||||
_IE_DESC = 'ITVX'
|
||||
IE_DESC = 'ITVX'
|
||||
_WORKING = False
|
||||
|
||||
_TESTS = [{
|
||||
'note': 'Hub URLs redirect to ITVX',
|
||||
'url': 'https://www.itv.com/hub/liar/2a4547a0012',
|
||||
@ -270,7 +263,7 @@ class ITVIE(ITVBaseIE):
|
||||
'ext': determine_ext(href, 'vtt'),
|
||||
})
|
||||
|
||||
next_data = self._search_nextjs_data(webpage, video_id, fatal=False, default='{}')
|
||||
next_data = self._search_nextjs_data(webpage, video_id, fatal=False, default={})
|
||||
video_data.update(traverse_obj(next_data, ('props', 'pageProps', ('title', 'episode')), expected_type=dict)[0] or {})
|
||||
title = traverse_obj(video_data, 'headerTitle', 'episodeTitle')
|
||||
info = self._og_extract(webpage, require_title=not title)
|
||||
@ -323,7 +316,7 @@ class ITVIE(ITVBaseIE):
|
||||
|
||||
class ITVBTCCIE(ITVBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?itv\.com/(?!(?:watch|hub)/)(?:[^/]+/)+(?P<id>[^/?#&]+)'
|
||||
_IE_DESC = 'ITV articles: News, British Touring Car Championship'
|
||||
IE_DESC = 'ITV articles: News, British Touring Car Championship'
|
||||
_TESTS = [{
|
||||
'note': 'British Touring Car Championship',
|
||||
'url': 'https://www.itv.com/btcc/articles/btcc-2018-all-the-action-from-brands-hatch',
|
||||
|
@ -47,7 +47,7 @@ class SenateISVPIE(InfoExtractor):
|
||||
['vetaff', '76462', 'http://vetaff-f.akamaihd.net'],
|
||||
['arch', '', 'http://ussenate-f.akamaihd.net/']
|
||||
]
|
||||
_IE_NAME = 'senate.gov'
|
||||
IE_NAME = 'senate.gov'
|
||||
_VALID_URL = r'https?://(?:www\.)?senate\.gov/isvp/?\?(?P<qs>.+)'
|
||||
_TESTS = [{
|
||||
'url': 'http://www.senate.gov/isvp/?comm=judiciary&type=live&stt=&filename=judiciary031715&auto_play=false&wmode=transparent&poster=http%3A%2F%2Fwww.judiciary.senate.gov%2Fthemes%2Fjudiciary%2Fimages%2Fvideo-poster-flash-fit.png',
|
||||
|
Loading…
x
Reference in New Issue
Block a user