myvideoge.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from .common import InfoExtractor
  2. from ..utils import js_to_json
  3. class MyVideoGeIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?myvideo\.ge/v/(?P<id>[0-9]+)'
  5. _TEST = {
  6. 'url': 'https://www.myvideo.ge/v/3941048',
  7. 'md5': '8c192a7d2b15454ba4f29dc9c9a52ea9',
  8. 'info_dict': {
  9. 'id': '3941048',
  10. 'ext': 'mp4',
  11. 'title': 'The best prikol',
  12. 'thumbnail': r're:^https?://.*\.jpg$',
  13. 'uploader': 'md5:d72addd357b0dd914e704781f7f777d8',
  14. 'description': 'md5:5c0371f540f5888d603ebfedd46b6df3'
  15. }
  16. }
  17. def _real_extract(self, url):
  18. video_id = self._match_id(url)
  19. webpage = self._download_webpage(url, video_id)
  20. title = self._html_search_regex(r'<h1[^>]*>([^<]+)</h1>', webpage, 'title')
  21. description = self._og_search_description(webpage)
  22. thumbnail = self._html_search_meta(['og:image'], webpage)
  23. uploader = self._search_regex(r'<a[^>]+class="mv_user_name"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False)
  24. jwplayer_sources = self._parse_json(
  25. self._search_regex(
  26. r"(?s)jwplayer\(\"mvplayer\"\).setup\(.*?sources: (.*?])", webpage, 'jwplayer sources'),
  27. video_id, transform_source=js_to_json)
  28. def _formats_key(f):
  29. if f['label'] == 'SD':
  30. return -1
  31. elif f['label'] == 'HD':
  32. return 1
  33. else:
  34. return 0
  35. jwplayer_sources = sorted(jwplayer_sources, key=_formats_key)
  36. formats = self._parse_jwplayer_formats(jwplayer_sources, video_id)
  37. return {
  38. 'id': video_id,
  39. 'title': title,
  40. 'description': description,
  41. 'uploader': uploader,
  42. 'formats': formats,
  43. 'thumbnail': thumbnail
  44. }