logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

pearvideo.py (2103B)


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