koditidal.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:plugin.audio.tidal2 作者: arnesongit 项目源码 文件源码
def get_video_url(self, video_id, maxHeight=-1):
        oldSessionId = self.session_id
        self.session_id = self.http_video_session_id
        maxVideoHeight = maxHeight if maxHeight > 0 else self._config.maxVideoHeight
        media = None
        try:
            if self._config.forceHttpVideo:
                quality = 'LOW' if self._config.maxVideoHeight < 480 else 'MEDIUM' if self._config.maxVideoHeight < 720 else 'HIGH'
                media = Session.get_video_url(self, video_id, quality=quality)
        except requests.HTTPError as e:
            r = e.response
            msg = _T(30505)
            try:
                msg = r.reason
                msg = r.json().get('userMessage')
            except:
                pass
            log('HTTP-Error: ' + msg, xbmc.LOGERROR)
            log('Got no HTTP Stream for Video ID %s, using HLS Stream ...' % video_id, xbmc.LOGERROR)
            xbmcgui.Dialog().notification(plugin.name, _T(30510), xbmcgui.NOTIFICATION_WARNING)
        if not media:
            # Using HLS-Stream 
            self.session_id = self.stream_session_id
            media = Session.get_video_url(self, video_id, quality=None)
        if maxVideoHeight <> 9999 and media.url.lower().find('.m3u8') > 0:
            log('Parsing M3U8 Playlist: %s' % media.url)
            m3u8obj = m3u8_load(media.url)
            if m3u8obj.is_variant and not m3u8obj.cookies:
                # Variant Streams with Cookies have to be played without stream selection.
                # You can change the Bandwidth Limit in Kodi Settings to select other streams !
                # Select stream with highest resolution <= maxVideoHeight
                selected_height = 0
                selected_bandwidth = -1
                for playlist in m3u8obj.playlists:
                    try:
                        width, height = playlist.stream_info.resolution
                        bandwidth = playlist.stream_info.average_bandwidth
                        if not bandwidth:
                            bandwidth = playlist.stream_info.bandwidth
                        if not bandwidth:
                            bandwidth = 0
                        if (height > selected_height or (height == selected_height and bandwidth > selected_bandwidth)) and height <= maxVideoHeight:
                            if re.match(r'https?://', playlist.uri):
                                media.url = playlist.uri
                            else:
                                media.url = m3u8obj.base_uri + playlist.uri
                            if height == selected_height and bandwidth > selected_bandwidth:
                                log('Bandwidth %s > %s' % (bandwidth, selected_bandwidth))
                            log('Selected %sx%s %s: %s' % (width, height, bandwidth, playlist.uri.split('?')[0].split('/')[-1]))
                            selected_height = height
                            selected_bandwidth = bandwidth
                            media.width = width
                            media.height = height
                            media.bandwidth = bandwidth
                        elif height > maxVideoHeight:
                            log('Skipped %sx%s %s: %s' % (width, height, bandwidth, playlist.uri.split('?')[0].split('/')[-1]))
                    except:
                        pass
        self.session_id = oldSessionId
        return media
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号