-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_spotify.py
More file actions
47 lines (38 loc) · 1.67 KB
/
Copy pathimport_spotify.py
File metadata and controls
47 lines (38 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Curatarr — Spotify History Importer (CLI wrapper)
The importer lives in ``src/services/spotify_import.py`` and is normally
driven from the GUI: drop the extended-streaming-history files (or the whole
zip) into Setup → Import or Admin → Spotify history import, pick the user,
done. This wrapper keeps the terminal path for headless boxes:
python import_spotify.py <directory> [--user 1]
``<directory>`` holds Streaming_History_Audio_*.json / endsong_*.json files
straight from Spotify's privacy export.
"""
import argparse
import logging
import sys
from pathlib import Path
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("directory", help="folder with Streaming_History_Audio_*.json")
ap.add_argument("--user", type=int, default=1,
help="Curatarr user id to attach the plays to (default 1)")
args = ap.parse_args()
from src.services.spotify_import import pending_files, run_import
directory = Path(args.directory)
if not pending_files(directory):
print(f"no usable Spotify extended-history files in {directory}")
print("(the basic StreamingHistory*.json export is not importable — "
"request the EXTENDED streaming history)")
return 1
stats = run_import(args.user, import_dir=directory)
if stats.get("error"):
print("error:", stats["error"])
return 1
print(f"imported {stats['imported']} plays "
f"({stats['skipped']} skipped, {stats['duplicates']} duplicates) "
f"from {stats['files']} file(s)")
return 0
if __name__ == "__main__":
sys.exit(main())