logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

cammodels.py (2952B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. url_or_none,
  7. )
  8. class CamModelsIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>[^/?#&]+)'
  10. _TESTS = [{
  11. 'url': 'https://www.cammodels.com/cam/AutumnKnight/',
  12. 'only_matching': True,
  13. 'age_limit': 18
  14. }]
  15. def _real_extract(self, url):
  16. user_id = self._match_id(url)
  17. manifest = self._download_json(
  18. 'https://manifest-server.naiadsystems.com/live/s:%s.json' % user_id, user_id)
  19. formats = []
  20. thumbnails = []
  21. for format_id, format_dict in manifest['formats'].items():
  22. if not isinstance(format_dict, dict):
  23. continue
  24. encodings = format_dict.get('encodings')
  25. if not isinstance(encodings, list):
  26. continue
  27. vcodec = format_dict.get('videoCodec')
  28. acodec = format_dict.get('audioCodec')
  29. for media in encodings:
  30. if not isinstance(media, dict):
  31. continue
  32. media_url = url_or_none(media.get('location'))
  33. if not media_url:
  34. continue
  35. format_id_list = [format_id]
  36. height = int_or_none(media.get('videoHeight'))
  37. if height is not None:
  38. format_id_list.append('%dp' % height)
  39. f = {
  40. 'url': media_url,
  41. 'format_id': '-'.join(format_id_list),
  42. 'width': int_or_none(media.get('videoWidth')),
  43. 'height': height,
  44. 'vbr': int_or_none(media.get('videoKbps')),
  45. 'abr': int_or_none(media.get('audioKbps')),
  46. 'fps': int_or_none(media.get('fps')),
  47. 'vcodec': vcodec,
  48. 'acodec': acodec,
  49. }
  50. if 'rtmp' in format_id:
  51. f['ext'] = 'flv'
  52. elif 'hls' in format_id:
  53. f.update({
  54. 'ext': 'mp4',
  55. # hls skips fragments, preferring rtmp
  56. 'preference': -1,
  57. })
  58. else:
  59. if format_id == 'jpeg':
  60. thumbnails.append({
  61. 'url': f['url'],
  62. 'width': f['width'],
  63. 'height': f['height'],
  64. 'format_id': f['format_id'],
  65. })
  66. continue
  67. formats.append(f)
  68. self._sort_formats(formats)
  69. return {
  70. 'id': user_id,
  71. 'title': self._live_title(user_id),
  72. 'thumbnails': thumbnails,
  73. 'is_live': True,
  74. 'formats': formats,
  75. 'age_limit': 18
  76. }