Add bundle function
This commit is contained in:
parent
8f6a42f8b4
commit
6fe89af3cc
@ -40,6 +40,14 @@ python3 -m karaokatalog.ui.serve $SONG_LIBRARY
|
||||
|
||||
To speed up the start, use jsonification to create and persist a JSON of all songs in the library root dir before starting this UI.
|
||||
|
||||
#### Bundle
|
||||
|
||||
**Create a bundle `.zip` file containg web app and data** that can be uploaded to any web hoster that can host static files.
|
||||
|
||||
```bash
|
||||
python3 -m karaokatalog.ui.bundle $SONG_LIBRARY
|
||||
```
|
||||
|
||||
### Deduplication
|
||||
|
||||
**Find and delete exactly duplicated songs**, i.e., songs with the same title and artist that also consist of exactly the same files in the directory.
|
||||
|
||||
0
karaokatalog/ui/bundle/__init__.py
Normal file
0
karaokatalog/ui/bundle/__init__.py
Normal file
47
karaokatalog/ui/bundle/__main__.py
Normal file
47
karaokatalog/ui/bundle/__main__.py
Normal file
@ -0,0 +1,47 @@
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
from karaokatalog.get_parser import get_parser
|
||||
from karaokatalog.Library import Library
|
||||
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s [%(levelname)s] %(message)s", level=logging.INFO
|
||||
)
|
||||
|
||||
STATIC_DIR = Path(__file__).parent.parent / "static"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = get_parser(
|
||||
"ui.bundle",
|
||||
"Create a bundle ZIP containing the Karaokatalog web app and all data which can be uploaded to a static web server.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
"--out-path",
|
||||
type=Path,
|
||||
default=Path("./karaokatalog.zip"),
|
||||
help="The path at which the output ZIP file should be stored",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
with ZipFile(args.out_path, "w") as out_zip:
|
||||
for file_path in STATIC_DIR.rglob("*"):
|
||||
relative_path = file_path.relative_to(STATIC_DIR)
|
||||
out_zip.write(file_path, relative_path)
|
||||
|
||||
songs_json_path = args.library_path / "songs.json"
|
||||
|
||||
if songs_json_path.exists():
|
||||
logging.info(f"Using existing songs.json at {songs_json_path}")
|
||||
out_zip.write(songs_json_path, "songs.json")
|
||||
else:
|
||||
logging.info("Loading library")
|
||||
library = Library.from_dir(args.library_path)
|
||||
logging.info("Library loaded")
|
||||
|
||||
songs = [song.as_dict() for song in library.songs]
|
||||
songs_json = json.dumps(songs, ensure_ascii=False, indent=4)
|
||||
out_zip.writestr("songs.json", songs_json)
|
||||
Loading…
x
Reference in New Issue
Block a user