Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster strm exports #320

Open
wants to merge 1 commit into
base: matrix
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions resources/lib/provider/googledrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def __init__(self, source_mode = False):
super(GoogleDrive, self).__init__('googledrive', source_mode)
self.download_requires_auth = True
self._items_cache = Cache(KodiUtils.get_addon_info('id'), 'items', datetime.timedelta(minutes=KodiUtils.get_cache_expiration_time()))

self._instance_cache = {}

def configure(self, account_manager, driveid):
super(GoogleDrive, self).configure(account_manager, driveid)
drive = account_manager.get_by_driveid('drive', driveid)
Expand Down Expand Up @@ -153,7 +154,44 @@ def get_folder_items(self, item_driveid=None, item_id=None, path=None, on_items_
parameters = {'albumId': item_id}
provider_method = self._photos_provider.post
url = '/mediaItems:search'


if url == '/files' and item_id and include_download_info:
if not item_id in self._instance_cache:
self._instance_cache[item_id] = []
ids_per_batch = 120
id_batch = [item_id]
original_params = {k:v for k,v in parameters.items()}
while id_batch:
query = ['trashed=false', 'and']
batch = id_batch[:ids_per_batch]
for idx, _id in enumerate(batch, start=1):
q = '\'%s\' in parents' % _id
if idx == 1:
q = '(' + q
if idx == len(batch):
q = q + ')'
query.append(q)
if idx != len(batch):
query.append('or')
parameters['q'] = ' '.join(query)
id_batch = id_batch[ids_per_batch:]
response = provider_method(url, parameters = parameters)
files = self.process_files(response, parameters, on_items_page_completed, include_download_info, on_before_add_item=on_before_add_item)
if self.cancel_operation():
return
parameters = original_params.copy()
for file in files:
file_mimeType = file['mimetype']
file_id = file['id']
parent_id = file['parent']
if file_mimeType == 'application/vnd.google-apps.folder':
id_batch.append(file_id)
self._instance_cache[file_id] = []
if parent_id in self._instance_cache:
self._instance_cache[parent_id].append(file)
items.extend(self._instance_cache[item_id])
return items

files = provider_method(url, parameters = parameters)
if self.cancel_operation():
return
Expand Down