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_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(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_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
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 get_bookmarks(self, parent, name, item_driveid=None, include_download_info=False): parameters = self.prepare_parameters() item_driveid = Utils.default(item_driveid, self._driveid) bookmarks = [] 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']: bookmark = self._extract_item(f, include_download_info) if bookmark['name_extension'].lower() in ('jpg', 'png'): bookmarks.append(bookmark) return bookmarks
def get_subtitles(self, parent, name, item_driveid=None, include_download_info=False): item_driveid = Utils.default(item_driveid, self._driveid) subtitles = [] search_url = '/drives/' + item_driveid + '/items/' + parent + '/search(q=\'' + urllib.quote( Utils.str(Utils.remove_extension(name)).replace("'", "''")) + '\')' files = self.get(search_url) for f in files['value']: subtitle = self._extract_item(f, include_download_info) if subtitle['name_extension'].lower() in ('srt', 'idx', 'sub', 'sbv', 'ass', 'ssa', 'smi'): subtitles.append(subtitle) return subtitles
def process_change_create(self, change, items_info, export): content_type = export['content_type'] changed_item_id = change['id'] changed_item_name = Utils.get_safe_value(change, 'name', '') changed_item_extension = Utils.get_safe_value(change, 'name_extension', '') parent_id = Utils.get_safe_value(change, 'parent', '') is_folder = 'folder' in change item_type = 'folder' if is_folder else 'file' parent_item_info = Utils.get_safe_value(items_info, parent_id) if parent_item_info: parent_item_path = parent_item_info['full_local_path'] new_path = os.path.join(Utils.unicode(parent_item_path), Utils.unicode(changed_item_name)) change_type = 'create' if is_folder: change_type += '_folder' new_path = os.path.join(new_path, '') if parent_id == 'root-folder' and KodiUtils.get_addon_setting( 'clean_folder') == 'true' and KodiUtils.file_exists( new_path): if not Utils.remove_folder(new_path): error = self._common_addon.getLocalizedString( 32066) % new_path KodiUtils.show_notification(error) Logger.debug(error) if not KodiUtils.file_exists(new_path): Logger.debug('creating folder: %s' % (new_path, )) if not KodiUtils.mkdir(new_path): change_type += '_retry' Logger.debug('unable to create folder %s' % (new_path, )) else: change_type += '_ignored' Logger.debug('folder %s already exists' % (new_path, )) else: download_artwork = 'download_artwork' in export and export[ 'download_artwork'] is_download = changed_item_extension \ and ( changed_item_extension in ['strm', 'nomedia'] or ( download_artwork and ( changed_item_extension in ['nfo'] or ( changed_item_extension in ['jpg', 'png'] and ( any(s in changed_item_name for s in self._artwork_file_extensions) or parent_item_info['name'] in ['.actors', 'extrafanart'] ) ) ) ) ) if is_download: Logger.debug('downloading file: %s' % (new_path, )) change_type = 'download_file' cloud_size = Utils.get_safe_value(change, 'size', 0) local_size = KodiUtils.file(new_path).size() if cloud_size != local_size: Logger.debug( 'Download requested. File changed: Local file size (%s) - cloud file size (%s)' % ( Utils.str(local_size), Utils.str(cloud_size), )) if not ExportManager.download(change, new_path, self.provider): change_type += "_retry" Logger.debug('Unable to download file: %s' % (new_path, )) else: change_type += '_ignored' Logger.debug( 'Download ignored: Local file size (%s) is equal to cloud file size (%s)' % ( Utils.str(local_size), Utils.str(cloud_size), )) else: is_stream_file = (('video' in change or (changed_item_extension and changed_item_extension in self._video_file_extensions)) and content_type == 'video') \ or (('audio' in change or (changed_item_extension and changed_item_extension in self._audio_file_extensions)) and content_type == 'audio') if is_stream_file: change_type += '_file' if KodiUtils.get_addon_setting( 'no_extension_strm') == 'true': new_path = Utils.remove_extension(new_path) new_path += ExportManager._strm_extension strm_content = ExportManager.get_strm_link( export['driveid'], change, content_type, 'plugin://%s/' % self.addonid) Logger.debug('creating strm file: %s' % (new_path, )) if not KodiUtils.file_exists( new_path) or KodiUtils.file( new_path).size() != len(strm_content): if not ExportManager.create_text_file( new_path, strm_content): change_type += '_retry' else: change_type += '_ignored' Logger.debug( 'ignoring strm creation: %s, strm file already exists. same expected size.' % (new_path, )) else: change_type = None Logger.debug('ignoring file: %s' % (new_path, )) if change_type: ExportManager.add_item_info(items_info, changed_item_id, Utils.unicode(changed_item_name), new_path, parent_id, item_type) else: Logger.debug('invalid state. no parent info found') change_type = None return change_type
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