vbox7.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from .common import InfoExtractor
  2. from ..utils import ExtractorError, base_url, int_or_none, url_basename
  3. from ..utils.traversal import traverse_obj
  4. class Vbox7IE(InfoExtractor):
  5. _VALID_URL = r'''(?x)
  6. https?://
  7. (?:[^/]+\.)?vbox7\.com/
  8. (?:
  9. play:|
  10. (?:
  11. emb/external\.php|
  12. player/ext\.swf
  13. )\?.*?\bvid=
  14. )
  15. (?P<id>[\da-fA-F]+)
  16. '''
  17. _EMBED_REGEX = [r'<iframe[^>]+src=(?P<q>["\'])(?P<url>(?:https?:)?//vbox7\.com/emb/external\.php.+?)(?P=q)']
  18. _GEO_COUNTRIES = ['BG']
  19. _TESTS = [{
  20. 'url': 'http://vbox7.com/play:0946fff23c',
  21. 'md5': '50ca1f78345a9c15391af47d8062d074',
  22. 'info_dict': {
  23. 'id': '0946fff23c',
  24. 'ext': 'mp4',
  25. 'title': 'Борисов: Притеснен съм за бъдещето на България',
  26. 'description': 'По думите му е опасно страната ни да бъде обявена за "сигурна"',
  27. 'thumbnail': r're:^https?://.*\.jpg$',
  28. 'timestamp': 1470982814,
  29. 'upload_date': '20160812',
  30. 'uploader': 'zdraveibulgaria',
  31. 'view_count': int,
  32. 'duration': 2640,
  33. },
  34. }, {
  35. 'url': 'http://vbox7.com/play:249bb972c2',
  36. 'md5': 'da1dd2eb245200cb86e6d09d43232116',
  37. 'info_dict': {
  38. 'id': '249bb972c2',
  39. 'ext': 'mp4',
  40. 'title': 'Смях! Чудо - чист за секунди - Скрита камера',
  41. 'uploader': 'svideteliat_ot_varshava',
  42. 'view_count': int,
  43. 'timestamp': 1360215023,
  44. 'thumbnail': 'https://i49.vbox7.com/o/249/249bb972c20.jpg',
  45. 'description': 'Смях! Чудо - чист за секунди - Скрита камера',
  46. 'upload_date': '20130207',
  47. 'duration': 83,
  48. },
  49. 'expected_warnings': ['Failed to download m3u8 information'],
  50. }, {
  51. 'url': 'http://vbox7.com/emb/external.php?vid=a240d20f9c&autoplay=1',
  52. 'only_matching': True,
  53. }, {
  54. 'url': 'http://i49.vbox7.com/player/ext.swf?vid=0946fff23c&autoplay=1',
  55. 'only_matching': True,
  56. }]
  57. def _real_extract(self, url):
  58. video_id = self._match_id(url)
  59. data = self._download_json(
  60. 'https://www.vbox7.com/aj/player/item/options', video_id,
  61. query={'vid': video_id})['options']
  62. src_url = data.get('src')
  63. if src_url in (None, '', 'blank'):
  64. raise ExtractorError('Video is unavailable', expected=True)
  65. fmt_base = url_basename(src_url).rsplit('.', 1)[0].rsplit('_', 1)[0]
  66. if fmt_base == 'vn':
  67. self.raise_geo_restricted()
  68. fmt_base = base_url(src_url) + fmt_base
  69. formats = self._extract_m3u8_formats(
  70. f'{fmt_base}.m3u8', video_id, m3u8_id='hls', fatal=False)
  71. # TODO: Add MPD formats, when dash range support is added
  72. for res in traverse_obj(data, ('resolutions', lambda _, v: v != 0, {int})):
  73. formats.append({
  74. 'url': f'{fmt_base}_{res}.mp4',
  75. 'format_id': f'http-{res}',
  76. 'height': res,
  77. })
  78. return {
  79. 'id': video_id,
  80. 'formats': formats,
  81. **self._search_json_ld(self._download_webpage(
  82. f'https://www.vbox7.com/play:{video_id}', video_id, fatal=False) or '', video_id, fatal=False),
  83. **traverse_obj(data, {
  84. 'title': ('title', {str}),
  85. 'uploader': ('uploader', {str}),
  86. 'duration': ('duration', {int_or_none}),
  87. }),
  88. }