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.7 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. fix_xml_ampersands,
  7. )
  8. class TNAFlixIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/(?P<cat_id>[\w-]+)/(?P<display_id>[\w-]+)/video(?P<id>\d+)'
  10. _TITLE_REGEX = None
  11. _DESCRIPTION_REGEX = r'<h3 itemprop="description">([^<]+)</h3>'
  12. _CONFIG_REGEX = r'flashvars\.config\s*=\s*escape\("([^"]+)"'
  13. _TEST = {
  14. 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
  15. 'md5': 'ecf3498417d09216374fc5907f9c6ec0',
  16. 'info_dict': {
  17. 'id': '553878',
  18. 'display_id': 'Carmella-Decesare-striptease',
  19. 'ext': 'mp4',
  20. 'title': 'Carmella Decesare - striptease',
  21. 'description': '',
  22. 'thumbnail': 're:https?://.*\.jpg$',
  23. 'duration': 91,
  24. 'age_limit': 18,
  25. }
  26. }
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. video_id = mobj.group('id')
  30. display_id = mobj.group('display_id')
  31. webpage = self._download_webpage(url, display_id)
  32. title = self._html_search_regex(
  33. self._TITLE_REGEX, webpage, 'title') if self._TITLE_REGEX else self._og_search_title(webpage)
  34. description = self._html_search_regex(
  35. self._DESCRIPTION_REGEX, webpage, 'description', fatal=False, default='')
  36. age_limit = self._rta_search(webpage)
  37. duration = self._html_search_meta('duration', webpage, 'duration', default=None)
  38. if duration:
  39. duration = parse_duration(duration[1:])
  40. cfg_url = self._html_search_regex(
  41. self._CONFIG_REGEX, webpage, 'flashvars.config')
  42. cfg_xml = self._download_xml(
  43. cfg_url, display_id, note='Downloading metadata',
  44. transform_source=fix_xml_ampersands)
  45. thumbnail = cfg_xml.find('./startThumb').text
  46. formats = []
  47. for item in cfg_xml.findall('./quality/item'):
  48. video_url = re.sub('speed=\d+', 'speed=', item.find('videoLink').text)
  49. format_id = item.find('res').text
  50. fmt = {
  51. 'url': video_url,
  52. 'format_id': format_id,
  53. }
  54. m = re.search(r'^(\d+)', format_id)
  55. if m:
  56. fmt['height'] = int(m.group(1))
  57. formats.append(fmt)
  58. self._sort_formats(formats)
  59. return {
  60. 'id': video_id,
  61. 'display_id': display_id,
  62. 'title': title,
  63. 'description': description,
  64. 'thumbnail': thumbnail,
  65. 'duration': duration,
  66. 'age_limit': age_limit,
  67. 'formats': formats,
  68. }