Implement JSONification
This commit is contained in:
		
							parent
							
								
									2c555ba8e0
								
							
						
					
					
						commit
						6840a57e0b
					
				
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
								
							| @ -1,10 +1,11 @@ | |||||||
| # Karaokatalog | # Karaokatalog | ||||||
| 
 | 
 | ||||||
| Tools to manage an Ultrastar DX song library. Features include: | Tools to manage an UltraStar DX song library. Features include: | ||||||
| 
 | 
 | ||||||
| 1. Deduplication | 1. Deduplication | ||||||
| 2. Organization | 2. Organization | ||||||
| 3. Recoding | 3. Recoding | ||||||
|  | 4. Jsonification | ||||||
| 
 | 
 | ||||||
| ## Setup | ## Setup | ||||||
| 
 | 
 | ||||||
| @ -55,3 +56,13 @@ python3 -m karaokatalog.organize $SONG_LIBRARY | |||||||
| ```bash | ```bash | ||||||
| python3 -m karaokatalog.recode $SONG_LIBRARY | python3 -m karaokatalog.recode $SONG_LIBRARY | ||||||
| ``` | ``` | ||||||
|  | 
 | ||||||
|  | ### Jsonification | ||||||
|  | 
 | ||||||
|  | **Create a `songs.json` file with some song metadata in the root library dir.** | ||||||
|  | 
 | ||||||
|  | ℹ️ This operation is risk-free: If a `songs.json` already exists, it is kept intact (so no data loss possible). | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | python3 -m karaokatalog.jsonify $SONG_LIBRARY | ||||||
|  | ``` | ||||||
|  | |||||||
							
								
								
									
										0
									
								
								karaokatalog/jsonify/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								karaokatalog/jsonify/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										30
									
								
								karaokatalog/jsonify/__main__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								karaokatalog/jsonify/__main__.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | import json | ||||||
|  | import logging | ||||||
|  | 
 | ||||||
|  | from karaokatalog.get_parser import get_parser | ||||||
|  | from karaokatalog.Library import Library | ||||||
|  | 
 | ||||||
|  | logging.basicConfig( | ||||||
|  |     format="%(asctime)s [%(levelname)s] %(message)s", level=logging.INFO | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | if __name__ == "__main__": | ||||||
|  |     args = get_parser( | ||||||
|  |         "jsonify", "Create a JSON file containing metadata of all songs in the library" | ||||||
|  |     ).parse_args() | ||||||
|  |     logging.info("Karaokatalog Jsonification started") | ||||||
|  | 
 | ||||||
|  |     logging.info("Loading library") | ||||||
|  |     library = Library.from_dir(args.library_path) | ||||||
|  |     logging.info("Library loaded") | ||||||
|  | 
 | ||||||
|  |     songs = [song.as_dict() for song in library.songs] | ||||||
|  |     json_path = args.library_path / "songs.json" | ||||||
|  | 
 | ||||||
|  |     logging.info(f"Writing JSON to {json_path}") | ||||||
|  | 
 | ||||||
|  |     with json_path.open("x", encoding="utf-8") as f: | ||||||
|  |         json.dump(songs, f, ensure_ascii=False, indent=4) | ||||||
|  | 
 | ||||||
|  |     logging.info("Karaokatalog Jsonification done") | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user