drtuber.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. NO_DEFAULT,
  6. str_to_int,
  7. )
  8. class DrTuberIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?drtuber\.com/video/(?P<id>\d+)/(?P<display_id>[\w-]+)'
  10. _TEST = {
  11. 'url': 'http://www.drtuber.com/video/1740434/hot-perky-blonde-naked-golf',
  12. 'md5': '93e680cf2536ad0dfb7e74d94a89facd',
  13. 'info_dict': {
  14. 'id': '1740434',
  15. 'display_id': 'hot-perky-blonde-naked-golf',
  16. 'ext': 'mp4',
  17. 'title': 'hot perky blonde naked golf',
  18. 'like_count': int,
  19. 'comment_count': int,
  20. 'categories': ['Babe', 'Blonde', 'Erotic', 'Outdoor', 'Softcore', 'Solo'],
  21. 'thumbnail': 're:https?://.*\.jpg$',
  22. 'age_limit': 18,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. display_id = mobj.group('display_id')
  29. webpage = self._download_webpage(url, display_id)
  30. video_url = self._html_search_regex(
  31. r'<source src="([^"]+)"', webpage, 'video URL')
  32. title = self._html_search_regex(
  33. [r'<p[^>]+class="title_substrate">([^<]+)</p>', r'<title>([^<]+) - \d+'],
  34. webpage, 'title')
  35. thumbnail = self._html_search_regex(
  36. r'poster="([^"]+)"',
  37. webpage, 'thumbnail', fatal=False)
  38. def extract_count(id_, name, default=NO_DEFAULT):
  39. return str_to_int(self._html_search_regex(
  40. r'<span[^>]+(?:class|id)="%s"[^>]*>([\d,\.]+)</span>' % id_,
  41. webpage, '%s count' % name, default=default, fatal=False))
  42. like_count = extract_count('rate_likes', 'like')
  43. dislike_count = extract_count('rate_dislikes', 'dislike', default=None)
  44. comment_count = extract_count('comments_count', 'comment')
  45. cats_str = self._search_regex(
  46. r'<div[^>]+class="categories_list">(.+?)</div>',
  47. webpage, 'categories', fatal=False)
  48. categories = [] if not cats_str else re.findall(
  49. r'<a title="([^"]+)"', cats_str)
  50. return {
  51. 'id': video_id,
  52. 'display_id': display_id,
  53. 'url': video_url,
  54. 'title': title,
  55. 'thumbnail': thumbnail,
  56. 'like_count': like_count,
  57. 'dislike_count': dislike_count,
  58. 'comment_count': comment_count,
  59. 'categories': categories,
  60. 'age_limit': self._rta_search(webpage),
  61. }