| |
---|
| | |
---|
| | |
---|
| | |
---|
| | # Function to list media files |
---|
| | def list_media_files(directories): |
---|
| | def list_media_files(socketio, directories): |
---|
| | media_files = [] |
---|
| | for directory in directories: |
---|
| | if os.path.exists(directory): |
---|
| | for root, _, files in os.walk(directory): |
---|
| | for file in files: |
---|
| | for inx, file in enumerate(files): |
---|
| | file_path = os.path.join(root, file) |
---|
| | |
---|
| | if not inx or not inx % 50: |
---|
| | socketio.emit("medialib-scaning-process", { |
---|
| | "message": f"Scaning: { directory }" |
---|
| | }) |
---|
| | try: |
---|
| | file_info = { |
---|
| | "name": file, |
---|
| | "path": file_path, |
---|
| |
---|
| | |
---|
| | |
---|
| | def bg_scan_medialib(socketio, config, GStorage): |
---|
| | GStorage["scaning_state"] = "inprogress"; |
---|
| | media_files = list_media_files(config.get("directories", [])) |
---|
| | media_files = list_media_files(socketio, config.get("directories", [])) |
---|
| | |
---|
| | allowed_formats = config.get("allowed_formats", []) |
---|
| | socketio.emit("medialib-scaning-process", { |
---|
| | "message": f"Filtering by file extension..." |
---|
| | }) |
---|
| | filtered_files = filter_media_files(media_files, allowed_formats) |
---|
| | |
---|
| | socketio.emit("medialib-scaning-process", { |
---|
| | "message": f"Adding media file detail..." |
---|
| | }) |
---|
| | |
---|
| | # Add detailed media info |
---|
| | for file in filtered_files: |
---|
| | file["size"], file["size_unit"], file["size_bytes"] = human_readable_size(file["size"]) |
---|
| | socketio.emit("medialib-scaning-process", { |
---|
| | "message": f"Adding detail: { file["path"] }" |
---|
| | }) |
---|
| | file_info = get_media_info_with_ffprobe(file["path"]) |
---|
| | if file_info: |
---|
| | file["info"] = file_info |
---|
| | else: |
---|
| | file["info"] = {"error": "Failed to retrieve media info"} |
---|
| | |
---|
| | GStorage["scaning_state"] = "inaction" |
---|
| | |
---|
| | socketio.emit("medialib-scaning-process", { |
---|
| | "message": f"Creating cache..." |
---|
| | }) |
---|
| | media_create_cache(config["cache_dir"], filtered_files) |
---|
| | |
---|
| | socketio.emit("medialib-scaning-complete", { |
---|
| | "data": filtered_files |
---|
| |
---|
| | |