]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/embedly.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / extractor / embedly.py
1 import re
2 import urllib.parse
3
4 from .common import InfoExtractor
5 from .youtube import YoutubeTabIE
6 from ..utils import parse_qs, smuggle_url, traverse_obj
7
8
9 class EmbedlyIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www|cdn\.)?embedly\.com/widgets/media\.html\?(?:[^#]*?&)?(?:src|url)=(?:[^#&]+)'
11 _TESTS = [{
12 'url': 'https://cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DUUGLim4T2loE5rwCMdpCIPVg&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSU4fj_aEMVw%26list%3DUUGLim4T2loE5rwCMdpCIPVg&image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FSU4fj_aEMVw%2Fhqdefault.jpg&key=8ee8a2e6a8cc47aab1a5ee67f9a178e0&type=text%2Fhtml&schema=youtube&autoplay=1',
13 'info_dict': {
14 'id': 'UUGLim4T2loE5rwCMdpCIPVg',
15 'modified_date': '20221225',
16 'view_count': int,
17 'uploader_url': 'https://www.youtube.com/@TraciHinesMusic',
18 'channel_id': 'UCGLim4T2loE5rwCMdpCIPVg',
19 'uploader': 'TraciJHines',
20 'channel_url': 'https://www.youtube.com/@TraciHinesMusic',
21 'channel': 'TraciJHines',
22 'availability': 'public',
23 'uploader_id': 'UCGLim4T2loE5rwCMdpCIPVg',
24 'description': '',
25 'tags': [],
26 'title': 'Uploads from TraciJHines',
27 },
28 'playlist_mincount': 10,
29 }, {
30 'url': 'https://cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DUUGLim4T2loE5rwCMdpCIPVg&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSU4fj_aEMVw%26list%3DUUGLim4T2loE5rwCMdpCIPVg&image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FSU4fj_aEMVw%2Fhqdefault.jpg&key=8ee8a2e6a8cc47aab1a5ee67f9a178e0&type=text%2Fhtml&schema=youtube&autoplay=1',
31 'params': {'noplaylist': True},
32 'info_dict': {
33 'id': 'SU4fj_aEMVw',
34 'ext': 'mp4',
35 'title': 'I\'m on Patreon!',
36 'age_limit': 0,
37 'categories': ['Entertainment'],
38 'thumbnail': 'https://i.ytimg.com/vi_webp/SU4fj_aEMVw/maxresdefault.webp',
39 'live_status': 'not_live',
40 'playable_in_embed': True,
41 'channel': 'TraciJHines',
42 'uploader_id': 'TraciJHines',
43 'channel_url': 'https://www.youtube.com/channel/UCGLim4T2loE5rwCMdpCIPVg',
44 'uploader_url': 'http://www.youtube.com/user/TraciJHines',
45 'upload_date': '20150211',
46 'duration': 282,
47 'availability': 'public',
48 'channel_follower_count': int,
49 'tags': 'count:39',
50 'view_count': int,
51 'comment_count': int,
52 'channel_id': 'UCGLim4T2loE5rwCMdpCIPVg',
53 'like_count': int,
54 'uploader': 'TraciJHines',
55 'description': 'md5:8af6425f50bd46fbf29f3db0fc3a8364',
56 'chapters': list,
57
58 },
59 }, {
60 'url': 'https://cdn.embedly.com/widgets/media.html?src=https://player.vimeo.com/video/1234567?h=abcdefgh',
61 'only_matching': True,
62 }]
63
64 _WEBPAGE_TESTS = [{
65 'url': 'http://www.permacultureetc.com/2022/12/comment-greffer-facilement-les-arbres-fruitiers.html',
66 'info_dict': {
67 'id': 'pfUK_ADTvgY',
68 'ext': 'mp4',
69 'title': 'Comment greffer facilement les arbres fruitiers ? (mois par mois)',
70 'description': 'md5:d3a876995e522f138aabb48e040bfb4c',
71 'view_count': int,
72 'upload_date': '20221210',
73 'comment_count': int,
74 'live_status': 'not_live',
75 'channel_id': 'UCsM4_jihNFYe4CtSkXvDR-Q',
76 'channel_follower_count': int,
77 'tags': ['permaculture', 'jardinage', 'dekarz', 'autonomie', 'greffe', 'fruitiers', 'arbres', 'jardin forêt', 'forêt comestible', 'damien'],
78 'playable_in_embed': True,
79 'uploader': 'permaculture agroécologie etc...',
80 'channel': 'permaculture agroécologie etc...',
81 'thumbnail': 'https://i.ytimg.com/vi/pfUK_ADTvgY/sddefault.jpg',
82 'duration': 1526,
83 'channel_url': 'https://www.youtube.com/channel/UCsM4_jihNFYe4CtSkXvDR-Q',
84 'age_limit': 0,
85 'uploader_id': 'permacultureetc',
86 'like_count': int,
87 'uploader_url': 'http://www.youtube.com/user/permacultureetc',
88 'categories': ['Education'],
89 'availability': 'public',
90 },
91 }]
92
93 @classmethod
94 def _extract_from_webpage(cls, url, webpage):
95 # Bypass "ie=cls" and suitable check
96 for mobj in re.finditer(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage):
97 yield cls.url_result(mobj.group('url'))
98
99 for mobj in re.finditer(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage):
100 yield cls.url_result(urllib.parse.unquote(mobj.group('url')))
101
102 def _real_extract(self, url):
103 qs = parse_qs(url)
104 src = urllib.parse.unquote(traverse_obj(qs, ('url', 0)) or '')
105 if src and YoutubeTabIE.suitable(src):
106 return self.url_result(src, YoutubeTabIE)
107 return self.url_result(smuggle_url(
108 urllib.parse.unquote(traverse_obj(qs, ('src', 0), ('url', 0))),
109 {'http_headers': {'Referer': url}}))