def get_strm_link(driveid, item, content_type, addon_url): item_id = Utils.str(item['id']) item_drive_id = Utils.default(Utils.get_safe_value(item, 'drive_id'), driveid) content = addon_url + '?' + urllib.urlencode( {'action': 'play', 'content_type': content_type, 'item_driveid': item_drive_id, 'item_id': item_id, 'driveid': driveid}) return Utils.str(content)
def get_item(self, driveid, item_driveid=None, item_id=None, path=None, find_subtitles=False, include_download_info=False): self._provider.configure(self._account_manager, driveid) item_driveid = Utils.default(item_driveid, driveid) all_cache_key = self._addonid+'-drive-'+Utils.str(driveid)+'-item_driveid-'+Utils.str(item_driveid)+'-item_id-'+Utils.str(item_id)+'-path-'+Utils.str(path) f = self._cache.get(all_cache_key) if f: item = self._extract_item(f, include_download_info) else: path_cache_key = self._addonid+'-drive-None-item_driveid-None-item_id-None-path-'+Utils.str(path) f = self._cache.get(path_cache_key) if f: item = self._extract_item(f, include_download_info) else: self._parameters['fields'] = self._file_fileds if not item_id and path == '/': item_id = 'root' if item_id: f = self._provider.get('/files/%s' % item_id, parameters = self._parameters) self._cache.set(all_cache_key, f, expiration=datetime.timedelta(seconds=59)) item = self._extract_item(f, include_download_info) else: item = self.get_item_by_path(path, include_download_info) if find_subtitles: subtitles = [] self._parameters['fields'] = 'files(' + self._file_fileds + ')' self._parameters['q'] = 'name contains \'%s\'' % Utils.str(Utils.remove_extension(item['name'])) files = self._provider.get('/files', parameters = self._parameters) for f in files['files']: subtitle = self._extract_item(f, include_download_info) if subtitle['name_extension'] == 'srt' or subtitle['name_extension'] == 'sub' or subtitle['name_extension'] == 'sbv': subtitles.append(subtitle) if subtitles: item['subtitles'] = subtitles return item
def get_item_by_path(self, path, include_download_info=False): if path[:1] == '/': path = path[1:] if path[-1:] == '/': path = path[:-1] parts = path.split('/') parent = 'root' current_path = '' item = None self._parameters['fields'] = 'files(%s)' % self._file_fileds for part in parts: part = urllib.unquote(part) current_path += '/%s' % part self._parameters['q'] = '\'%s\' in parents and name = \'%s\'' % ( Utils.str(parent), Utils.str(part)) files = self._provider.get('/files', parameters=self._parameters) if (len(files['files']) > 0): for f in files['files']: item = self._extract_item(f, include_download_info) parent = item['id'] cache_key = self._addonid + '-drive-None-item_driveid-None-item_id-None-path-' + Utils.str( current_path) self._cache.set(cache_key, f, expiration=datetime.timedelta(minutes=1)) break else: item = None break if not item: raise HTTPError(path, 404, 'Not found', None, None) return item
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_scheduled_export_map(self): exports = self.export_manager.get_exports() export_map = {} for exportid in exports: export = exports[exportid] schedules = Utils.get_safe_value(export, 'schedules', []) exporting = Utils.get_safe_value(export, 'exporting', False) if not exporting: if Utils.get_safe_value(export, 'schedule', False) and schedules: for schedule in schedules: key = Utils.str( Utils.get_safe_value(schedule, 'type', '')) if key != self._startup_type: key += Utils.get_safe_value(schedule, 'at', '') export_map[key] = Utils.get_safe_value( export_map, key, []) export_map[key].append(export) key = 'run_immediately' if Utils.get_safe_value(export, key, False): export_map[key] = Utils.get_safe_value(export_map, key, []) export_map[key].append(export) export[key] = False self.export_manager.save_export(export) Logger.debug('scheduled export_map: %s' % Utils.str(export_map)) return export_map
def process_files(self, driveid, files, on_items_page_completed=None): items = [] if files: if 'files' in files: for f in files['files']: item = self._extract_item(f) cache_key = self._addonid + '-drive-' + Utils.str( driveid) + '-item_driveid-' + Utils.str( item['drive_id']) + '-item_id-' + Utils.str( item['id']) + '-path-None' self._cache.set(cache_key, f, expiration=datetime.timedelta(minutes=1)) items.append(item) if on_items_page_completed: on_items_page_completed(items) if 'nextPageToken' in files: self._parameters['pageToken'] = files['nextPageToken'] next_files = self._provider.get('/files', parameters=self._parameters) if self.cancel_operation(): return items.extend( self.process_files(driveid, next_files, on_items_page_completed)) return items
def _select_stream_format(self, driveid, item_driveid=None, item_id=None, auto=False): url = None if not auto: self._progress_dialog.update(0, self._addon.getLocalizedString(32009)) self._provider.configure(self._account_manager, driveid) self._provider.get_item(item_driveid, item_id) request = Request( 'https://drive.google.com/get_video_info', urllib.urlencode({'docid': item_id}), { 'authorization': 'Bearer %s' % self._provider.get_access_tokens()['access_token'] }) response_text = request.request() response_params = dict(urlparse.parse_qsl(response_text)) if not auto: self._progress_dialog.close() if Utils.get_safe_value(response_params, 'status', '') == 'ok': fmt_list = Utils.get_safe_value(response_params, 'fmt_list', '').split(',') stream_formats = [] for fmt in fmt_list: data = fmt.split('/') stream_formats.append(data[1]) stream_formats.append(self._addon.getLocalizedString(32015)) Logger.debug('Stream formats: %s' % Utils.str(stream_formats)) select = -1 if auto: select = self._auto_select_stream(stream_formats) else: select = self._dialog.select( self._addon.getLocalizedString(32016), stream_formats, 8000, 0) Logger.debug('Selected: %s' % Utils.str(select)) if select == -1: self._cancel_operation = True elif select != len(stream_formats) - 1: data = fmt_list[select].split('/') fmt_stream_map = Utils.get_safe_value(response_params, 'fmt_stream_map', '').split(',') for fmt in fmt_stream_map: stream_data = fmt.split('|') if stream_data[0] == data[0]: url = stream_data[1] break if url: cookie_header = '' for cookie in request.response_cookies: if cookie_header: cookie_header += ';' cookie_header += cookie.name + '=' + cookie.value url += '|cookie=' + urllib.quote(cookie_header) return url
def _validate_access_tokens(self, access_tokens, url, data, request_headers): if not access_tokens or not 'access_token' in access_tokens or not 'refresh_token' in access_tokens or not 'expires_in' in access_tokens or not 'date' in access_tokens: raise RequestException( 'Access tokens provided are not valid: ' + Utils.str(access_tokens), None, 'Request URL: ' + Utils.str(url) + '\nRequest data: ' + Utils.str(data) + '\nRequest headers: ' + Utils.str(request_headers), None)
def process_change(self, change, items_info, export): change_type = None changed_item_id = change['id'] Logger.debug('Change: %s' % Utils.str(change)) if changed_item_id != export['id']: changed_item_name = change['name'] deleted = Utils.get_safe_value(change, 'deleted') parent_id = change['parent'] is_folder = 'folder' in change if not is_folder: changed_item_name += ExportManager._strm_extension if changed_item_id in items_info: item_info = items_info[changed_item_id] Logger.debug('item_info: %s' % Utils.str(item_info)) item_info_path = item_info['full_local_path'] if KodiUtils.file_exists(item_info_path): if deleted: change_type = self.process_change_delete(items_info, changed_item_id, is_folder) elif parent_id != item_info['parent'] or changed_item_name != item_info['name']: if parent_id in items_info: change_type = 'move' Logger.debug('Change is move') parent_item_info = items_info[parent_id] parent_item_path = parent_item_info['full_local_path'] new_path = os.path.join(parent_item_path, changed_item_name) if is_folder: new_path = os.path.join(new_path, '') if KodiUtils.file_rename(item_info_path, new_path): ExportManager.remove_item_info(items_info, changed_item_id) ExportManager.add_item_info(items_info, changed_item_id, changed_item_name, new_path, parent_id) else: change_type = 'retry' else: Logger.debug('Change is move but parent not in item list. Change is delete') change_type = self.process_change_delete(items_info, changed_item_id, is_folder) else: Logger.debug('Invalid state. Changed item not found: %s. Deleting from item list.' % item_info_path) change_type = self.process_change_delete(items_info, changed_item_id, is_folder) elif parent_id in items_info and not deleted: content_type = export['content_type'] item_name_extension = change['name_extension'] if is_folder or (('video' in change or item_name_extension in self._video_file_extensions) and content_type == 'video') or ('audio' in change and content_type == 'audio'): change_type = 'add' Logger.debug('Change is new item') parent_item_info = items_info[parent_id] parent_item_path = parent_item_info['full_local_path'] new_path = os.path.join(parent_item_path, changed_item_name) if is_folder: new_path = os.path.join(new_path, '') if not KodiUtils.mkdirs(new_path): change_type = 'retry' else: ExportManager.create_strm(export['driveid'], change, new_path, content_type, 'plugin://%s/' % self.addonid) if change_type != 'retry': ExportManager.add_item_info(items_info, changed_item_id, changed_item_name, new_path, parent_id) Logger.debug('change type: %s ' % Utils.str(change_type)) return change_type
def __export_folder(self, driveid, folder, export_folder, export, items_info): folder_id = Utils.str(folder['id']) folder_name = Utils.unicode(folder['name']) folder_path = os.path.join(os.path.join(export_folder, folder_name), '') if not xbmcvfs.exists(folder_path): try: xbmcvfs.mkdirs(folder_path) except: if self._system_monitor.waitForAbort(3): return xbmcvfs.mkdirs(folder_path) items = self.get_provider().get_folder_items( Utils.default(Utils.get_safe_value(folder, 'drive_id'), driveid), folder['id']) if self.cancel_operation(): return for item in items: if 'folder' in item: if self._child_count_supported: self._exporting_target += int( item['folder']['child_count']) else: self._exporting_target += 1 for item in items: is_folder = 'folder' in item item_id = Utils.str(item['id']) item_name = Utils.unicode(item['name']) item_name_extension = item['name_extension'] file_path = os.path.join(folder_path, item_name) if is_folder: ExportManager.add_item_info(items_info, item_id, item_name, os.path.join(file_path, ''), folder_id) self.__export_folder(driveid, item, folder_path, export, items_info) elif (('video' in item or item_name_extension in self._video_file_extensions) and export['content_type'] == 'video') or ( 'audio' in item and export['content_type'] == 'audio'): item_name += ExportManager._strm_extension file_path += ExportManager._strm_extension ExportManager.create_strm(driveid, item, file_path, export['content_type'], self._addon_url) ExportManager.add_item_info(items_info, item_id, item_name, file_path, folder_id) self._exporting_count += 1 p = int(self._exporting_count / float(self._exporting_target) * 100) if self._exporting_percent < p: self._exporting_percent = p self._export_progress_dialog_bg.update( self._exporting_percent, self._addon_name + ' ' + self._common_addon.getLocalizedString(32024), file_path[len(export['destination_folder']):])
def track_progress(self): Logger.debug('tracking progress started...') monitor = KodiUtils.get_system_monitor() while self.isPlaying(): KodiUtils.set_home_property('dbresume_position', Utils.str(self.getTime())) KodiUtils.set_home_property('dbresume_total', Utils.str(self.getTotalTime())) if monitor.waitForAbort(1): break del monitor Logger.debug('tracking progress finished')
def process_schedules(self, export_map, now, startup=False): Logger.debug('now: %s, startup: %s' % (Utils.str(now), Utils.str(startup))) export_list = [] if startup: export_list.extend( Utils.get_safe_value(export_map, self._startup_type, [])) else: key = 'run_immediately' run_immediately_list = Utils.get_safe_value(export_map, key, []) export_list.extend(run_immediately_list) at = '%02d:%02d' % ( now.hour, now.minute, ) Logger.debug('at: %s' % Utils.str(at)) daily_list = Utils.get_safe_value( export_map, Utils.str(ExportScheduleDialog._daily_type) + at, []) export_list.extend(daily_list) Logger.debug('daily_list: %s' % Utils.str(daily_list)) weekday = now.weekday() + 11 weekday_list = Utils.get_safe_value(export_map, Utils.str(weekday) + at, []) export_list.extend(weekday_list) Logger.debug('weekday_list: %s' % Utils.str(weekday_list)) Logger.debug('export_list: %s' % Utils.str(export_list)) for export in export_list: self.run_export(export)
def on_items_page_completed(self, items): self._load_count += len(items) if self._load_target > self._load_count: percent = int( round(float(self._load_count) / self._load_target * 100)) self._progress_dialog_bg.update( percent, self._addon_name, self._common_addon.getLocalizedString(32047) % (Utils.str(self._load_count), Utils.str(self._load_target))) else: self._progress_dialog_bg.update( 100, self._addon_name, self._common_addon.getLocalizedString(32048) % Utils.str(self._load_count))
def get_item(self, driveid, item_driveid=None, item_id=None, path=None, find_subtitles=False, include_download_info=False): self._provider.configure(self._account_manager, driveid) item_driveid = Utils.default(item_driveid, driveid) cache_key = self._addonid + '-drive-' + driveid + '-item_driveid-' + Utils.str( item_driveid) + '-item_id-' + Utils.str( item_id) + '-path-' + Utils.str(path) f = self._cache.get(cache_key) if not f: if item_id: path = item_id elif path == '/': path = '' self._parameters['path'] = path f = self._provider.post('/files/get_metadata', parameters=self._parameters, headers=self._headers) self._cache.set(cache_key, f, expiration=datetime.timedelta(seconds=59)) item = self._extract_item(f, driveid, include_download_info) if find_subtitles: subtitles = [] parent_path = Utils.get_parent_path(item['path_lower']) if parent_path == '/': parent_path = '' self._parameters['path'] = parent_path self._parameters['query'] = urllib.quote( Utils.remove_extension(item['name'])) self._parameters['mode'] = 'filename' del self._parameters['include_media_info'] files = self._provider.post('/files/search', parameters=self._parameters, headers=self._headers) for f in files['matches']: subtitle = self._extract_item(f['metadata'], driveid, include_download_info) if subtitle['name_extension'] == 'srt' or subtitle[ 'name_extension'] == 'sub' or subtitle[ 'name_extension'] == 'sbv': subtitles.append(subtitle) if subtitles: item['subtitles'] = subtitles Logger.notice(item) return item
def download_item(driveid, item, item_name): item_id = Utils.str(item['id']) item_drive_id = Utils.default(Utils.get_safe_value(item, 'drive_id'), driveid) content = DownloadServiceUtil.build_download_url( driveid, item_drive_id, item_id, item_name) return content
def _list_exports(self, driveid): self._export_manager = ExportManager(self._profile_path) exports = self._export_manager.get_exports() listing = [] for exportid in exports: export = exports[exportid] if export['driveid'] == driveid and export[ 'content_type'] == self._content_type: item_name = Utils.unicode(export['name']) params = { 'action': '_open_export', 'content_type': self._content_type, 'driveid': driveid, 'item_driveid': export['item_driveid'], 'item_id': export['id'], 'name': urllib.parse.quote(Utils.str(item_name)) } url = self._addon_url + '?' + urllib.parse.urlencode(params) list_item = xbmcgui.ListItem(item_name) context_options = [] params['action'] = '_run_export' context_options.append((KodiUtils.localize(21479), 'RunPlugin(' + self._addon_url + '?' + urllib.parse.urlencode(params) + ')')) params['action'] = '_remove_export' context_options.append( (KodiUtils.localize(1210), 'RunPlugin(' + self._addon_url + '?' + urllib.parse.urlencode(params) + ')')) list_item.addContextMenuItems(context_options) listing.append((url, list_item, True)) xbmcplugin.addDirectoryItems(self._addon_handle, listing, len(listing)) xbmcplugin.endOfDirectory(self._addon_handle, True)
def get_item(self, driveid, item_driveid=None, item_id=None, path=None, find_subtitles=False, include_download_info=False): self._provider.configure(self._account_manager, driveid) item_driveid = Utils.default(item_driveid, driveid) cache_key = self._addonid+'-drive-'+driveid+'-item_driveid-'+Utils.str(item_driveid)+'-item_id-'+Utils.str(item_id)+'-path-'+Utils.str(path) f = self._cache.get(cache_key) if not f : if item_id: f = self._provider.get('/drives/'+item_driveid+'/items/' + item_id, parameters = self._extra_parameters) elif path == 'sharedWithMe' or path == 'recent': return else: if path == '/': path = 'root' else: parts = path.split('/') if len(parts) > 1 and not parts[0]: path = 'root:'+path+':' f = self._provider.get('/drives/'+driveid+'/' + path, parameters = self._extra_parameters) self._cache.set(cache_key, f, expiration=datetime.timedelta(seconds=59)) item = self._extract_item(f, include_download_info) if find_subtitles: subtitles = [] parent_id = Utils.get_safe_value(Utils.get_safe_value(f, 'parentReference', {}), 'id') search_url = '/drives/'+item_driveid+'/items/' + parent_id + '/search(q=\'{'+urllib.quote(Utils.remove_extension(item['name']))+'}\')' files = self._provider.get(search_url) for f in files['value']: subtitle = self._extract_item(f, include_download_info) if subtitle['name_extension'] == 'srt' or subtitle['name_extension'] == 'sub' or subtitle['name_extension'] == 'sbv': subtitles.append(subtitle) if subtitles: item['subtitles'] = subtitles return item
def saveProgress(self): dbid = KodiUtils.get_home_property('dbid') addonid = KodiUtils.get_home_property('addonid') if addonid and addonid == self.addonid: if dbid: Logger.debug('ok to save dbid: ' + dbid) dbtype = KodiUtils.get_home_property('dbtype') position = KodiUtils.get_home_property('dbresume_position') total = KodiUtils.get_home_property('dbresume_total') if dbtype and position and total: position = float(position) total = float(total) percent = position / total * 100 details = {} Logger.debug('position is %d of %d = %d percent' % (position, total, percent)) if percent >= 90: position = 0 total = 0 details['resume'] = {'position': 0, 'total': 0} details['lastplayed'] = KodiUtils.to_db_date_str( datetime.datetime.today()) details['playcount'] = int( KodiUtils.get_home_property('playcount')) + 1 elif position > 180: details['resume'] = { 'position': position, 'total': total } if details: Logger.debug( KodiUtils.save_video_details( dbtype, dbid, details)) Logger.debug('details saved to db - %s: %s' % (dbid, Utils.str(details)))
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 get_item(self, driveid, item_driveid=None, item_id=None, path=None, find_subtitles=False, include_download_info=False): self._provider.configure(self._account_manager, driveid) item_driveid = Utils.default(item_driveid, driveid) cache_key = self._addonid+'-drive-'+driveid+'-item_driveid-'+Utils.str(item_driveid)+'-item_id-'+Utils.str(item_id)+'-path-'+Utils.str(path) f = self._cache.get(cache_key) if f: item = self._extract_item(f, include_download_info) else: cache_key = self._addonid+'-drive-None-item_driveid-None-item_id-None-path-'+path f = self._cache.get(cache_key) if f: item = self._extract_item(f, include_download_info) else: self._parameters['fields'] = self._file_fileds if not item_id and path == '/': item_id = 'root' if item_id: f = self._provider.get('/files/%s' % item_id, parameters = self._parameters) self._cache.set(cache_key, f, expiration=datetime.timedelta(seconds=59)) item = self._extract_item(f, include_download_info) else: item = self.get_item_by_path(path, include_download_info) if find_subtitles: subtitles = [] self._parameters['q'] = 'name contains \'%s\'' % urllib.quote(Utils.remove_extension(item['name'])) files = self._provider.get('/files', parameters = self._parameters) for f in files['files']: subtitle = self._extract_item(f, include_download_info) if subtitle['name_extension'] == 'srt' or subtitle['name_extension'] == 'sub' or subtitle['name_extension'] == 'sbv': subtitles.append(subtitle) if subtitles: item['subtitles'] = subtitles return item
def get_item_by_path(self, path, include_download_info=False): parameters = self.prepare_parameters() if path[-1:] == '/': path = path[:-1] Logger.debug(path + ' <- Target') key = '%s%s' % (self._driveid, path,) Logger.debug('Testing item from cache: %s' % key) item = self._items_cache.get(key) if not item: parameters['fields'] = 'files(%s)' % self._get_field_parameters() index = path.rfind('/') filename = urllib.unquote(path[index+1:]) parent = path[0:index] if not parent: parent = 'root' else: parent = self.get_item_by_path(parent, include_download_info)['id'] item = None parameters['q'] = '\'%s\' in parents and name = \'%s\'' % (Utils.str(parent), Utils.str(filename).replace("'","\\'")) files = self.get('/files', parameters = parameters) if (len(files['files']) > 0): for f in files['files']: item = self._extract_item(f, include_download_info) break else: Logger.debug('Found in cache.') if not item: raise RequestException('Not found by path', HTTPError(path, 404, 'Not found', None, None), 'Request URL: %s' % path, None) else: self._items_cache.set(key, item) return item
def get_folder_items(self, driveid, path): provider = self._get_provider() provider.configure(self._account_manager, driveid) cache_path = path[:len(path)-1] request_path = cache_path if len(path) > 1 else path self.is_path_possible(driveid, request_path) key = '%s%s:items' % (driveid, cache_path,) items = self._items_cache.get(key) if not items and type(items) is NoneType: items = provider.get_folder_items(path=request_path, include_download_info=True) self._items_cache.set(key, items) children_names = [] cache_items = [] for item in items: quoted_name = urllib.quote(Utils.str(item['name'])) children_names.append(quoted_name) key = '%s%s%s' % (driveid, path, quoted_name,) Logger.debug('Adding item in cache for bulk: %s' % key) cache_items.append([key, item]) self._items_cache.setmany(cache_items) Logger.debug('Cache in bulk saved') key = '%s%s:children' % (driveid, cache_path,) Logger.debug('saving children names for: ' + key) self._children_cache.set(key, children_names) else: Logger.debug('items for %s served from cache' % path) return items
def get_item(self, item_driveid=None, item_id=None, path=None, find_subtitles=False, include_download_info=False): parameters = copy.deepcopy(self._default_parameters) item_driveid = Utils.default(item_driveid, self._driveid) parameters['fields'] = self._file_fileds if not item_id and path == '/': item_id = 'root' if item_id: f = self.get('/files/%s' % item_id, parameters=parameters) item = self._extract_item(f, include_download_info) else: item = self.get_item_by_path(path, include_download_info) if find_subtitles: subtitles = [] parameters['fields'] = 'files(' + self._file_fileds + ')' parameters['q'] = 'name contains \'%s\'' % Utils.str( Utils.remove_extension(item['name'])).replace("'", "\\'") files = self.get('/files', parameters=parameters) for f in files['files']: subtitle = self._extract_item(f, include_download_info) if subtitle['name_extension'] == 'srt' or subtitle[ 'name_extension'] == 'sub' or subtitle[ 'name_extension'] == 'sbv': subtitles.append(subtitle) if subtitles: item['subtitles'] = subtitles return item
def get_driveid(self, drive_name): driveid = None drives = self.get_drive_list() for drive in drives: if urllib.quote(Utils.str(drive['display_name'])) == drive_name: driveid = drive['id'] break return driveid
def get_addonid(self, addon_name): addons = self.get_cloud_drive_addons() addonid = None for addon in addons: if urllib.quote(Utils.str(addon['name'])) == addon_name: addonid = addon['addonid'] break return addonid
def show_addon_list(self): html, table = self.open_table('Index of /') for addon in self.get_cloud_drive_addons(): self.add_row(table, Utils.str(addon['name']) + '/') self.close_table(table) response = Utils.get_file_buffer() response.write(str(html)) self.write_response(200, content=response)
def create_text_file(file_path, content): try: with KodiUtils.file(file_path, 'w') as f: f.write(Utils.str(content)) except Exception as e: ErrorReport.handle_exception(e) return False return True
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(self._get_item_play_url(urllib.quote(Utils.str(subtitle['name'])), driveid, Utils.default(Utils.get_safe_value(subtitle, 'drive_id'), driveid), subtitle['id'], True)) list_item.setSubtitles(subtitles) if not self.cancel_operation(): xbmcplugin.setResolvedUrl(self._addon_handle, succeeded, list_item)
def show_drives(self, addon_name): html, table = self.open_table('Index of /'+addon_name+'/') self.add_row(table, '../') drives = self.get_drive_list() for drive in drives: self.add_row(table, Utils.str(drive['display_name']) + '/') self.close_table(table) response = Utils.get_file_buffer() response.write(str(html)) return {'response_code': 200, 'content': response}
def __init__(self, provider_class): self.abort = False self._system_monitor = KodiUtils.get_system_monitor() self.provider = provider_class() self.addonid = KodiUtils.get_addon_info('id') self._profile_path = Utils.unicode(KodiUtils.translate_path(KodiUtils.get_addon_info('profile'))) self._startup_type = Utils.str(ExportScheduleDialog._startup_type) self.export_manager = ExportManager(self._profile_path) self._account_manager = AccountManager(self._profile_path) self._video_file_extensions = KodiUtils.get_supported_media("video") self._audio_file_extensions = KodiUtils.get_supported_media("music")
def get_export_map(self): exports = self.export_manager.load() export_map = {} for exportid in exports: export = exports[exportid] schedules = Utils.get_safe_value(export, 'schedules', []) exporting = Utils.get_safe_value(export, 'exporting', False) if not exporting: if Utils.get_safe_value(export, 'schedule', False) and schedules: for schedule in schedules: key = Utils.str(Utils.get_safe_value(schedule, 'type', '')) if key != self._startup_type: key += Utils.get_safe_value(schedule, 'at', '') export_map[key] = Utils.get_safe_value(export_map, key, []) export_map[key].append(export) if Utils.get_safe_value(export, 'watch', False): export_map['watch'] = Utils.get_safe_value(export_map, 'watch', []) export_map['watch'].append(export) Logger.debug('export_map: %s' % Utils.str(export_map)) return export_map
def get_subtitles(self, parent, name, item_driveid=None, include_download_info=False): parameters = self.prepare_parameters() item_driveid = Utils.default(item_driveid, self._driveid) subtitles = [] parameters['fields'] = 'files(' + self._get_field_parameters() + ')' parameters['q'] = 'name contains \'%s\'' % Utils.str(Utils.remove_extension(name)).replace("'","\\'") files = self.get('/files', parameters = parameters) for f in files['files']: subtitle = self._extract_item(f, include_download_info) if subtitle['name_extension'].lower() in ('srt','idx','sub','sbv','ass','ssa'): subtitles.append(subtitle) return subtitles