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.

98 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. url_or_none,
  8. )
  9. class CamModelsIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
  11. _TESTS = [{
  12. 'url': 'https://www.cammodels.com/cam/AutumnKnight/',
  13. 'only_matching': True,
  14. 'age_limit': 18
  15. }]
  16. def _real_extract(self, url):
  17. user_id = self._match_id(url)
  18. webpage = self._download_webpage(
  19. url, user_id, headers=self.geo_verification_headers())
  20. manifest_root = self._html_search_regex(
  21. r'manifestUrlRoot=([^&\']+)', webpage, 'manifest', default=None)
  22. if not manifest_root:
  23. ERRORS = (
  24. ("I'm offline, but let's stay connected", 'This user is currently offline'),
  25. ('in a private show', 'This user is in a private show'),
  26. ('is currently performing LIVE', 'This model is currently performing live'),
  27. )
  28. for pattern, message in ERRORS:
  29. if pattern in webpage:
  30. error = message
  31. expected = True
  32. break
  33. else:
  34. error = 'Unable to find manifest URL root'
  35. expected = False
  36. raise ExtractorError(error, expected=expected)
  37. manifest = self._download_json(
  38. '%s%s.json' % (manifest_root, user_id), user_id)
  39. formats = []
  40. for format_id, format_dict in manifest['formats'].items():
  41. if not isinstance(format_dict, dict):
  42. continue
  43. encodings = format_dict.get('encodings')
  44. if not isinstance(encodings, list):
  45. continue
  46. vcodec = format_dict.get('videoCodec')
  47. acodec = format_dict.get('audioCodec')
  48. for media in encodings:
  49. if not isinstance(media, dict):
  50. continue
  51. media_url = url_or_none(media.get('location'))
  52. if not media_url:
  53. continue
  54. format_id_list = [format_id]
  55. height = int_or_none(media.get('videoHeight'))
  56. if height is not None:
  57. format_id_list.append('%dp' % height)
  58. f = {
  59. 'url': media_url,
  60. 'format_id': '-'.join(format_id_list),
  61. 'width': int_or_none(media.get('videoWidth')),
  62. 'height': height,
  63. 'vbr': int_or_none(media.get('videoKbps')),
  64. 'abr': int_or_none(media.get('audioKbps')),
  65. 'fps': int_or_none(media.get('fps')),
  66. 'vcodec': vcodec,
  67. 'acodec': acodec,
  68. }
  69. if 'rtmp' in format_id:
  70. f['ext'] = 'flv'
  71. elif 'hls' in format_id:
  72. f.update({
  73. 'ext': 'mp4',
  74. # hls skips fragments, preferring rtmp
  75. 'preference': -1,
  76. })
  77. else:
  78. continue
  79. formats.append(f)
  80. self._sort_formats(formats)
  81. return {
  82. 'id': user_id,
  83. 'title': self._live_title(user_id),
  84. 'is_live': True,
  85. 'formats': formats,
  86. 'age_limit': 18
  87. }