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.

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