#1 : 17/12-24 23:18 Nathan
Posts: 4
|
I have a ton of karaoke songs that come in two files. Each of the two song files are named exactly the same but have a different extension. So for example:
123 Artist Name 1 - Song Name 1.mp3 123 Artist Name 1 - Song Name 1.cdg 456 Artist Name 1 - Song Name 2.mp3 456 Artist Name 1 - Song Name 2.cdg 789 Artist Name 2 - Song Name 1.mp3 789 Artist Name 2 - Song Name 1.cdg 012 Artist Name 2 - Song Name 2.mp3 012 Artist Name 2 - Song Name 2.cdg I am comfortable with being able to rename the file. In this case I just want to remove the "123 " in the beginning so I remove a count of 4 starting at 1. The next part I want to do is create a folder "Artist Name" so I would need to name the folder everything before the " -" (space and hyphen). But I only want one folder for each unique artist. So in the above example I would want a one folder called "Artist Name 1" and one folder called "Artist Name 2". Then I would want to put all the mp3/cdg files that are "Artist Name 1" into that associated folder. Repeat for Artist Name 2. Is this possible in the program? It would be a huge lifesaver. Edit: Using batch I was able to get the desired results after renaming the files in Advanced Renamer. I'd still like to know if this is possible within the program though. For those curious, here is the script: @echo off setlocal set "_MusicFolder=YOUR MEDIA FOLDER PATH HERE" pushd "%_MusicFolder%" for %%f in (*.mp3 *.cdg) do if /i not "%%~nf"=="organize" call :SplitName "%%~f" popd tree /f "%_MusicFolder%" endlocal pause exit /b rem -- Subroutine to split filenames :SplitName %1 = original filename set "_Filename=%~n1" set "_Filename=%_Filename:&=^^^&%" set "_Filename=%_Filename:)=\%" set "_Filename=%_Filename: (=\%" set "_Filename=%_Filename: - =\%" for /f "tokens=1 delims=\" %%n in ('echo %_Filename%') do ( md "%%~n" >nul 2>nul move "%~1.*" "%%~n" ) goto :EOF |
#2 : 18/12-24 06:36 Delta Foxtrot
Posts: 401
|
Reply to #1:
Hi Nathan, welcome, Wow, that's a lot of stuff to do that little task. You're gonna love this. ;) For files that still have the three digits in front you'll have to run them through first and remove those numbers. Then load all the files you want to move back into ARen, deactivate the "Remove" method (or whatever method you are using). Now change the ARen mode to "Move" above the menu and files list. In the "Output folder:" field that pops up enter: <substr:1: -> If you right-click on the column header you can activate and move the "New Path" column so you can see where your files will be moved to. If that looks right just click "Start batch" and you are done! Be sure and save the batch so you can use it later for new files. Best, DF |
#3 : 18/12-24 06:50 Nathan
Posts: 4
|
Reply to #2:
That's great, thanks for the response! It worked like a charm. I'll have to play around with it. With the karaoke files there is sometimes something after the artist's name in the filename. For example, "Artist Name (MPX) - Song Name". In the parenthesis there can be other words or phrases like "(wbgv)" or "(wobgv)". Is there any way to disregard characters in the brackets when creating a new artist folder? As it is, I get multiple folders for a single artist if the file names include the brackets. It's also nice that it gives a warning/error if there is already a folder with a file of the same name in there. |
#4 : 18/12-24 07:59 Delta Foxtrot
Posts: 401
|
Reply to #3:
Hi Nathan, That' s funny, I had an idea for a way to do all files together and was coding it–and thinking about if there might be be edge conditions like that–when you replied. I added that change in and here's a script that takes any of the filename types you mentioned and deals with them. Here's of a screenshot of it working: https://drive.google.com/file/d/18mtZ30qQJMi3CPo 2oJs8irLJR0q_L7xX/view?usp=sharing Here's the script: newName = item.name ; newName1 = ( newName.search(/^\d{3} /) == 0 ? newName.substr(4): newName ) ; index1 = newName1.search(/ -/) ; index3 = newName1.search(/\(/) ; index2 = ( index3 == -1 ? 100 : index3 ) ; if ( index1 > index2 ) { item.newPath = item.path + newName1.substr( 0, index2 ) ; } else { item.newPath = item.path + newName1.substr( 0, index1 ) ; } return newName1 ; //------------------------------------------------------------------------------------- Standard warning, be sure to test it thoroughly and watch the preview columns. If something goes wrong you can undo the batch if nothing has changed. With a clean method list open a Script method and paste the code in there, press "Apply script" and make sure the Batch mode is set to RENAME or COPY. If copy it will copy the files rather than moving them. Add files and go. :) (Oh, you could also just add a method that would put a "- " in front of the parenthesis (using the Batch move mode in my previous post). Best, DF |
#5 : 18/12-24 14:20 Nathan
Posts: 4
|
Reply to #4:
I really appreciate your help in this. I wish I could understand the script a bit more so I could troubleshoot it myself. I'm just reporting back my findings, not expecting you to fix anything, you've already done so much! When testing the script it is getting hung up on files with parenthesis in them. It won't move them into the created folders. Here's a couple screenshots showing the issue. https://imgur.com/a/5oSPayg So for example, Lace - I Want A Man.cdg Lace - I Want A Man.mp3 will both move to the new "Lace" folder but Lace (MPX) - I Want A Man.cdg Lace (MPX) - I Want A Man.mp3 throws an error and remains in the original folder. |
#6 : 19/12-24 01:44 Delta Foxtrot
Posts: 401
|
Reply to #5:
Hi Nathan, Well, what a long strange trip *this* is... For some reason I can't view files on imgur (probably my privacy settings), but I got the same results you did when I actually ran the script. When I wrote the script I just used the "New Path" column to tell me where the files (should) go, because of course why wouldn't they? :) Sorry about that. That led me off on a whole *thing*. I realized that, while I've used the basic method of setting a new path in scripts MANY times before, I can't remember a time when I changed the name of the file before moving it. Doesn't mean that's correct, but, working on that theory I rewrote the script so that it *should* move all files into appropriate directories, bypassing the changing of names, just figuring out what the folder name *should* be without the leading digits or trailing parentheses. Here's the first fun part: THAT script moved ONLY the files with parentheses, and gave errors when a file *didn't* have a parenthesis! Great, huh? :) So it wasn't *just* that the name was changed in previous tries. I ran the scripts in both version 3.95 and version 4.06, and they all exhibited the same behavior. Since the two versions use different scripting engines, I feel that the problem is somewhere in ARen itself, some memory location that isn't updating properly or something like that. It's sort of like the behavior that happens when you try to rename a file and then move it based on the new filename. ARen doesn't "see" the new filename in whatever it's doing to interpret the contents of the Move mode "Output folder:" field. Anyway, the ONLY way I've been able to get the job done is to use three instances of ARen: 1. Rename the files with leading digits in the name, using Rename mode. Easiest for me with a replace method: Replace: "^\d{3} " (no quotes) With: <nothing> Reg. expr.: checked (because remove method just brute deletes, so all the files would get chopped. You could add an {if} clause in version 4, but I don't really like using that for a couple of reasons.) 2. Open a new instance of ARen and move just the items with parentheses, using "<substr:1: (>" (no quotes) in the Output folder field. No active methods. 3. Open another instance of ARen and move just the items left (the ones without parens) using "<substr:1: ->" (no quotes) in the Output folder field. Again, no active methods. So far that's the only way I've found to do what you need. (Oh, you should drag the whole folder into ARen each time, and specify "*.cdg;*.mp3" (no quotes) as the file mask in the popup box. After the first time they will just reappear until you change them. You have batch skills, so you could probably set all that up and run everything together in a batch. I'm sorry I couldn't get this done for you in a nice, tidy, single-instance script. I'm going to keep thinking about it, and maybe Kim can shed more light on the problem. And Miguel and Styb are good at automating ARen files in batch files, I think, so if you need help you should ask. I'll let you know if I come up with something else. Best, DF |
#7 : 19/12-24 19:23 Delta Foxtrot
Posts: 401
|
Reply to #6:
Hello, Miguel got in touch with me and sent me a script that works. After a lot of reworking it and scratching my head I'm still not sure why it works when the others didn't, but I'm just glad there's a way to do this. Here's the script: // Get the original file name let newName = item.name; // Remove the numeric prefix (e.g., "123 ") if it exists let newNameWithoutNumber = (newName.search(/^\d{3} /) === 0 ? newName.substr(4) : newName); // Find the position of the first " -" let index1 = newNameWithoutNumber.search(/ -/); // Extract only the "Artist Name" (text before the first hyphen, ignoring parentheses) let artistName = index1 !== -1 ? newNameWithoutNumber.substr(0, index1).replace(/\s*\(.*?\)\s*/g, "").trim() : newNameWithoutNumber.replace(/\s*\(.*?\)\s*/g, "").trim(); // Ensure the folder name does not contain invalid characters artistName = artistName.replace(/[<>:"/\\|?*]/g, ""); // Create the new file path // Folder: Artist name without additional details (such as "(MPX)") item.newPath = item.path + "\\" + artistName; // Return the file name without the numeric prefix return newNameWithoutNumber; //----------------------- Thanks MIguel! :) Best, DF |
#8 : 21/12-24 07:59 Delta Foxtrot
Posts: 401
|
Reply to #7:
Hey guys, I figured out why those scripts failed: there was a trailing space in the new folder names. :( You can't see it in the preview column... All the previous scripts work with the addition of one little ".trim()" in the right place. Oh, here's another one that works, in only four ugly lines: pattern = /^(\d{3} )?([^\(-]+)([\(][A-Z]+\))? - (.*)$/ ; names = item.name.match( pattern ) ; item.newPath = item.path + names[2].trim() ; return names[2].trim()+( names[3]?" "+names[3]:"")+" - "+names[4].trim() ; I also realized how to use strings stored in one array as variable names to address elements of another array–for instance when I use a filename.match() statement like above to capture the parts of the file or folder name. That's going to save me a lot of time, headaches, and lines of code in the future I think. Cheers all, DF |
#9 : 21/12-24 12:24 Miguel
Posts: 170
|
Reply to #8:
Perfect!! Miguel |
#10 : 26/12-24 15:18 Nathan
Posts: 4
|
Reply to #8:
Wow, can't believe how much time and effort has gone into this. I really appreciate it! I'm glad you were able to learn something out of being so helpful too. This seems like a tough nut to crack and I would have never been able to get this far. Again, not expecting fixes, just reporting my findings for anyone in the future who sees this. I found another bug with the four line code pattern = /^(\d{3} )?([^\(-]+)([\(][A-Z]+\))? - (.*)$/ ; names = item.name.match( pattern ) ; item.newPath = item.path + names[2].trim() ; return names[2].trim()+( names[3]?" "+names[3]:"")+" - "+names[4].trim() ; I tested out with a couple potential problem files which were named the following: +44 - When Your Heart Stops Beating [Stellar Karaoke] - Copy.cdg +44 - When Your Heart Stops Beating [Stellar Karaoke] - Copy.mp3 2.4 Family - Lean On Me [EZ Karaoke] - Copy.cdg 2.4 Family - Lean On Me [EZ Karaoke] - Copy.mp3 Mama's & Papa's - Words Of Love [PS Karaoke] - Copy.cdg Mama's & Papa's - Words Of Love [PS Karaoke] - Copy.mp3 2 Pac & Dr Dre (Duet) - California Love [#Z Karaoke] - Copy.cdg 2 Pac & Dr Dre (Duet) - California Love [#Z Karaoke] - Copy.mp3 When adding the first three pairs of files (through to Mama's & Papa's - Words Of Love [PS Karaoke] - Copy.mp3) everything works great. If I run the batch with those six files all is clear in AdRen and the script does it's job moving to folders. However, as soon as I add the 2 Pac & Dr Dre (Duet) - California Love [#Z Karaoke] - Copy files, AdRen says the script is invalid for all files even if the files had no errors before. It seems the "(Duet)" is causing the issue. Specifically the closing bracket. |
#11 : 26/12-24 16:21 Delta Foxtrot
Posts: 401
|
Reply to #10:
Hi Nathan, In the first line, "pattern = "... change the "A-Z" to "^\)" and it works. The example you gave was capital letters in the parens so that's what I used. This way it matches anything but the closing paren. Miguel's script should also work with those files. Best, DF |