Changeset 35878


Ignore:
Timestamp:
2022-01-04T17:45:39+13:00 (2 years ago)
Author:
davidb
Message:

Further development of script. Now at the point of printing out what the desired copy commands are

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  
    33import os
    44import re
     5import shutil
    56
    67prep_dir = "essentia-audio-features"
     
    2930     audio_year_dir = os.path.join(audio_dir,year)
    3031
    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         
    3537
    3638#print("json files = " + repr(all_af_json_files))
     
    3840
    3941entrant_recs = []
     42
    4043
    4144for year_and_entrant in all_af_json_files:
     
    6164
    6265
     66#
    6367# af = audio-features
     68#
    6469all_af_nul_files = []
     70src_af_lookup    = {}
    6571
    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:")
    6874
    6975for 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(" ","")
    7285
    7386     if year == "1956":
     
    7992
    8093     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);
    8196     
    82 print(", ".join(all_af_nul_files))
     97# print(", ".join(all_af_nul_files))
    8398
    8499
     
    146161          if af_nul_file_errata is not None:
    147162               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
    148167               all_af_nul_files[i] = af_nul_file_errata
     168               
    149169               
    150170print("Matching Audio-Feature files to nul files in 'import':")
     
    154174print("The following files have Audio Features, but did not match in to a .nul file in the 'import' diretory")
    155175
     176matched_af_nul_files = []
     177
    156178for 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:
    158182          print("  " + af_nul_file)
    159183               
    160184
     185print()
     186print("Copying the following Essentia audio feature JSON files into .nul matched positions in 'import'")
    161187
    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                
     188for 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.