def stream_torrent(file_index): """ Stream a videofile from torrent @param file_index: @return: """ torrent_data = jsonrq.get_last_added_torrent() if file_index >= len(torrent_data['files']) or file_index < 0: raise IndexError('File index {0} is out of range!'.format(file_index)) progress_dialog = xbmcgui.DialogProgress() progress_dialog.create(string(32014)) jsonrq.buffer_file(file_index) while not (progress_dialog.iscanceled() or jsonrq.check_buffering_complete()): torrent_info = jsonrq.get_torrent_info(torrent_data['info_hash']) progress_dialog.update(jsonrq.get_buffer_percent(), string(32018).format(torrent_info['total_download']), string(32019).format(torrent_info['dl_speed']), string(32020).format(torrent_info['num_seeds'])) time.sleep(1.0) if not progress_dialog.iscanceled(): progress_dialog.close() return media_url + quote(torrent_data['files'][file_index][0].replace('\\', '/').encode('utf-8')) else: jsonrq.abort_buffering() return ''
def stream_torrent(file_index, info_hash): """ Stream a videofile from torrent :param file_index: :param info_hash: :return: """ files = jsonrq.get_files(info_hash) if file_index not in range(len(files)): raise IndexError('File index {0} is out of range!'.format(file_index)) progress_dialog = xbmcgui.DialogProgress() progress_dialog.create(_('Buffering torrent')) jsonrq.buffer_file(file_index, info_hash) while not (progress_dialog.iscanceled() or jsonrq.check_buffering_complete()): torrent_info = jsonrq.get_torrent_info(info_hash) progress_dialog.update(jsonrq.get_buffer_percent(), _('Downloaded: {0}MB. Seeds: {1}.').format( torrent_info['total_download'], torrent_info['num_seeds'] ), _('Download speed: {0}KB/s.').format(torrent_info['dl_speed'])) xbmc.sleep(1000) if not progress_dialog.iscanceled(): progress_dialog.close() return media_url + quote(files[file_index][0].replace('\\', '/').encode('utf-8')) else: jsonrq.abort_buffering() return ''
def buffer_torrent(torrent, file_index=None): """ Buffer a torrent and resolve a playable path from it @param torrent: str - magnet link or .torrent file URL @return: """ torrent_data = add_torrent(torrent) if torrent_data is not None: if file_index is None or file_index == 'dialog': file_index = select_file(torrent_data, file_index == 'dialog') if file_index is None: jsonrq.remove_torrent(torrent_data['info_hash'], True) xbmcgui.Dialog().notification(addon.id, string(32022), addon.icon, 3000) elif file_index >= 0: url = stream_torrent(file_index) if url: return url else: xbmcgui.Dialog().notification(addon.id, string(32021), addon.icon, 3000) if not (jsonrq.check_torrent_added() and jsonrq.check_buffering_complete()): xbmcgui.Dialog().notification(addon.id, string(32023), addon.icon, 3000) return ''
def buffer_torrent(torrent, file_index=None): """ Buffer a torrent and resolve a playable path from it :param torrent: str - magnet link or .torrent file URL :return: """ torrent_data = add_torrent(torrent, False) if torrent_data is not None: if file_index is None or file_index == 'dialog': file_index = select_file(torrent_data, file_index == 'dialog') if file_index is None: jsonrq.remove_torrent(torrent_data['info_hash'], True) xbmcgui.Dialog().notification(addon.id, _('No videofiles to play.'), addon.icon, 3000) elif file_index >= 0: url = stream_torrent(file_index, torrent_data['info_hash']) if url: return url else: xbmcgui.Dialog().notification(addon.id, _('No video is selected.'), addon.icon, 3000) if not (jsonrq.check_torrent_added() and jsonrq.check_buffering_complete()): xbmcgui.Dialog().notification(addon.id, _('Playback cancelled.'), addon.icon, 3000) return ''