[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / pearvideo.py
blob4bea04bf2be5e776aa574e36124a4ab344a7b522
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 qualities,
6 traverse_obj,
7 unified_timestamp,
11 class PearVideoIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?pearvideo\.com/video_(?P<id>\d+)'
13 _TEST = {
14 'url': 'http://www.pearvideo.com/video_1076290',
15 'info_dict': {
16 'id': '1076290',
17 'ext': 'mp4',
18 'title': '小浣熊在主人家玻璃上滚石头:没砸',
19 'description': 'md5:01d576b747de71be0ee85eb7cac25f9d',
20 'timestamp': 1494275280,
21 'upload_date': '20170508',
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id)
30 quality = qualities(
31 ('ldflv', 'ld', 'sdflv', 'sd', 'hdflv', 'hd', 'src'))
33 formats = [{
34 'url': mobj.group('url'),
35 'format_id': mobj.group('id'),
36 'quality': quality(mobj.group('id')),
37 } for mobj in re.finditer(
38 r'(?P<id>[a-zA-Z]+)Url\s*=\s*(["\'])(?P<url>(?:https?:)?//.+?)\2',
39 webpage)]
40 if not formats:
41 info = self._download_json(
42 'https://www.pearvideo.com/videoStatus.jsp', video_id=video_id,
43 query={'contId': video_id}, headers={'Referer': url})
44 formats = [{
45 'format_id': k,
46 'url': v.replace(info['systemTime'], f'cont-{video_id}') if k == 'srcUrl' else v,
47 } for k, v in traverse_obj(info, ('videoInfo', 'videos'), default={}).items() if v]
49 title = self._search_regex(
50 (r'<h1[^>]+\bclass=(["\'])video-tt\1[^>]*>(?P<value>[^<]+)',
51 r'<[^>]+\bdata-title=(["\'])(?P<value>(?:(?!\1).)+)\1'),
52 webpage, 'title', group='value')
53 description = self._search_regex(
54 (r'<div[^>]+\bclass=(["\'])summary\1[^>]*>(?P<value>[^<]+)',
55 r'<[^>]+\bdata-summary=(["\'])(?P<value>(?:(?!\1).)+)\1'),
56 webpage, 'description', default=None,
57 group='value') or self._html_search_meta('Description', webpage)
58 timestamp = unified_timestamp(self._search_regex(
59 r'<div[^>]+\bclass=["\']date["\'][^>]*>([^<]+)',
60 webpage, 'timestamp', fatal=False))
62 return {
63 'id': video_id,
64 'title': title,
65 'description': description,
66 'timestamp': timestamp,
67 'formats': formats,