vidly.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. mimetype2ext,
  5. url_or_none,
  6. )
  7. from ..utils.traversal import traverse_obj
  8. class VidlyIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:vid\.ly/|(?:s\.)?vid\.ly/embeded\.html\?(?:[^#]+&)?link=)(?P<id>\w+)'
  10. _EMBED_REGEX = [r'<script[^>]+\bsrc=[\'"](?P<url>(?:https?:)?//vid\.ly/\w+/embed[^\'"]+)',
  11. r'<iframe[^>]+\bsrc=[\'"](?P<url>(?:https?:)?//(?:s\.)?vid\.ly/embeded\.html\?(?:[^#\'"]+&)?link=\w+[^\'"]+)']
  12. _TESTS = [{
  13. # JWPlayer 7, Embeds forbidden
  14. 'url': 'https://vid.ly/2i3o9j/embed',
  15. 'info_dict': {
  16. 'id': '2i3o9j',
  17. 'ext': 'mp4',
  18. 'title': '2i3o9j',
  19. 'thumbnail': r're:https://\w+\.cloudfront\.net/',
  20. },
  21. }, {
  22. # JWPlayer 6
  23. 'url': 'http://s.vid.ly/embeded.html?link=jw_test&new=1&autoplay=true&controls=true',
  24. 'info_dict': {
  25. 'id': 'jw_test',
  26. 'ext': 'mp4',
  27. 'title': '2x8m8t',
  28. 'thumbnail': r're:https://\w+\.cloudfront\.net/',
  29. },
  30. }, {
  31. # Vidlyplayer
  32. 'url': 'https://vid.ly/7x0e6l',
  33. 'info_dict': {
  34. 'id': '7x0e6l',
  35. 'ext': 'mp4',
  36. 'title': '7x0e6l',
  37. },
  38. }]
  39. _WEBPAGE_TESTS = [{
  40. 'url': 'https://www.petfinder.com/dog/gus-57378930/tn/ooltewah/furever-furkids-rescue-tn592/',
  41. 'info_dict': {
  42. 'id': 'w8p5b0',
  43. 'ext': 'mp4',
  44. 'title': 'w8p5b0',
  45. 'thumbnail': r're:https://\w+\.cloudfront\.net/',
  46. },
  47. }]
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. embed_script = self._download_webpage(
  51. f'https://vid.ly/{video_id}/embed', video_id, headers={'Referer': 'https://vid.ly/'})
  52. player = self._search_json(r'initCallback\(', embed_script, 'player', video_id)
  53. player_type = player.get('player') or ''
  54. if player_type.startswith('jwplayer'):
  55. return self._parse_jwplayer_data(player['config'], video_id)
  56. elif not player_type.startswith('vidly'):
  57. raise ExtractorError(f'Unknown player type {player_type!r}')
  58. formats = []
  59. ext = mimetype2ext(traverse_obj(player, ('config', 'type')))
  60. for source, fid in [('source', 'sd'), ('source_hd', 'hd')]:
  61. if traverse_obj(player, ('config', source, {url_or_none})):
  62. formats.append({
  63. 'url': player['config'][source],
  64. 'format_id': f'http-{fid}',
  65. 'ext': ext,
  66. })
  67. # Has higher quality formats
  68. formats.extend(self._extract_m3u8_formats(
  69. f'https://d3fenhwk93s16g.cloudfront.net/{video_id}/hls.m3u8', video_id,
  70. fatal=False, note='Requesting higher quality m3u8 formats',
  71. errnote='No higher quality m3u8 formats found') or [])
  72. return {
  73. 'id': video_id,
  74. 'title': video_id,
  75. 'formats': formats,
  76. }