foxgay.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import itertools
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. get_element_by_id,
  5. int_or_none,
  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_extract_title(webpage), ' - Foxgay.com')
  26. description = get_element_by_id('inf_tit', webpage)
  27. # The default user-agent with foxgay cookies leads to pages without videos
  28. self.cookiejar.clear('.foxgay.com')
  29. # Find the URL for the iFrame which contains the actual video.
  30. iframe_url = self._html_search_regex(
  31. r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1', webpage,
  32. 'video frame', group='url')
  33. iframe = self._download_webpage(
  34. iframe_url, video_id, headers={'User-Agent': 'curl/7.50.1'},
  35. note='Downloading video frame')
  36. video_data = self._parse_json(self._search_regex(
  37. r'video_data\s*=\s*([^;]+);', iframe, 'video data'), video_id)
  38. formats = [{
  39. 'url': source,
  40. 'height': int_or_none(resolution),
  41. } for source, resolution in zip(
  42. video_data['sources'], video_data.get('resolutions', itertools.repeat(None)))]
  43. return {
  44. 'id': video_id,
  45. 'title': title,
  46. 'formats': formats,
  47. 'description': description,
  48. 'thumbnail': video_data.get('act_vid', {}).get('thumb'),
  49. 'age_limit': 18,
  50. }