You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class VidioIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)'
  8. _TESTS = [{
  9. 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015',
  10. 'md5': 'cd2801394afc164e9775db6a140b91fe',
  11. 'info_dict': {
  12. 'id': '165683',
  13. 'display_id': 'dj_ambred-booyah-live-2015',
  14. 'ext': 'mp4',
  15. 'title': 'DJ_AMBRED - Booyah (Live 2015)',
  16. 'description': 'md5:27dc15f819b6a78a626490881adbadf8',
  17. 'thumbnail': r're:^https?://.*\.jpg$',
  18. 'duration': 149,
  19. 'like_count': int,
  20. },
  21. }, {
  22. 'url': 'https://www.vidio.com/watch/77949-south-korea-test-fires-missile-that-can-strike-all-of-the-north',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id, display_id = mobj.group('id', 'display_id')
  28. webpage = self._download_webpage(url, display_id)
  29. title = self._og_search_title(webpage)
  30. m3u8_url, duration, thumbnail = [None] * 3
  31. clips = self._parse_json(
  32. self._html_search_regex(
  33. r'data-json-clips\s*=\s*(["\'])(?P<data>\[.+?\])\1',
  34. webpage, 'video data', default='[]', group='data'),
  35. display_id, fatal=False)
  36. if clips:
  37. clip = clips[0]
  38. m3u8_url = clip.get('sources', [{}])[0].get('file')
  39. duration = clip.get('clip_duration')
  40. thumbnail = clip.get('image')
  41. m3u8_url = m3u8_url or self._search_regex(
  42. r'data(?:-vjs)?-clip-hls-url=(["\'])(?P<url>(?!\1).+)\1',
  43. webpage, 'hls url')
  44. formats = self._extract_m3u8_formats(
  45. m3u8_url, display_id, 'mp4', entry_protocol='m3u8_native')
  46. self._sort_formats(formats)
  47. duration = int_or_none(duration or self._search_regex(
  48. r'data-video-duration=(["\'])(?P<duration>\d+)\1', webpage,
  49. 'duration', fatal=False, group='duration'))
  50. thumbnail = thumbnail or self._og_search_thumbnail(webpage)
  51. like_count = int_or_none(self._search_regex(
  52. (r'<span[^>]+data-comment-vote-count=["\'](\d+)',
  53. r'<span[^>]+class=["\'].*?\blike(?:__|-)count\b.*?["\'][^>]*>\s*(\d+)'),
  54. webpage, 'like count', fatal=False))
  55. return {
  56. 'id': video_id,
  57. 'display_id': display_id,
  58. 'title': title,
  59. 'description': self._og_search_description(webpage),
  60. 'thumbnail': thumbnail,
  61. 'duration': duration,
  62. 'like_count': like_count,
  63. 'formats': formats,
  64. }