Changeset 35878
- Timestamp:
- 2022-01-04T17:45:39+13:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/08b-COPY-AUDIO-FEATURES-TO-IMPORT.py
r35870 r35878 3 3 import os 4 4 import re 5 import shutil 5 6 6 7 prep_dir = "essentia-audio-features" … … 29 30 audio_year_dir = os.path.join(audio_dir,year) 30 31 31 json_files = [os.path.join(year,f) for f in os.listdir(audio_year_dir) if re.search(r"\.json$",f)] 32 33 all_af_json_files += json_files 34 32 for f in os.listdir(audio_year_dir): 33 if re.search(r"\.json$",f): 34 year_entrant = os.path.join(year,f) 35 all_af_json_files.append(year_entrant) 36 35 37 36 38 #print("json files = " + repr(all_af_json_files)) … … 38 40 39 41 entrant_recs = [] 42 40 43 41 44 for year_and_entrant in all_af_json_files: … … 61 64 62 65 66 # 63 67 # af = audio-features 68 # 64 69 all_af_nul_files = [] 70 src_af_lookup = {} 65 71 66 print()67 print("Nul files derived from year/country_title_artist audio feature JSON files:")72 #print() 73 #print("Nul files derived from year/country_title_artist audio feature JSON files:") 68 74 69 75 for entrant_rec in entrant_recs: 70 year = entrant_rec["year"] 71 country = entrant_rec["country"].replace("&","and").replace(" ","") 76 year = entrant_rec["year"] 77 country = entrant_rec["country"] 78 title = entrant_rec["title"] 79 artist = entrant_rec["artist"] 80 81 full_year_entrant = os.path.join(audio_dir,year,country+"_" + title + "_" + artist) 82 83 # Tweak the values so they align with those used in SPARQL resultsset 84 country = country.replace("&","and").replace(" ","") 72 85 73 86 if year == "1956": … … 79 92 80 93 all_af_nul_files.append(nul_file) 94 src_af_lookup[nul_file] = full_year_entrant 95 # print("**## storing nul_file = " + nul_file + " => " + full_year_entrant); 81 96 82 print(", ".join(all_af_nul_files))97 # print(", ".join(all_af_nul_files)) 83 98 84 99 … … 146 161 if af_nul_file_errata is not None: 147 162 print(" Errata: Fixing " + af_nul_file + " => " + af_nul_file_errata) 163 164 src_af_lookup[af_nul_file_errata] = src_af_lookup[af_nul_file] 165 del src_af_lookup[af_nul_file] 166 148 167 all_af_nul_files[i] = af_nul_file_errata 168 149 169 150 170 print("Matching Audio-Feature files to nul files in 'import':") … … 154 174 print("The following files have Audio Features, but did not match in to a .nul file in the 'import' diretory") 155 175 176 matched_af_nul_files = [] 177 156 178 for af_nul_file in all_af_nul_files: 157 if not af_nul_file in entrant_nul_files_lookup: 179 if af_nul_file in entrant_nul_files_lookup: 180 matched_af_nul_files.append(af_nul_file) 181 else: 158 182 print(" " + af_nul_file) 159 183 160 184 185 print() 186 print("Copying the following Essentia audio feature JSON files into .nul matched positions in 'import'") 161 187 162 #for af_nul_file in all_af_nul_files: 163 # if not af_nul_file in entrant_nul_files_lookup: 164 # if re.search(r"^NorthMacedonia",af_nul_file): 165 # af_nul_file = af_nul_file.replace("North","") 166 # if not af_nul_file in entrant_nul_files_lookup: 167 # print("**** Failed to find lookup for: " + af_nul_file) 168 # else: 169 # print("**** Failed to find lookup for: " + af_nul_file) 170 171 188 for af_nul_file in matched_af_nul_files: 189 import_files = entrant_nul_files_lookup[af_nul_file] 190 for import_file in import_files: 191 # print("** looking up " + af_nul_file) 192 src_json_file = src_af_lookup[af_nul_file] 193 dst_json_file = import_file.replace(".nul","-Essentia.json") 194 195 print(" Copying: " + src_json_file + " => " + dst_json_file) 196 # shutil.copy(src_json_file,dst_json_file) 197 198
Note:
See TracChangeset
for help on using the changeset viewer.