def catch_all(path): if path.startswith("audio1.html"): files = request.args["data"].split(",") folder = request.args["folder"] info = {'files': files, 'folder': folder} return render_template('audio1.html', info=info, path=path_format(path).strip('/')) info = od.list_items_with_cache( path_format(config.start_directory + '/' + path)) if info.is_file: file_extension = os.path.splitext(path)[1][1:] if file_extension in ['webm', 'mkv', 'mp4']: return render_template('video5.html', info=info, path=path_format(path).strip('/')) # if file_extension in ['avi', 'mpg', 'mpeg', 'rm', 'rmvb', 'mov', 'wmv', 'asf', 'ts', 'flv']: # return render_template('video2.html', info=info, path=path_format(path).strip('/')) if file_extension in ['ogg', 'mp3', 'wav', 'flac']: if request.args: return info.files[0]['download_url'] return render_template('audio.html', info=info, path=path_format(path).strip('/')) return redirect(info.files[0]['download_url']) if info.files.__len__() > 0: info.files = sorted(info.files, key=lambda x: x["updated_at"], reverse=True) return render_template('list.html', info=info, path=path_format(path).strip('/'))
def catch_all(path): info = od.list_items_with_cache( path_format(config.start_directory + '/' + path) ) if info.is_file: # download return redirect(info.files[0]['download_url']) return render_template('list.html', info=info, path=path_format(path).strip('/'))
def list_items(self, path='/'): url = '%s/drive/root:%s/?expand=children(select=name,size,file,folder,parentReference,lastModifiedDateTime)' % ( self.api_url, parse.quote(path_format(path))) res = self._http_request(url) info = _ItemInfo() self._append_item(info, res) if 'children' in res: for children in res['children']: self._append_item(info, children) if info.files and not info.folders: info.is_file = True return info
def list_items_with_cache(self, path='/', flash=False): path = path_format(path) key = ('tmp:' + path) if flash else path if not Cache.has(key): if flash: Cache.set(key, self.list_items(path), 10) else: print('missing: %s' % path) info = self.list_items(path) if info.is_file: Cache.set(key, info, config.metadata_cached_seconds) else: Cache.set(key, info, config.structure_cached_seconds) return Cache.get(key)
def list_items(self, path=''): url = '%s/drive/root?$expand=children' % (self.api_url) if len(path) > 1: url = '%s/drive/root:/%s?$expand=children' % ( self.api_url, parse.quote(path_format(path))) res = self._http_request(url) info = _ItemInfo() self._append_item(info, res) if 'children' in res: for children in res['children']: self._append_item(info, children) if info.files and not info.folders: info.is_file = True return info
def _append_item(self, info, item): if 'path' not in item['parentReference']: path = item['name'] = '/' else: path = item['parentReference']['path'][12:] or '/' dic = { 'name': item['name'], 'size': item['size'], 'hash': self._get_item_hash(item), 'folder': path, 'full_path': path_format(path + '/' + item['name']), 'updated_at': item['lastModifiedDateTime'] } if '@content.downloadUrl' in item: dic['download_url'] = item['@content.downloadUrl'] if 'file' in item: info.files.append(dic) else: info.folders.append(dic)