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.

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