pearvideo.py 2.4 KB

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