def add_torrent(torrent): """ Add torrent for downloading @param torrent: @return: """ jsonrq.add_torrent(torrent) progress_dialog = xbmcgui.DialogProgress() progress_dialog.create(string(32015)) progress_dialog.update(0, string(32016)) while not (progress_dialog.iscanceled() or jsonrq.check_torrent_added()): time.sleep(1.0) if not progress_dialog.iscanceled(): progress_dialog.close() return jsonrq.get_last_added_torrent() else: return None
def add_torrent(torrent, paused=True): """ Add torrent for downloading :param torrent: :return: """ jsonrq.add_torrent(torrent, paused) progress_dialog = xbmcgui.DialogProgress() progress_dialog.create(_('Adding torrent')) progress_dialog.update(0, _('This may take some time.')) while not (progress_dialog.iscanceled() or jsonrq.check_torrent_added()): xbmc.sleep(1000) if not progress_dialog.iscanceled(): progress_dialog.close() return jsonrq.get_last_added_torrent() else: return None
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 ''