Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Guzman committed Dec 1, 2017
1 parent b09dd2e commit 552360c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
14 changes: 9 additions & 5 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand All @@ -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'),
Expand Down Expand Up @@ -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)
Expand All @@ -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__':
Expand Down
4 changes: 3 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.onedrive" name="OneDrive" version="2.0.0" provider-name="Carlos Guzman (cguZZman)">
<addon id="plugin.onedrive" name="OneDrive" version="2.0.1" provider-name="Carlos Guzman (cguZZman)">
<requires>
<import addon="xbmc.python" version="2.25.0" />
<import addon="script.module.clouddrive.common"/>
Expand Down Expand Up @@ -35,6 +35,8 @@ Play all your media from OneDrive including Videos, Music and Pictures.
<forum>https://github.com/cguZZman/plugin.onedrive/issues</forum>
<website>https://addons.kodi.tv/show/plugin.onedrive</website>
<news>
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
Expand Down
25 changes: 16 additions & 9 deletions resources/lib/provider/onedrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit 552360c

Please sign in to comment.