Skip to content

Commit

Permalink
bugfix that should affect no one but me
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireCJS committed May 14, 2024
1 parent abd7c51 commit a932f4e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
26 changes: 14 additions & 12 deletions BAT-and-UTIL-files/add-art-to-flac.bat
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
@echo off
@Echo OFF

rem We had to move this functionality into a subordinate BAT file after discovering that WinAmp only displays
rem artwork added by Metaflac if you remove the existing artwork first. So adding requires removing first.

SET ART=%1
SET MUSIC=%2
call validate-environment-variables ART MUSIC


metaflac --import-picture-from="%@UNQUOTE[%ART]" %MUSIC%
rem Capture parameters and validate environment:
set PARAMS_ADDARTTOFLAC=%*
set PARAM_ADDARTTOFLAC_1=%1
set PARAM_ADDARTTOFLAC_2=%2
if %VALIDATED_ADDARTTOFLAC ne 1 (
call validate-in-path remove-art-from-flac add-art-to-flac-helper
set VALIDATED_ADDARTTOFLAC=1
)

rem Remove old art, add new art:
call remove-art-from-flac %PARAM_ADDARTTOFLAC_2%
call add-art-to-flac-helper %PARAM_ADDARTTOFLAC_1% %PARAM_ADDARTTOFLAC_2%

call warning "this is untested on flac yet - ERRORLEVEL = %ERRORLEVEL% - let's see what happens?!"
pause



if ERRORLEVEL 1 (%COLOR_ERROR %+ ECHO %EMOJI_RED_EXCLAMATION_MARK%ERROR embedding art "%ART%" into song "%SONG%"!! %+ BEEP %+ pause %+ pause %+ pause %+ pause %+ pause %+ pause %+ pause %+ pause %+ pause)
REM if ERRORLEVEL 0 .and. %DONT_DELETE_ART_AFTER_EMBEDDING ne 1 (del %ART%)
if ERRORLEVEL 0 .and. %DONT_DELETE_ART_AFTER_EMBEDDING ne 1 (%COLOR_SUCCESS% %+ echo %EMOJI_CHECK_MARK%Success!!! %+ if %DONT_DELETE_ART_AFTER_EMBEDDING ne 1 (%COLOR_REMOVAL %+ del %ART%))
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2023-07-16 21:34 772 50% add-art-to-flac.bat
2024-04-19 20:02 781 55% add-art-to-flac.bat
2023-07-18 09:19 3,817 70% add-art-to-mp3.bat
2023-05-05 02:24 459 47% add-art-to-song.bat
Binary file not shown.
25 changes: 21 additions & 4 deletions cover_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def delete_file_with_backup(filename):



def does_companion_exist(filename):
def does_companion_exist_OLD_tried_and_true_for_a_year(filename):
base_filename = os.path.splitext(filename)[0]
image_extensions = [".jpg", ".jpeg", ".png", ".webp"]
possible_filenames = [f"{base_filename}{s}{image_extension}"
Expand All @@ -296,6 +296,23 @@ def does_companion_exist(filename):



def does_companion_exist(filename): #new 2024/04/19 version of function to include truncated last character situation I've run into
base_filename_1 = os.path.splitext(filename)[0] #with last charcter
base_filename_2 = os.path.splitext(filename)[:-1] #without last charcter
image_extensions = [".jpg", ".jpeg", ".png", ".webp"]
possible_filenames = [ f"{filename_to_use}{fname_range_sfx}{image_extension}"
for filename_to_use in [base_filename_1, base_filename_2]
for fname_range_sfx in ["", "A", "B", "C"] + [f"B{i}" for i in range(1, 999)]
for image_extension in image_extensions]
#primt("[PF] possible_filenames: " + possible_filenames)
for possible_filename in possible_filenames:
#primt("[CA] Checking " + possible_filename)
if file_exists_and_nonzero_size(possible_filename):
return True
return False






Expand Down Expand Up @@ -993,9 +1010,9 @@ def clean_up_zero_byte_downloads():
file.write('\n:CleanUp_Zero_Byte_Images_Execute\n')
if IS_WINDOWS and OUR_SHELL.lower() != "bash":
file.write('set FMASK_IMAGE=*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.webp;*.ico;*.tif;*.tiff;*.pcx;*.art;*.dcm;*.jfif;*.jpg_large;*.png_large\n')
if OUR_SHELL == "TCC": file.write('call delete-zero-byte-files\n\n') #i have my own script for this purpose so i call that one too just to be double-thorough
if OUR_SHELL == "TCC": file.write('for %A in (%FMASK_IMAGE%) do ( if %@FILESIZE["%A"] == 0 (*del "%A") )\n\n')
else: file.write('for %%A in ("%FMASK_IMAGE%") do (if %%~zA equ 0 ( del "%%~A") )\n\n') #untested
if OUR_SHELL == "TCC": file.write('call delete-zero-byte-files %FMASK_IMAGE%\n\n') #i have my own script for this purpose so i call that one too just to be double-thorough, however that script needs to be passed a list of extensions or it ends up deleting other 0-byte files that are unrelated to this task
if OUR_SHELL == "TCC": file.write('for %A in (%FMASK_IMAGE%) do ( if %@FILESIZE["%A"] == 0 (*del /p "%A") )\n\n')
else: file.write('for %%A in ("%FMASK_IMAGE%") do (if %%~zA equ 0 ( del /p "%%~A") )\n\n') #untested
else:
file.write('export FMASK_IMAGE="*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.webp;*.ico;*.tif;*.tiff;*.pcx;*.art;*.dcm;*.jfif;*.jpg_large;*.png_large"\n')
file.write('find . -name "$FMASK_IMAGE" -size 0 -delete\n\n') #untested
Expand Down
4 changes: 3 additions & 1 deletion cover_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def find_jpg(base_filename):
bat_file.write("@Echo OFF\n\n")
for audio_file in audio_files: # Iterate over audio files
base_filename = os.path.splitext(audio_file)[0] # Get the base filename without the extension
jpg_filename = find_jpg(base_filename) # Search for a similarly named JPG
jpg_filename = None
if jpg_filename is None: jpg_filename = find_jpg(base_filename ) # Search for a similarly named JPG
if jpg_filename is None: jpg_filename = find_jpg(base_filename[:-1]) # Search for a similarly named JPG without the last character of the original name [for some reason I saw this happen in the wild]
if jpg_filename: # Generate the command using the template and the filenames
print(f" - yes companion jpg: {audio_file}")
command = command_template.format(jpgfilename=jpg_filename, audiofilename=audio_file)
Expand Down

0 comments on commit a932f4e

Please sign in to comment.