rule34video.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import re
  2. from ..utils import parse_duration
  3. from .common import InfoExtractor
  4. class Rule34VideoIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?rule34video\.com/videos/(?P<id>\d+)'
  6. _TESTS = [
  7. {
  8. 'url': 'https://rule34video.com/videos/3065157/shot-it-mmd-hmv/',
  9. 'md5': 'ffccac2c23799dabbd192621ae4d04f3',
  10. 'info_dict': {
  11. 'id': '3065157',
  12. 'ext': 'mp4',
  13. 'title': 'Shot It-(mmd hmv)',
  14. 'thumbnail': 'https://rule34video.com/contents/videos_screenshots/3065000/3065157/preview.jpg',
  15. 'duration': 347.0,
  16. 'age_limit': 18
  17. }
  18. },
  19. {
  20. 'url': 'https://rule34video.com/videos/3065296/lara-in-trouble-ep-7-wildeerstudio/',
  21. 'md5': '6bb5169f9f6b38cd70882bf2e64f6b86',
  22. 'info_dict': {
  23. 'id': '3065296',
  24. 'ext': 'mp4',
  25. 'title': 'Lara in Trouble Ep. 7 [WildeerStudio]',
  26. 'thumbnail': 'https://rule34video.com/contents/videos_screenshots/3065000/3065296/preview.jpg',
  27. 'duration': 938.0,
  28. 'age_limit': 18
  29. }
  30. },
  31. ]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. formats = []
  36. for mobj in re.finditer(r'<a[^>]+href="(?P<video_url>[^"]+download=true[^"]+)".*>(?P<ext>[^\s]+) (?P<quality>[^<]+)p</a>', webpage):
  37. url, ext, quality = mobj.groups()
  38. formats.append({
  39. 'url': url,
  40. 'ext': ext.lower(),
  41. 'quality': quality,
  42. })
  43. title = self._html_extract_title(webpage)
  44. thumbnail = self._html_search_regex(r'preview_url:\s+\'([^\']+)\'', webpage, 'thumbnail', default=None)
  45. duration = self._html_search_regex(r'"icon-clock"></i>\s+<span>((?:\d+:?)+)', webpage, 'duration', default=None)
  46. return {
  47. 'id': video_id,
  48. 'formats': formats,
  49. 'title': title,
  50. 'thumbnail': thumbnail,
  51. 'duration': parse_duration(duration),
  52. 'age_limit': 18
  53. }