diff --git a/addon.py b/addon.py index 6e055c3..a576b4b 100644 --- a/addon.py +++ b/addon.py @@ -89,7 +89,7 @@ def search(self, query, driveid, item_driveid=None, item_id=None, on_items_page_ url += item_driveid+'/items/' + item_id else: url += driveid - url += '/search(q=\''+urllib.quote(query)+'\')' + url += '/search(q=\''+urllib.quote(Utils.str(query))+'\')' self._extra_parameters['filter'] = 'file ne null' files = self._provider.get(url, parameters = self._extra_parameters) if self.cancel_operation(): @@ -101,7 +101,7 @@ def process_files(self, driveid, files, on_items_page_completed=None): for f in files['value']: f = Utils.get_safe_value(f, 'remoteItem', f) item = self._extract_item(f) - cache_key = self._addonid+'-drive-'+driveid+'-item_driveid-'+item['drive_id']+'-item_id-'+item['id']+'-path-None' + cache_key = self._addonid+'-drive-'+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: @@ -114,10 +114,11 @@ def process_files(self, driveid, files, on_items_page_completed=None): return items def _extract_item(self, f, include_download_info=False): + name = Utils.get_safe_value(f, 'name', '') item = { 'id': f['id'], - 'name': f['name'], - 'name_extension' : Utils.get_extension(f['name']), + 'name': name, + 'name_extension' : Utils.get_extension(name), 'drive_id' : Utils.get_safe_value(Utils.get_safe_value(f, 'parentReference', {}), 'driveId'), 'mimetype' : Utils.get_safe_value(Utils.get_safe_value(f, 'file', {}), 'mimeType'), 'last_modified_date' : Utils.get_safe_value(f,'lastModifiedDateTime'), @@ -183,7 +184,7 @@ def get_item(self, driveid, item_driveid=None, item_id=None, path=None, find_sub 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']))+'}\')' + search_url = '/drives/'+item_driveid+'/items/' + parent_id + '/search(q=\''+urllib.quote(Utils.str(Utils.remove_extension(item['name'])).replace("'","''"))+'\')' files = self._provider.get(search_url) for f in files['value']: subtitle = self._extract_item(f, include_download_info) @@ -194,9 +195,12 @@ def get_item(self, driveid, item_driveid=None, item_id=None, path=None, find_sub return item def _rename_action(self): + if self._action == 'open_drive_folder': + self._addon_params['path'] = Utils.get_safe_value(self._addon_params, 'folder') self._action = Utils.get_safe_value({ 'open_folder': '_list_folder', 'open_drive': '_list_drive', + 'open_drive_folder': '_list_folder' }, self._action, self._action) if __name__ == '__main__': diff --git a/addon.xml b/addon.xml index c34a3aa..ebe5b89 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -35,6 +35,8 @@ Play all your media from OneDrive including Videos, Music and Pictures. https://github.com/cguZZman/plugin.onedrive/issues https://addons.kodi.tv/show/plugin.onedrive +v2.0.1 released Nov 30, 2017: +- Bug fixes v2.0.0 released Nov 06, 2017: - Remake using script.module.clouddrive.common library - Fix OneDrive for Business functionality diff --git a/resources/lib/provider/onedrive.py b/resources/lib/provider/onedrive.py index 286101d..9144b19 100644 --- a/resources/lib/provider/onedrive.py +++ b/resources/lib/provider/onedrive.py @@ -19,6 +19,8 @@ from clouddrive.common.remote.provider import Provider from clouddrive.common.utils import Utils +from clouddrive.common.exception import RequestException, ExceptionUtils +from urllib2 import HTTPError class OneDrive(Provider): @@ -40,17 +42,22 @@ def get_account(self, request_params={}, access_tokens={}): return { 'id' : me['id'], 'name' : me['displayName']} def get_drives(self, request_params={}, access_tokens={}): - response = self.get('/drives', request_params=request_params, access_tokens=access_tokens) drives = [] drives_id_list =[] - for drive in response['value']: - drives_id_list.append(drive['id']) - drives.append({ - 'id' : drive['id'], - 'name' : Utils.get_safe_value(drive, 'name', ''), - 'type' : drive['driveType'] - }) - + try: + response = self.get('/drives', request_params=request_params, access_tokens=access_tokens) + for drive in response['value']: + drives_id_list.append(drive['id']) + drives.append({ + 'id' : drive['id'], + 'name' : Utils.get_safe_value(drive, 'name', ''), + 'type' : drive['driveType'] + }) + except RequestException as ex: + httpex = ExceptionUtils.extract_exception(ex, HTTPError) + if not httpex or httpex.code != 403: + raise ex + response = self.get('/me/drives', request_params=request_params, access_tokens=access_tokens) for drive in response['value']: if not drive['id'] in drives_id_list: