]>
Commit | Line | Data |
---|---|---|
bfd973ec | 1 | import re |
2 | import urllib.parse | |
78d25e0b | 3 | |
6b961a85 | 4 | from .common import InfoExtractor |
78d25e0b | 5 | from .youtube import YoutubeTabIE |
6 | from ..utils import parse_qs, smuggle_url, traverse_obj | |
6b961a85 PH |
7 | |
8 | ||
9 | class EmbedlyIE(InfoExtractor): | |
78d25e0b | 10 | _VALID_URL = r'https?://(?:www|cdn\.)?embedly\.com/widgets/media\.html\?(?:[^#]*?&)?(?:src|url)=(?:[^#&]+)' |
6b961a85 PH |
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', | |
78d25e0b | 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', | |
6b961a85 PH |
61 | 'only_matching': True, |
62 | }] | |
63 | ||
bfd973ec | 64 | @classmethod |
87ebab06 | 65 | def _extract_from_webpage(cls, url, webpage): |
66 | # Bypass "ie=cls" and suitable check | |
bfd973ec | 67 | for mobj in re.finditer(r'class=["\']embedly-card["\'][^>]href=["\'](?P<url>[^"\']+)', webpage): |
87ebab06 | 68 | yield cls.url_result(mobj.group('url')) |
bfd973ec | 69 | |
70 | for mobj in re.finditer(r'class=["\']embedly-embed["\'][^>]src=["\'][^"\']*url=(?P<url>[^&]+)', webpage): | |
87ebab06 | 71 | yield cls.url_result(urllib.parse.unquote(mobj.group('url'))) |
bfd973ec | 72 | |
6b961a85 | 73 | def _real_extract(self, url): |
78d25e0b | 74 | qs = parse_qs(url) |
75 | src = urllib.parse.unquote(traverse_obj(qs, ('url', 0)) or '') | |
76 | if src and YoutubeTabIE.suitable(src): | |
77 | return self.url_result(src, YoutubeTabIE) | |
78 | return self.url_result(smuggle_url( | |
79 | urllib.parse.unquote(traverse_obj(qs, ('src', 0), ('url', 0))), | |
80 | {'http_headers': {'Referer': url}})) |