]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/meipai.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / meipai.py
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 parse_duration,
5 unified_timestamp,
6 )
7
8
9 class MeipaiIE(InfoExtractor):
10 IE_DESC = '美拍'
11 _VALID_URL = r'https?://(?:www\.)?meipai\.com/media/(?P<id>[0-9]+)'
12 _TESTS = [{
13 # regular uploaded video
14 'url': 'http://www.meipai.com/media/531697625',
15 'md5': 'e3e9600f9e55a302daecc90825854b4f',
16 'info_dict': {
17 'id': '531697625',
18 'ext': 'mp4',
19 'title': '#葉子##阿桑##余姿昀##超級女聲#',
20 'description': '#葉子##阿桑##余姿昀##超級女聲#',
21 'thumbnail': r're:^https?://.*\.jpg$',
22 'duration': 152,
23 'timestamp': 1465492420,
24 'upload_date': '20160609',
25 'view_count': 35511,
26 'creator': '她她-TATA',
27 'tags': ['葉子', '阿桑', '余姿昀', '超級女聲'],
28 }
29 }, {
30 # record of live streaming
31 'url': 'http://www.meipai.com/media/585526361',
32 'md5': 'ff7d6afdbc6143342408223d4f5fb99a',
33 'info_dict': {
34 'id': '585526361',
35 'ext': 'mp4',
36 'title': '姿昀和善願 練歌練琴啦😁😁😁',
37 'description': '姿昀和善願 練歌練琴啦😁😁😁',
38 'thumbnail': r're:^https?://.*\.jpg$',
39 'duration': 5975,
40 'timestamp': 1474311799,
41 'upload_date': '20160919',
42 'view_count': 1215,
43 'creator': '她她-TATA',
44 }
45 }]
46
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
49 webpage = self._download_webpage(url, video_id)
50
51 title = self._generic_title('', webpage)
52
53 formats = []
54
55 # recorded playback of live streaming
56 m3u8_url = self._html_search_regex(
57 r'file:\s*encodeURIComponent\((["\'])(?P<url>(?:(?!\1).)+)\1\)',
58 webpage, 'm3u8 url', group='url', default=None)
59 if m3u8_url:
60 formats.extend(self._extract_m3u8_formats(
61 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
62 m3u8_id='hls', fatal=False))
63
64 if not formats:
65 # regular uploaded video
66 video_url = self._search_regex(
67 r'data-video=(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'video url',
68 group='url', default=None)
69 if video_url:
70 formats.append({
71 'url': video_url,
72 'format_id': 'http',
73 })
74
75 timestamp = unified_timestamp(self._og_search_property(
76 'video:release_date', webpage, 'release date', fatal=False))
77
78 tags = self._og_search_property(
79 'video:tag', webpage, 'tags', default='').split(',')
80
81 view_count = int_or_none(self._html_search_meta(
82 'interactionCount', webpage, 'view count'))
83 duration = parse_duration(self._html_search_meta(
84 'duration', webpage, 'duration'))
85 creator = self._og_search_property(
86 'video:director', webpage, 'creator', fatal=False)
87
88 return {
89 'id': video_id,
90 'title': title,
91 'description': self._og_search_description(webpage),
92 'thumbnail': self._og_search_thumbnail(webpage),
93 'duration': duration,
94 'timestamp': timestamp,
95 'view_count': view_count,
96 'creator': creator,
97 'tags': tags,
98 'formats': formats,
99 }