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.

62 lines
2.1 KiB

  1. from __future__ import unicode_literals
  2. import itertools
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. get_element_by_id,
  6. remove_end,
  7. )
  8. class FoxgayIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?foxgay\.com/videos/(?:\S+-)?(?P<id>\d+)\.shtml'
  10. _TEST = {
  11. 'url': 'http://foxgay.com/videos/fuck-turkish-style-2582.shtml',
  12. 'md5': '344558ccfea74d33b7adbce22e577f54',
  13. 'info_dict': {
  14. 'id': '2582',
  15. 'ext': 'mp4',
  16. 'title': 'Fuck Turkish-style',
  17. 'description': 'md5:6ae2d9486921891efe89231ace13ffdf',
  18. 'age_limit': 18,
  19. 'thumbnail': r're:https?://.*\.jpg$',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. title = remove_end(self._html_search_regex(
  26. r'<title>([^<]+)</title>', webpage, 'title'), ' - Foxgay.com')
  27. description = get_element_by_id('inf_tit', webpage)
  28. # The default user-agent with foxgay cookies leads to pages without videos
  29. self._downloader.cookiejar.clear('.foxgay.com')
  30. # Find the URL for the iFrame which contains the actual video.
  31. iframe_url = self._html_search_regex(
  32. r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1', webpage,
  33. 'video frame', group='url')
  34. iframe = self._download_webpage(
  35. iframe_url, video_id, headers={'User-Agent': 'curl/7.50.1'},
  36. note='Downloading video frame')
  37. video_data = self._parse_json(self._search_regex(
  38. r'video_data\s*=\s*([^;]+);', iframe, 'video data'), video_id)
  39. formats = [{
  40. 'url': source,
  41. 'height': resolution,
  42. } for source, resolution in zip(
  43. video_data['sources'], video_data.get('resolutions', itertools.repeat(None)))]
  44. self._sort_formats(formats)
  45. return {
  46. 'id': video_id,
  47. 'title': title,
  48. 'formats': formats,
  49. 'description': description,
  50. 'thumbnail': video_data.get('act_vid', {}).get('thumb'),
  51. 'age_limit': 18,
  52. }