logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

vidio.py (3285B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. str_or_none,
  9. strip_or_none,
  10. try_get,
  11. )
  12. class VidioIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?vidio\.com/watch/(?P<id>\d+)-(?P<display_id>[^/?#&]+)'
  14. _TESTS = [{
  15. 'url': 'http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015',
  16. 'md5': 'cd2801394afc164e9775db6a140b91fe',
  17. 'info_dict': {
  18. 'id': '165683',
  19. 'display_id': 'dj_ambred-booyah-live-2015',
  20. 'ext': 'mp4',
  21. 'title': 'DJ_AMBRED - Booyah (Live 2015)',
  22. 'description': 'md5:27dc15f819b6a78a626490881adbadf8',
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. 'duration': 149,
  25. 'like_count': int,
  26. 'uploader': 'TWELVE Pic',
  27. 'timestamp': 1444902800,
  28. 'upload_date': '20151015',
  29. 'uploader_id': 'twelvepictures',
  30. 'channel': 'Cover Music Video',
  31. 'channel_id': '280236',
  32. 'view_count': int,
  33. 'dislike_count': int,
  34. 'comment_count': int,
  35. 'tags': 'count:4',
  36. },
  37. }, {
  38. 'url': 'https://www.vidio.com/watch/77949-south-korea-test-fires-missile-that-can-strike-all-of-the-north',
  39. 'only_matching': True,
  40. }]
  41. def _real_initialize(self):
  42. self._api_key = self._download_json(
  43. 'https://www.vidio.com/auth', None, data=b'')['api_key']
  44. def _real_extract(self, url):
  45. video_id, display_id = re.match(self._VALID_URL, url).groups()
  46. data = self._download_json(
  47. 'https://api.vidio.com/videos/' + video_id, display_id, headers={
  48. 'Content-Type': 'application/vnd.api+json',
  49. 'X-API-KEY': self._api_key,
  50. })
  51. video = data['videos'][0]
  52. title = video['title'].strip()
  53. formats = self._extract_m3u8_formats(
  54. data['clips'][0]['hls_url'], display_id, 'mp4', 'm3u8_native')
  55. self._sort_formats(formats)
  56. get_first = lambda x: try_get(data, lambda y: y[x + 's'][0], dict) or {}
  57. channel = get_first('channel')
  58. user = get_first('user')
  59. username = user.get('username')
  60. get_count = lambda x: int_or_none(video.get('total_' + x))
  61. return {
  62. 'id': video_id,
  63. 'display_id': display_id,
  64. 'title': title,
  65. 'description': strip_or_none(video.get('description')),
  66. 'thumbnail': video.get('image_url_medium'),
  67. 'duration': int_or_none(video.get('duration')),
  68. 'like_count': get_count('likes'),
  69. 'formats': formats,
  70. 'uploader': user.get('name'),
  71. 'timestamp': parse_iso8601(video.get('created_at')),
  72. 'uploader_id': username,
  73. 'uploader_url': 'https://www.vidio.com/@' + username if username else None,
  74. 'channel': channel.get('name'),
  75. 'channel_id': str_or_none(channel.get('id')),
  76. 'view_count': get_count('view_count'),
  77. 'dislike_count': get_count('dislikes'),
  78. 'comment_count': get_count('comments'),
  79. 'tags': video.get('tag_list'),
  80. }