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