picarto.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError, js_to_json, urlencode_postdata
  5. class PicartoIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www.)?picarto\.tv/(?P<id>[a-zA-Z0-9]+)[^/]*$'
  7. _TEST = {
  8. 'url': 'https://picarto.tv/Setz',
  9. 'info_dict': {
  10. 'id': 'Setz',
  11. 'ext': 'mp4',
  12. 'title': 're:^Setz [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  13. 'timestamp': int,
  14. 'is_live': True
  15. },
  16. 'params': {
  17. 'skip_download': True
  18. }
  19. }
  20. def _real_extract(self, url):
  21. channel_id = self._match_id(url)
  22. stream_page = self._download_webpage(url, channel_id)
  23. if 'This channel does not exist.' in stream_page:
  24. raise ExtractorError('Channel does not exist', expected=True)
  25. player_settings_js = self._html_search_regex(
  26. r'(?s)playerSettings\[1\]\s*=\s*(\{.+?\}\n)', stream_page, 'player-settings')
  27. player_settings = self._parse_json(player_settings_js, channel_id,
  28. transform_source=js_to_json)
  29. if not player_settings.get('online'):
  30. raise ExtractorError('Stream is offline', expected=True)
  31. cdn_data = self._download_json('https://picarto.tv/process/channel', channel_id,
  32. data=urlencode_postdata({'loadbalancinginfo': channel_id}),
  33. note='Fetching load balancer info')
  34. edge = [edge['ep'] for edge in cdn_data['edges'] if edge['id'] == cdn_data['preferedEdge']][0]
  35. formats = self._extract_m3u8_formats('https://%s/hls/%s/index.m3u8' % (edge, channel_id),
  36. channel_id, 'mp4')
  37. formats.append({'url': 'https://%s/mp4/%s.mp4' % (edge, channel_id)})
  38. self._sort_formats(formats)
  39. return {
  40. 'id': channel_id,
  41. 'formats': formats,
  42. 'ext': 'mp4',
  43. 'title': self._live_title(channel_id),
  44. 'is_live': True,
  45. 'thumbnail': player_settings.get('vodThumb'),
  46. 'age_limit': 18 if player_settings.get('mature') else None,
  47. }
  48. class PicartoVodIE(InfoExtractor):
  49. _VALID_URL = r'https?://(?:www.)?picarto\.tv/videopopout/(?P<id>[a-zA-Z0-9_\-\.]+).flv'
  50. _TEST = {
  51. 'url': 'https://picarto.tv/videopopout/Carrot_2018.01.11.07.55.12.flv',
  52. 'md5': '80765b67813053ff31d4df2bd5e900ce',
  53. 'info_dict': {
  54. 'id': 'Carrot_2018.01.11.07.55.12',
  55. 'ext': 'mp4',
  56. 'title': 'Carrot_2018.01.11.07.55.12',
  57. 'thumbnail': r're:^https?://.*\.jpg$'
  58. }
  59. }
  60. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. webpage = self._download_webpage(url, video_id)
  63. vod_info_js = self._html_search_regex(r'(?s)"#vod-player",\s*(\{.+?\})\)',
  64. webpage, video_id)
  65. vod_info = self._parse_json(vod_info_js, video_id, transform_source=js_to_json)
  66. return {
  67. 'id': video_id,
  68. 'title': video_id,
  69. 'ext': 'mp4',
  70. 'protocol': 'm3u8',
  71. 'url': vod_info['vod'],
  72. 'thumbnail': vod_info.get('vodThumb'),
  73. }