moviefap.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. xpath_text,
  6. str_to_int
  7. )
  8. from ..compat import compat_str
  9. class MovieFapIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<name>[a-z-_]+)'
  11. _TESTS = [{
  12. # normal, multi-format video
  13. 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
  14. 'md5': '26624b4e2523051b550067d547615906',
  15. 'info_dict': {
  16. 'id': 'be9867c9416c19f54a4a',
  17. 'ext': 'mp4',
  18. 'title': 'Experienced MILF Amazing Handjob',
  19. 'description': 'Experienced MILF giving an Amazing Handjob',
  20. 'thumbnail': 'http://img.moviefap.com/a16:9w990r/thumbs/be/322032-20l.jpg',
  21. 'uploader_id': 'darvinfred06',
  22. 'display_id': 'experienced-milf-amazing-handjob',
  23. 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing']
  24. }
  25. }, {
  26. # quirky single-format case where the extension is given as fid, but the video is really an flv
  27. 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
  28. 'md5': 'fa56683e291fc80635907168a743c9ad',
  29. 'info_dict': {
  30. 'id': 'e5da0d3edce5404418f5',
  31. 'ext': 'flv',
  32. 'title': 'Jeune Couple Russe',
  33. 'description': 'Amateur',
  34. 'thumbnail': 'http://pic.moviefap.com/thumbs/e5/949-18l.jpg',
  35. 'uploader_id': 'whiskeyjar',
  36. 'display_id': 'jeune-couple-russe',
  37. 'categories': ['Amateur', 'Teen']
  38. }
  39. }]
  40. @staticmethod
  41. def __get_thumbnail_data(xml):
  42. """
  43. Constructs a list of video thumbnails from timeline preview images.
  44. :param xml: the information XML document to parse
  45. """
  46. timeline = xml.find('timeline')
  47. if timeline is None:
  48. # not all videos have the data - ah well
  49. return []
  50. # get the required information from the XML
  51. width = str_to_int(timeline.find('imageWidth').text)
  52. height = str_to_int(timeline.find('imageHeight').text)
  53. first = str_to_int(timeline.find('imageFirst').text)
  54. last = str_to_int(timeline.find('imageLast').text)
  55. pattern = timeline.find('imagePattern').text
  56. # generate the list of thumbnail information dicts
  57. thumbnails = []
  58. for i in range(first, last + 1):
  59. thumbnails.append({
  60. 'url': pattern.replace('#', compat_str(i)),
  61. 'width': width,
  62. 'height': height
  63. })
  64. return thumbnails
  65. def _real_extract(self, url):
  66. video_id = self._match_id(url)
  67. webpage = self._download_webpage(url, video_id)
  68. # find and retrieve the XML document detailing video download URLs
  69. info_url = self._html_search_regex(
  70. r'flashvars\.config = escape\("(.+?)"', webpage, 'player parameters')
  71. xml = self._download_xml(info_url, video_id)
  72. # find the video container
  73. if xml.find('videoConfig') is not None:
  74. ext = xml.find('videoConfig').find('type').text
  75. else:
  76. ext = 'flv' # guess...
  77. # work out the video URL(s)
  78. formats = []
  79. if xml.find('videoLink') is not None:
  80. # single format available
  81. formats.append({
  82. 'url': xpath_text(xml, 'videoLink', 'url', True),
  83. 'ext': ext
  84. })
  85. else:
  86. # multiple formats available
  87. for item in xml.find('quality').findall('item'):
  88. resolution = xpath_text(item, 'res', 'resolution', True) # 480p etc.
  89. formats.append({
  90. 'url': xpath_text(item, 'videoLink', 'url', True),
  91. 'ext': ext,
  92. 'resolution': resolution,
  93. 'height': int(re.findall(r'\d+', resolution)[0])
  94. })
  95. self._sort_formats(formats)
  96. return {
  97. 'id': video_id,
  98. 'formats': formats,
  99. 'title': self._html_search_regex(
  100. r'<div id="view_title"><h1>(.*?)</h1>', webpage, 'title'),
  101. 'display_id': re.compile(self._VALID_URL).match(url).group('name'),
  102. 'thumbnails': self.__get_thumbnail_data(xml),
  103. 'thumbnail': xpath_text(xml, 'startThumb', 'thumbnail'),
  104. 'description': self._html_search_regex(
  105. r'name="description" value="(.*?)"', webpage, 'description', fatal=False),
  106. 'uploader_id': self._html_search_regex(
  107. r'name="username" value="(.*?)"', webpage, 'uploader_id', fatal=False),
  108. 'view_count': str_to_int(self._html_search_regex(
  109. r'<br>Views <strong>([0-9]+)</strong>', webpage, 'view_count, fatal=False')),
  110. 'average_rating': float(self._html_search_regex(
  111. r'Current Rating<br> <strong>(.*?)</strong>', webpage, 'average_rating', fatal=False)),
  112. 'comment_count': str_to_int(self._html_search_regex(
  113. r'<span id="comCount">([0-9]+)</span>', webpage, 'comment_count', fatal=False)),
  114. 'age_limit': 18,
  115. 'webpage_url': self._html_search_regex(
  116. r'name="link" value="(.*?)"', webpage, 'webpage_url', fatal=False),
  117. 'categories': self._html_search_regex(
  118. r'</div>\s*(.*?)\s*<br>', webpage, 'categories', fatal=False).split(', ')
  119. }