embedly.py 5.2 KB

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