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.

84 lines
2.8 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. NO_DEFAULT,
  9. str_to_int,
  10. )
  11. class XNXXIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:video|www)\.xnxx\.com/video-?(?P<id>[0-9a-z]+)/'
  13. _TESTS = [{
  14. 'url': 'http://www.xnxx.com/video-55awb78/skyrim_test_video',
  15. 'md5': '7583e96c15c0f21e9da3453d9920fbba',
  16. 'info_dict': {
  17. 'id': '55awb78',
  18. 'ext': 'mp4',
  19. 'title': 'Skyrim Test Video',
  20. 'thumbnail': r're:^https?://.*\.jpg',
  21. 'duration': 469,
  22. 'view_count': int,
  23. 'age_limit': 18,
  24. },
  25. }, {
  26. 'url': 'http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'http://www.xnxx.com/video-55awb78/',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. def get(meta, default=NO_DEFAULT, fatal=True):
  36. return self._search_regex(
  37. r'set%s\s*\(\s*(["\'])(?P<value>(?:(?!\1).)+)\1' % meta,
  38. webpage, meta, default=default, fatal=fatal, group='value')
  39. title = self._og_search_title(
  40. webpage, default=None) or get('VideoTitle')
  41. formats = []
  42. for mobj in re.finditer(
  43. r'setVideo(?:Url(?P<id>Low|High)|HLS)\s*\(\s*(?P<q>["\'])(?P<url>(?:https?:)?//.+?)(?P=q)', webpage):
  44. format_url = mobj.group('url')
  45. if determine_ext(format_url) == 'm3u8':
  46. formats.extend(self._extract_m3u8_formats(
  47. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  48. preference=1, m3u8_id='hls', fatal=False))
  49. else:
  50. format_id = mobj.group('id')
  51. if format_id:
  52. format_id = format_id.lower()
  53. formats.append({
  54. 'url': format_url,
  55. 'format_id': format_id,
  56. 'quality': -1 if format_id == 'low' else 0,
  57. })
  58. self._sort_formats(formats)
  59. thumbnail = self._og_search_thumbnail(webpage, default=None) or get(
  60. 'ThumbUrl', fatal=False) or get('ThumbUrl169', fatal=False)
  61. duration = int_or_none(self._og_search_property('duration', webpage))
  62. view_count = str_to_int(self._search_regex(
  63. r'id=["\']nb-views-number[^>]+>([\d,.]+)', webpage, 'view count',
  64. default=None))
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'thumbnail': thumbnail,
  69. 'duration': duration,
  70. 'view_count': view_count,
  71. 'age_limit': 18,
  72. 'formats': formats,
  73. }