Exemplo n.º 1
0
 def _process_items(self, items, driveid):
     listing = []
     for item in items:
         item_id = item['id']
         item_name = Utils.unicode(item['name'])
         item_name_extension = item['name_extension']
         item_driveid = Utils.default(Utils.get_safe_value(item, 'drive_id'), driveid)
         list_item = xbmcgui.ListItem(item_name)
         url = None
         is_folder = 'folder' in item
         params = {'content_type': self._content_type, 'item_driveid': item_driveid, 'item_id': item_id, 'driveid': driveid}
         if 'extra_params' in item:
             params.update(item['extra_params'])
         context_options = []
         info = {'size': item['size'], 'date': KodiUtils.to_kodi_item_date_str(KodiUtils.to_datetime(Utils.get_safe_value(item, 'last_modified_date')))}
         if is_folder:
             params['action'] = '_list_folder'
             url = self._addon_url + '?' + urllib.urlencode(params)
             params['action'] = '_search'
             cmd = 'ActivateWindow(%d,%s?%s)' % (xbmcgui.getCurrentWindowId(), self._addon_url, urllib.urlencode(params))
             context_options.append((self._common_addon.getLocalizedString(32039), cmd))
             if self._content_type == 'audio' or self._content_type == 'video':
                 params['action'] = '_open_export'
                 params['name'] = urllib.quote(Utils.str(item_name))
                 context_options.append((self._common_addon.getLocalizedString(32004), 'RunPlugin('+self._addon_url + '?' + urllib.urlencode(params)+')'))
                 del params['name']
             elif self._content_type == 'image' and self._auto_refreshed_slideshow_supported:
                 params['action'] = '_slideshow'
                 context_options.append((self._common_addon.getLocalizedString(32032), 'RunPlugin('+self._addon_url + '?' + urllib.urlencode(params)+')'))
         elif (('video' in item or item_name_extension in self._video_file_extensions) and self._content_type == 'video') or (('audio' in item or item_name_extension in self._audio_file_extensions) and self._content_type == 'audio'):
             list_item.setProperty('IsPlayable', 'true')
             params['action'] = 'play'
             url = self._addon_url + '?' + urllib.urlencode(params)
             info_type = self._content_type
             if 'audio' in item:
                 info.update(item['audio'])
                 info_type = 'music'
             elif 'video' in item:
                 list_item.addStreamInfo('video', item['video'])
             list_item.setInfo(info_type, info)
             if 'thumbnail' in item:
                 list_item.setArt({'icon': item['thumbnail'], 'thumb': item['thumbnail']})
         elif ('image' in item or item_name_extension in self._image_file_extensions) and self._content_type == 'image' and item_name_extension != 'mp4':
             if 'url' in item:
                 url = item['url']
             else:
                 url = self._get_item_play_url(urllib.quote(Utils.str(item_name)), driveid, item_driveid, item_id)
             if 'image' in item:
                 info.update(item['image'])
             list_item.setInfo('pictures', info)
             if 'thumbnail' in item and item['thumbnail']:
                 list_item.setArt({'icon': item['thumbnail'], 'thumb': item['thumbnail']})
         if url:
             context_options.extend(self.get_context_options(list_item, params, is_folder))
             list_item.addContextMenuItems(context_options)
             mimetype = Utils.default(Utils.get_mimetype_by_extension(item_name_extension), Utils.get_safe_value(item, 'mimetype'))
             if mimetype:
                 list_item.setProperty('mimetype', mimetype)
             
             listing.append((url, list_item, is_folder))
     xbmcplugin.addDirectoryItems(self._addon_handle, listing, len(listing))
     xbmcplugin.endOfDirectory(self._addon_handle, True)
Exemplo n.º 2
0
 def _extract_item(self, f, include_download_info=False):
     kind = Utils.get_safe_value(f, 'kind', '')
     if kind == 'drive#change':
         if 'file' in f:
             f = f['file']
         else:
             return {}
     size = long('%s' % Utils.get_safe_value(f, 'size', 0))
     is_album = kind == 'album'
     is_media_items = kind == 'media_item'
     item_id = f['id']
     if is_album:
         mimetype = 'application/vnd.google-apps.folder'
         name = Utils.get_safe_value(f, 'title', item_id)
     else:
         mimetype = Utils.get_safe_value(f, 'mimeType', '')
         name = Utils.get_safe_value(f, 'name', '')
     if is_media_items:
         name = Utils.get_safe_value(f, 'filename', item_id) 
     item = {
         'id': item_id,
         'name': name,
         'name_extension' : Utils.get_extension(name),
         'parent': Utils.get_safe_value(f, 'parents', ['root'])[0],
         'drive_id' : Utils.get_safe_value(Utils.get_safe_value(f, 'owners', [{}])[0], 'permissionId'),
         'mimetype' : mimetype,
         'last_modified_date' : Utils.get_safe_value(f,'modifiedTime'),
         'size': size,
         'description': Utils.get_safe_value(f, 'description', ''),
         'deleted' : Utils.get_safe_value(f, 'trashed', False)
     }
     if item['mimetype'] == 'application/vnd.google-apps.folder':
         item['folder'] = {
             'child_count' : 0
         }
     if is_media_items:
         item['url'] = f['baseUrl'] + '=d'
         if 'mediaMetadata' in f:
             metadata = f['mediaMetadata']
             item['video'] = {
                 'width' : Utils.get_safe_value(metadata, 'width'),
                 'height' : Utils.get_safe_value(metadata, 'height')
             }
             item['last_modified_date'] = Utils.get_safe_value(metadata, 'creationTime')
     if 'videoMediaMetadata' in f:
         video = f['videoMediaMetadata']
         item['video'] = {
             'width' : Utils.get_safe_value(video, 'width'),
             'height' : Utils.get_safe_value(video, 'height'),
             'duration' : long('%s' % Utils.get_safe_value(video, 'durationMillis', 0)) / 1000
         }
     if 'imageMediaMetadata' in f or 'mediaMetadata' in f:
         item['image'] = {
             'size' : size
         }
     if 'hasThumbnail' in f and f['hasThumbnail']:
         item['thumbnail'] = Utils.get_safe_value(f, 'thumbnailLink')
     if is_album:
         item['thumbnail'] = Utils.get_safe_value(f, 'coverPhotoBaseUrl')
         item['id'] = 'album-' + item['id']
     if include_download_info:
         if is_media_items:
             item['download_info'] =  {
                 'url' : item['url']
             }
         else:
             parameters = {
                 'alt': 'media',
                 'access_token': self.get_access_tokens()['access_token']
             }
             url = self._get_api_url() + '/files/%s' % item['id']
             if 'size' not in f and item['mimetype'] == 'application/vnd.google-apps.document':
                 url += '/export'
                 parameters['mimeType'] = Utils.default(Utils.get_mimetype_by_extension(item['name_extension']), Utils.get_mimetype_by_extension('pdf'))
             item['download_info'] =  {
                 'url' : url + '?%s' % urllib.urlencode(parameters)
             }
     return item