sunporno.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. determine_ext,
  5. int_or_none,
  6. parse_duration,
  7. qualities,
  8. )
  9. class SunPornoIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:(?:www\.)?sunporno\.com/videos|embeds\.sunporno\.com/embed)/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'http://www.sunporno.com/videos/807778/',
  13. 'md5': '507887e29033502f29dba69affeebfc9',
  14. 'info_dict': {
  15. 'id': '807778',
  16. 'ext': 'mp4',
  17. 'title': 'md5:0a400058e8105d39e35c35e7c5184164',
  18. 'description': 'md5:a31241990e1bd3a64e72ae99afb325fb',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. 'duration': 302,
  21. 'age_limit': 18,
  22. },
  23. }, {
  24. 'url': 'http://embeds.sunporno.com/embed/807778',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(
  30. f'http://www.sunporno.com/videos/{video_id}', video_id)
  31. title = self._html_extract_title(webpage)
  32. description = self._html_search_meta(
  33. 'description', webpage, 'description')
  34. thumbnail = self._html_search_regex(
  35. r'poster="([^"]+)"', webpage, 'thumbnail', fatal=False)
  36. duration = parse_duration(self._search_regex(
  37. (r'itemprop="duration"[^>]*>\s*(\d+:\d+)\s*<',
  38. r'>Duration:\s*<span[^>]+>\s*(\d+:\d+)\s*<'),
  39. webpage, 'duration', fatal=False))
  40. view_count = int_or_none(self._html_search_regex(
  41. r'class="views">(?:<noscript>)?\s*(\d+)\s*<',
  42. webpage, 'view count', fatal=False))
  43. comment_count = int_or_none(self._html_search_regex(
  44. r'(\d+)</b> Comments?',
  45. webpage, 'comment count', fatal=False, default=None))
  46. formats = []
  47. quality = qualities(['mp4', 'flv'])
  48. for video_url in re.findall(r'<(?:source|video) src="([^"]+)"', webpage):
  49. video_ext = determine_ext(video_url)
  50. formats.append({
  51. 'url': video_url,
  52. 'format_id': video_ext,
  53. 'quality': quality(video_ext),
  54. })
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'description': description,
  59. 'thumbnail': thumbnail,
  60. 'duration': duration,
  61. 'view_count': view_count,
  62. 'comment_count': comment_count,
  63. 'formats': formats,
  64. 'age_limit': 18,
  65. }