You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. clean_html,
  10. ExtractorError,
  11. determine_ext,
  12. )
  13. class XVideosIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?xvideos\.com/video(?P<id>[0-9]+)(?:.*)'
  15. _TEST = {
  16. 'url': 'http://www.xvideos.com/video4588838/biker_takes_his_girl',
  17. 'md5': '4b46ae6ea5e6e9086e714d883313c0c9',
  18. 'info_dict': {
  19. 'id': '4588838',
  20. 'ext': 'flv',
  21. 'title': 'Biker Takes his Girl',
  22. 'age_limit': 18,
  23. }
  24. }
  25. _ANDROID_USER_AGENT = 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19'
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. mobj = re.search(r'<h1 class="inlineError">(.+?)</h1>', webpage)
  30. if mobj:
  31. raise ExtractorError('%s said: %s' % (self.IE_NAME, clean_html(mobj.group(1))), expected=True)
  32. video_url = compat_urllib_parse.unquote(
  33. self._search_regex(r'flv_url=(.+?)&', webpage, 'video URL'))
  34. video_title = self._html_search_regex(
  35. r'<title>(.*?)\s+-\s+XVID', webpage, 'title')
  36. video_thumbnail = self._search_regex(
  37. r'url_bigthumb=(.+?)&amp', webpage, 'thumbnail', fatal=False)
  38. formats = [{
  39. 'url': video_url,
  40. }]
  41. android_req = compat_urllib_request.Request(url)
  42. android_req.add_header('User-Agent', self._ANDROID_USER_AGENT)
  43. android_webpage = self._download_webpage(android_req, video_id, fatal=False)
  44. if android_webpage is not None:
  45. player_params_str = self._search_regex(
  46. 'mobileReplacePlayerDivTwoQual\(([^)]+)\)',
  47. android_webpage, 'player parameters', default='')
  48. player_params = list(map(lambda s: s.strip(' \''), player_params_str.split(',')))
  49. if player_params:
  50. formats.extend([{
  51. 'url': param,
  52. 'preference': -10,
  53. } for param in player_params if determine_ext(param) == 'mp4'])
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'formats': formats,
  58. 'title': video_title,
  59. 'ext': 'flv',
  60. 'thumbnail': video_thumbnail,
  61. 'age_limit': 18,
  62. }