def play(self, driveid, item_driveid=None, item_id=None): find_subtitles = self._addon.getSetting( 'set_subtitle') == 'true' and self._content_type == 'video' item = self.get_item(driveid, item_driveid, item_id, find_subtitles=find_subtitles) file_name = Utils.unicode(item['name']) list_item = xbmcgui.ListItem(file_name) if 'audio' in item: list_item.setInfo('music', item['audio']) elif 'video' in item: list_item.addStreamInfo('video', item['video']) list_item.select(True) list_item.setPath( DownloadServiceUtil.build_download_url( self._addonid, driveid, item_driveid, item_id, urllib.quote(Utils.str(file_name)))) list_item.setProperty('mimetype', Utils.get_safe_value(item, 'mimetype')) if find_subtitles and 'subtitles' in item: subtitles = [] for subtitle in item['subtitles']: subtitles.append( DownloadServiceUtil.build_download_url( self._addonid, driveid, Utils.default( Utils.get_safe_value(subtitle, 'drive_id'), driveid), subtitle['id'], urllib.quote(Utils.str(subtitle['name'])))) list_item.setSubtitles(subtitles) xbmcplugin.setResolvedUrl(self._addon_handle, True, list_item)
def _get_item_play_url(self, file_name, driveid, item_driveid=None, item_id=None): return DownloadServiceUtil.build_download_url( driveid, item_driveid, item_id, urllib.quote(Utils.str(file_name)))
def create_nfo(driveid, item, item_name, nfo_path): item_enc = urllib.quote_plus(item_name.encode('utf-8')) dl_url = DownloadServiceUtil.download_item(driveid, item, item_enc) try: response = Request(dl_url, None).request() except: Logger.error('Error on request to: %s' % dl_url) return False f = None try: f=KodiUtils.file(nfo_path,'w') f.write(response) except Exception as err: Logger.error(err) return False finally: if f: f.close() return True
def get_subtitles(self): try: from clouddrive.common.remote.request import Request from clouddrive.common.service.download import DownloadServiceUtil response = Request(self.getPlayingFile() + '?subtitles', None).request_json() if response and 'driveid' in response and 'subtitles' in response: driveid = response['driveid'] subtitles = response['subtitles'] for subtitle in subtitles: url = DownloadServiceUtil.build_download_url( driveid, Utils.default( Utils.get_safe_value(subtitle, 'drive_id'), driveid), subtitle['id'], urllib.quote(Utils.str(subtitle['name']))) Logger.debug('subtitle: %s' % url) self.setSubtitles(url) except Exception as e: Logger.error(e) from clouddrive.common.remote.errorreport import ErrorReport ErrorReport.handle_exception(e)
def play(self, driveid, item_driveid=None, item_id=None): self.get_provider().configure(self._account_manager, driveid) find_subtitles = self._addon.getSetting( 'set_subtitle') == 'true' and self._content_type == 'video' item = self.get_provider().get_item(item_driveid, item_id, find_subtitles=find_subtitles) file_name = Utils.unicode(item['name']) list_item = xbmcgui.ListItem(file_name) succeeded = True info = KodiUtils.get_current_library_info() if not info: info = KodiUtils.find_exported_video_in_library( item_id, file_name + ExportManager._strm_extension) if info and info['id']: Logger.debug('library info: %s' % Utils.str(info)) KodiUtils.set_home_property('dbid', Utils.str(info['id'])) KodiUtils.set_home_property('dbtype', info['type']) KodiUtils.set_home_property('addonid', self._addonid) details = KodiUtils.get_video_details(info['type'], info['id']) Logger.debug('library details: %s' % Utils.str(details)) if details and 'resume' in details: KodiUtils.set_home_property('playcount', Utils.str(details['playcount'])) resume = details['resume'] if resume['position'] > 0: play_resume = False if self.iskrypton: play_resume = KodiUtils.get_addon_setting( 'resume_playing') == 'true' elif KodiUtils.get_addon_setting('ask_resume') == 'true': d = datetime(1, 1, 1) + timedelta(seconds=resume['position']) t = '%02d:%02d:%02d' % (d.hour, d.minute, d.second) Logger.debug(t) option = self._dialog.contextmenu([ KodiUtils.localize(32054, addon=self._common_addon) % t, KodiUtils.localize(12021) ]) Logger.debug('selected option: %d' % option) if option == -1: succeeded = False elif option == 0: play_resume = True if play_resume: list_item.setProperty('resumetime', Utils.str(resume['position'])) list_item.setProperty('startoffset', Utils.str(resume['position'])) list_item.setProperty('totaltime', Utils.str(resume['total'])) else: from clouddrive.common.service.player import KodiPlayer KodiPlayer.cleanup() if 'audio' in item: list_item.setInfo('music', item['audio']) elif 'video' in item: list_item.addStreamInfo('video', item['video']) list_item.select(True) list_item.setPath( self._get_item_play_url(file_name, driveid, item_driveid, item_id)) list_item.setProperty('mimetype', Utils.get_safe_value(item, 'mimetype')) if find_subtitles and 'subtitles' in item: subtitles = [] for subtitle in item['subtitles']: subtitles.append( DownloadServiceUtil.build_download_url( driveid, Utils.default( Utils.get_safe_value(subtitle, 'drive_id'), driveid), subtitle['id'], urllib.quote(Utils.str(subtitle['name'])))) list_item.setSubtitles(subtitles) if not self.cancel_operation(): xbmcplugin.setResolvedUrl(self._addon_handle, succeeded, list_item)
def _process_items(self, items, driveid): listing = [] for item in items: item_id = item['id'] item_name = Utils.unicode(item['name']) item_name_extension = item['name_extension'] item_driveid = Utils.default( Utils.get_safe_value(item, 'drive_id'), driveid) list_item = xbmcgui.ListItem(item_name) url = None is_folder = 'folder' in item params = { 'content_type': self._content_type, 'item_driveid': item_driveid, 'item_id': item_id, 'driveid': driveid } if 'extra_params' in item: params.update(item['extra_params']) context_options = [] info = { 'size': item['size'], 'date': KodiUtils.to_kodi_item_date_str( KodiUtils.to_datetime( Utils.get_safe_value(item, 'last_modified_date'))) } if is_folder: params['action'] = '_list_folder' url = self._addon_url + '?' + urllib.urlencode(params) params['action'] = '_search' cmd = 'ActivateWindow(%d,%s?%s)' % (xbmcgui.getCurrentWindowId( ), self._addon_url, urllib.urlencode(params)) context_options.append( (self._common_addon.getLocalizedString(32039), cmd)) if self._content_type == 'audio' or self._content_type == 'video': params['action'] = '_open_export' params['name'] = urllib.quote(Utils.str(item_name)) context_options.append( (self._common_addon.getLocalizedString(32004), 'RunPlugin(' + self._addon_url + '?' + urllib.urlencode(params) + ')')) del params['name'] elif self._content_type == 'image' and self._auto_refreshed_slideshow_supported: params['action'] = '_slideshow' context_options.append( (self._common_addon.getLocalizedString(32032), 'RunPlugin(' + self._addon_url + '?' + urllib.urlencode(params) + ')')) elif (('video' in item or item_name_extension in self._video_file_extensions) and self._content_type == 'video') or ( ('audio' in item or item_name_extension in self._audio_file_extensions) and self._content_type == 'audio'): list_item.setProperty('IsPlayable', 'true') params['action'] = 'play' url = self._addon_url + '?' + urllib.urlencode(params) info_type = self._content_type if 'audio' in item: info.update(item['audio']) info_type = 'music' elif 'video' in item: list_item.addStreamInfo('video', item['video']) list_item.setInfo(info_type, info) if 'thumbnail' in item: list_item.setArt({ 'icon': item['thumbnail'], 'thumb': item['thumbnail'] }) elif ( 'image' in item or item_name_extension in self._image_file_extensions ) and self._content_type == 'image' and item_name_extension != 'mp4': if 'url' in item: url = item['url'] else: url = DownloadServiceUtil.build_download_url( driveid, item_driveid, item_id, urllib.quote(Utils.str(item_name))) if 'image' in item: info.update(item['image']) list_item.setInfo('pictures', info) if 'thumbnail' in item and item['thumbnail']: list_item.setArt({ 'icon': item['thumbnail'], 'thumb': item['thumbnail'] }) if url: context_options.extend( self.get_context_options(list_item, params, is_folder)) list_item.addContextMenuItems(context_options) mimetype = Utils.default( Utils.get_mimetype_by_extension(item_name_extension), Utils.get_safe_value(item, 'mimetype')) if mimetype: list_item.setProperty('mimetype', mimetype) listing.append((url, list_item, is_folder)) xbmcplugin.addDirectoryItems(self._addon_handle, listing, len(listing)) xbmcplugin.endOfDirectory(self._addon_handle, True)