yapfiles.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. int_or_none,
  5. qualities,
  6. url_or_none,
  7. )
  8. class YapFilesIE(InfoExtractor):
  9. _WORKING = False
  10. _YAPFILES_URL = r'//(?:(?:www|api)\.)?yapfiles\.ru/get_player/*\?.*?\bv=(?P<id>\w+)'
  11. _VALID_URL = rf'https?:{_YAPFILES_URL}'
  12. _EMBED_REGEX = [rf'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?{_YAPFILES_URL}.*?)\1']
  13. _TESTS = [{
  14. # with hd
  15. 'url': 'http://www.yapfiles.ru/get_player/?v=vMDE1NjcyNDUt0413',
  16. 'md5': '2db19e2bfa2450568868548a1aa1956c',
  17. 'info_dict': {
  18. 'id': 'vMDE1NjcyNDUt0413',
  19. 'ext': 'mp4',
  20. 'title': 'Самый худший пароль WIFI',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'duration': 72,
  23. },
  24. }, {
  25. # without hd
  26. 'url': 'https://api.yapfiles.ru/get_player/?uid=video_player_1872528&plroll=1&adv=1&v=vMDE4NzI1Mjgt690b',
  27. 'only_matching': True,
  28. }]
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id, fatal=False)
  32. player_url = None
  33. query = {}
  34. if webpage:
  35. player_url = self._search_regex(
  36. r'player\.init\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  37. 'player url', default=None, group='url')
  38. if not player_url:
  39. player_url = f'http://api.yapfiles.ru/load/{video_id}/'
  40. query = {
  41. 'md5': 'ded5f369be61b8ae5f88e2eeb2f3caff',
  42. 'type': 'json',
  43. 'ref': url,
  44. }
  45. player = self._download_json(
  46. player_url, video_id, query=query)['player']
  47. playlist_url = player['playlist']
  48. title = player['title']
  49. thumbnail = player.get('poster')
  50. if title == 'Ролик удален' or 'deleted.jpg' in (thumbnail or ''):
  51. raise ExtractorError(
  52. f'Video {video_id} has been removed', expected=True)
  53. playlist = self._download_json(
  54. playlist_url, video_id)['player']['main']
  55. hd_height = int_or_none(player.get('hd'))
  56. QUALITIES = ('sd', 'hd')
  57. quality_key = qualities(QUALITIES)
  58. formats = []
  59. for format_id in QUALITIES:
  60. is_hd = format_id == 'hd'
  61. format_url = url_or_none(playlist.get(
  62. 'file%s' % ('_hd' if is_hd else '')))
  63. if not format_url:
  64. continue
  65. formats.append({
  66. 'url': format_url,
  67. 'format_id': format_id,
  68. 'quality': quality_key(format_id),
  69. 'height': hd_height if is_hd else None,
  70. })
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'thumbnail': thumbnail,
  75. 'duration': int_or_none(player.get('length')),
  76. 'formats': formats,
  77. }