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.

73 lines
2.7 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': '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', webpage, 'hls url')
  43. formats = self._extract_m3u8_formats(m3u8_url, display_id, 'mp4', entry_protocol='m3u8_native')
  44. duration = int_or_none(duration or self._search_regex(
  45. r'data-video-duration=(["\'])(?P<duartion>\d+)\1', webpage, 'duration'))
  46. thumbnail = thumbnail or self._og_search_thumbnail(webpage)
  47. like_count = int_or_none(self._search_regex(
  48. (r'<span[^>]+data-comment-vote-count=["\'](\d+)',
  49. r'<span[^>]+class=["\'].*?\blike(?:__|-)count\b.*?["\'][^>]*>\s*(\d+)'),
  50. webpage, 'like count', fatal=False))
  51. return {
  52. 'id': video_id,
  53. 'display_id': display_id,
  54. 'title': title,
  55. 'description': self._og_search_description(webpage),
  56. 'thumbnail': thumbnail,
  57. 'duration': duration,
  58. 'like_count': like_count,
  59. 'formats': formats,
  60. }