myvideoge.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. MONTH_NAMES,
  5. clean_html,
  6. get_element_by_class,
  7. get_element_by_id,
  8. int_or_none,
  9. js_to_json,
  10. qualities,
  11. unified_strdate,
  12. )
  13. class MyVideoGeIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?myvideo\.ge/v/(?P<id>[0-9]+)'
  15. _TEST = {
  16. 'url': 'https://www.myvideo.ge/v/3941048',
  17. 'md5': '8c192a7d2b15454ba4f29dc9c9a52ea9',
  18. 'info_dict': {
  19. 'id': '3941048',
  20. 'ext': 'mp4',
  21. 'title': 'The best prikol',
  22. 'upload_date': '20200611',
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. 'uploader': 'chixa33',
  25. 'description': 'md5:5b067801318e33c2e6eea4ab90b1fdd3',
  26. },
  27. }
  28. _MONTH_NAMES_KA = ['იანვარი', 'თებერვალი', 'მარტი', 'აპრილი', 'მაისი', 'ივნისი', 'ივლისი', 'აგვისტო', 'სექტემბერი', 'ოქტომბერი', 'ნოემბერი', 'დეკემბერი']
  29. _quality = staticmethod(qualities(('SD', 'HD')))
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. title = (
  34. self._og_search_title(webpage, default=None)
  35. or clean_html(get_element_by_class('my_video_title', webpage))
  36. or self._html_search_regex(r'<title\b[^>]*>([^<]+)</title\b', webpage, 'title'))
  37. jwplayer_sources = self._parse_json(
  38. self._search_regex(
  39. r'''(?s)jwplayer\s*\(\s*['"]mvplayer['"]\s*\)\s*\.\s*setup\s*\(.*?\bsources\s*:\s*(\[.*?])\s*[,});]''', webpage, 'jwplayer sources', fatal=False)
  40. or '',
  41. video_id, transform_source=js_to_json, fatal=False)
  42. formats = self._parse_jwplayer_formats(jwplayer_sources or [], video_id)
  43. for f in formats or []:
  44. f['quality'] = self._quality(f['format_id'])
  45. description = (
  46. self._og_search_description(webpage)
  47. or get_element_by_id('long_desc_holder', webpage)
  48. or self._html_search_meta('description', webpage))
  49. uploader = self._search_regex(r'<a[^>]+class="mv_user_name"[^>]*>([^<]+)<', webpage, 'uploader', fatal=False)
  50. upload_date = get_element_by_class('mv_vid_upl_date', webpage)
  51. # as ka locale may not be present roll a local date conversion
  52. upload_date = (unified_strdate(
  53. # translate any ka month to an en one
  54. re.sub('|'.join(self._MONTH_NAMES_KA),
  55. lambda m: MONTH_NAMES['en'][self._MONTH_NAMES_KA.index(m.group(0))],
  56. upload_date, flags=re.I))
  57. if upload_date else None)
  58. return {
  59. 'id': video_id,
  60. 'title': title,
  61. 'description': description,
  62. 'uploader': uploader,
  63. 'formats': formats,
  64. 'thumbnail': self._og_search_thumbnail(webpage),
  65. 'upload_date': upload_date,
  66. 'view_count': int_or_none(get_element_by_class('mv_vid_views', webpage)),
  67. 'like_count': int_or_none(get_element_by_id('likes_count', webpage)),
  68. 'dislike_count': int_or_none(get_element_by_id('dislikes_count', webpage)),
  69. }