parent
							
								
									cd55c6ccd7
								
							
						
					
					
						commit
						af62de104f
					
				@ -14,25 +14,23 @@ from ..utils import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class BeamProLiveIE(InfoExtractor):
 | 
					class BeamProLiveIE(InfoExtractor):
 | 
				
			||||||
    IE_NAME = 'Beam:live'
 | 
					    IE_NAME = 'Beam:live'
 | 
				
			||||||
    _VALID_URL = r'https?://(?:\w+.)?beam.pro/(?P<id>[^?]+)$'
 | 
					    _VALID_URL = r'https?://(?:\w+\.)?beam\.pro/(?P<id>[^/?#&]+)'
 | 
				
			||||||
    _API_CHANNEL = 'https://beam.pro/api/v1/channels/{0}'
 | 
					 | 
				
			||||||
    _API_MANIFEST = 'https://beam.pro/api/v1/channels/{0}/manifest.m3u8'
 | 
					 | 
				
			||||||
    _RATINGS = {'family': 0, 'teen': 13, '18+': 18}
 | 
					    _RATINGS = {'family': 0, 'teen': 13, '18+': 18}
 | 
				
			||||||
 | 
					 | 
				
			||||||
    _TEST = {
 | 
					    _TEST = {
 | 
				
			||||||
        'url': 'http://www.beam.pro/niterhayven',
 | 
					        'url': 'http://www.beam.pro/niterhayven',
 | 
				
			||||||
        'info_dict': {
 | 
					        'info_dict': {
 | 
				
			||||||
            'id': '261562',
 | 
					            'id': '261562',
 | 
				
			||||||
            'ext': 'mp4',
 | 
					            'ext': 'mp4',
 | 
				
			||||||
            'uploader': 'niterhayven',
 | 
					 | 
				
			||||||
            'timestamp': 1483477281,
 | 
					 | 
				
			||||||
            'age_limit': 18,
 | 
					 | 
				
			||||||
            'title': 'Introducing The Witcher 3 //  The Grind Starts Now!',
 | 
					            'title': 'Introducing The Witcher 3 //  The Grind Starts Now!',
 | 
				
			||||||
            'thumbnail': r're:https://.*\.jpg$',
 | 
					 | 
				
			||||||
            'upload_date': '20170103',
 | 
					 | 
				
			||||||
            'uploader_id': 373396,
 | 
					 | 
				
			||||||
            'description': 'md5:0b161ac080f15fe05d18a07adb44a74d',
 | 
					            'description': 'md5:0b161ac080f15fe05d18a07adb44a74d',
 | 
				
			||||||
 | 
					            'thumbnail': r're:https://.*\.jpg$',
 | 
				
			||||||
 | 
					            'timestamp': 1483477281,
 | 
				
			||||||
 | 
					            'upload_date': '20170103',
 | 
				
			||||||
 | 
					            'uploader': 'niterhayven',
 | 
				
			||||||
 | 
					            'uploader_id': '373396',
 | 
				
			||||||
 | 
					            'age_limit': 18,
 | 
				
			||||||
            'is_live': True,
 | 
					            'is_live': True,
 | 
				
			||||||
 | 
					            'view_count': int,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        'skip': 'niterhayven is offline',
 | 
					        'skip': 'niterhayven is offline',
 | 
				
			||||||
        'params': {
 | 
					        'params': {
 | 
				
			||||||
@ -41,42 +39,35 @@ class BeamProLiveIE(InfoExtractor):
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _real_extract(self, url):
 | 
					    def _real_extract(self, url):
 | 
				
			||||||
        channel_id = self._match_id(url)
 | 
					        channel_name = self._match_id(url)
 | 
				
			||||||
        chan_data = self._download_json(self._API_CHANNEL.format(channel_id), channel_id)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not chan_data.get('online'):
 | 
					        chan = self._download_json(
 | 
				
			||||||
            raise ExtractorError('{0} is offline'.format(channel_id), expected=True)
 | 
					            'https://beam.pro/api/v1/channels/%s' % channel_name, channel_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if chan.get('online') is False:
 | 
				
			||||||
 | 
					            raise ExtractorError(
 | 
				
			||||||
 | 
					                '{0} is offline'.format(channel_name), expected=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        channel_id = chan['id']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        formats = self._extract_m3u8_formats(
 | 
					        formats = self._extract_m3u8_formats(
 | 
				
			||||||
            self._API_MANIFEST.format(chan_data.get('id')), channel_id, ext='mp4')
 | 
					            'https://beam.pro/api/v1/channels/%s/manifest.m3u8' % channel_id,
 | 
				
			||||||
 | 
					            channel_name, ext='mp4', m3u8_id='hls', fatal=False)
 | 
				
			||||||
        self._sort_formats(formats)
 | 
					        self._sort_formats(formats)
 | 
				
			||||||
        info = {}
 | 
					 | 
				
			||||||
        info['formats'] = formats
 | 
					 | 
				
			||||||
        if chan_data:
 | 
					 | 
				
			||||||
            info.update(self._extract_info(chan_data))
 | 
					 | 
				
			||||||
        if not info.get('title'):
 | 
					 | 
				
			||||||
            info['title'] = self._live_title(channel_id)
 | 
					 | 
				
			||||||
        if not info.get('id'):  # barely possible but just in case
 | 
					 | 
				
			||||||
            info['id'] = compat_str(abs(hash(channel_id)) % (10 ** 8))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return info
 | 
					        user_id = chan.get('userId') or try_get(chan, lambda x: x['user']['id'])
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def _extract_info(self, info):
 | 
					 | 
				
			||||||
        thumbnail = try_get(info, lambda x: x['thumbnail']['url'], compat_str)
 | 
					 | 
				
			||||||
        username = try_get(info, lambda x: x['user']['url'], compat_str)
 | 
					 | 
				
			||||||
        video_id = compat_str(info['id']) if info.get('id') else None
 | 
					 | 
				
			||||||
        rating = info.get('audience')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            'id': video_id,
 | 
					            'id': compat_str(chan.get('id') or channel_name),
 | 
				
			||||||
            'title': info.get('name'),
 | 
					            'title': self._live_title(chan.get('name') or channel_name),
 | 
				
			||||||
            'description': clean_html(info.get('description')),
 | 
					            'description': clean_html(chan.get('description')),
 | 
				
			||||||
            'age_limit': self._RATINGS[rating] if rating in self._RATINGS else None,
 | 
					            'thumbnail': try_get(chan, lambda x: x['thumbnail']['url'], compat_str),
 | 
				
			||||||
            'is_live': True if info.get('online') else False,
 | 
					            'timestamp': parse_iso8601(chan.get('updatedAt')),
 | 
				
			||||||
            'timestamp': parse_iso8601(info.get('updatedAt')),
 | 
					            'uploader': chan.get('token') or try_get(
 | 
				
			||||||
            'uploader': info.get('token') or username,
 | 
					                chan, lambda x: x['user']['username'], compat_str),
 | 
				
			||||||
            'uploader_id': int_or_none(info.get('userId')),
 | 
					            'uploader_id': compat_str(user_id) if user_id else None,
 | 
				
			||||||
            'view_count': int_or_none(info.get('viewersTotal')),
 | 
					            'age_limit': self._RATINGS.get(chan.get('audience')),
 | 
				
			||||||
            'thumbnail': thumbnail,
 | 
					            'is_live': True,
 | 
				
			||||||
 | 
					            'view_count': int_or_none(chan.get('viewersTotal')),
 | 
				
			||||||
 | 
					            'formats': formats,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user