4

I have a music repository that contain mostly mp3 files. I used Minilyrics to download .lrc files for each mp3, so most mp3 files have a corresponding lyrics file with the same name but has .lrc extension in the same folder.

Now I need to list mp3 files that doesn't have lyrics. Is there a way to do this in PowerShell or command line?

3 Answers 3

5

The below PowerShell will list the the full path name of any .mp3 files that do not have any matching .lrc files in the same directory with the same base file name.

Just change the $pth = to be the full path to the starting folder which the .mp3 files reside. This solution will recursively traverse the $pth folder for all .mp3 files in any subfolders too.

PowerShell

$pth = "C:\MP3\Folder\Location";
Get-ChildItem -Path $pth -Recurse -Include "*.mp3" | % { Process { 
    If ( ! ( Test-Path "$((Split-Path $_.FullName -Resolve))\$($_.BaseName).lrc" ) ) 
    { $_.FullName };
    }};

Supporting Resources

11
  • 2
    tested and worked on my PC
    – fall
    Mar 7, 2021 at 4:27
  • 1
    Better IMO: Get-ChildItem -Path $pth -Recurse -Include "*.mp3" | ? {(! ( Test-Path "$((Split-Path $_.FullName -Resolve))\$($_.BaseName).lrc" ) ) } | Format-Table;
    – Jonathan
    Mar 7, 2021 at 11:51
  • Perhaps that's a preference but foreach-object with conditional If performs better than where-object so that's out of habit with the way I write code. Same with the process {} too. I'm not sure of the scale so I typically just go with what performs best out of habit. You can use Measure-Command {} to compare the time of the operations to confirm. Mar 7, 2021 at 15:07
  • Won't you get better performance if you let the FileSytem Provider do the filtering? Get-ChildItem -Path $pth\*.mp3? Mar 7, 2021 at 17:41
  • 1
    Right. I read that the -Path and -Filter are passed to the File System Provider and thus faster than -Include or -Exclude. Most likely trivial in this case, but good to keep in mind when optimizing. Mar 8, 2021 at 1:53
3

If you have Python installed on your computer, you could just paste this code into a file called songlister.py and put it in the same folder as all the .mp3 and .lrc files, then just run it from the command line like this:

python songlister.py

and it will list all the names of the songs that don't have a .lrc file!

Here's the code:

import glob,re

# These give the lists of all the .mp3 and .lrc files in your current folder and sub folders
mp3_files = glob.glob("/**/*.mp3", recursive=True)
lyric_files = glob.glob("/**/*.lrc", recursive=True)

# For every .mp3 file, check if it has a matching .lrc file.
for i in mp3_files:
    music_name = re.search(".*\.mp3$", i).group().replace('.mp3', '')
    match = False
    for s in lyric_files:
        lyric_name = re.search(".*\.lrc$", s).group().replace('.lrc', '')

# If it does NOT have a .lrc file, then list the name of the file.
        if lyric_name == music_name: 
            match = True
            break
    if not match:
        print(i)
4
  • Python is very good idea. I didn't consider Python because I don't know Python. I tried this script. It has 1 problem: If there are 100 lrc files in this folder, it will print the same mp3 filename 100 times if it doesn't have a lyrics file or 99 times if does have one. So I improved the code, and added recursion for sub folders. Please tell me if there are any mistakes as I was coding while googling. Code is too long to fit in a comment, so I edited the code in your answer
    – fall
    Mar 7, 2021 at 4:06
  • 1
    ah, thank you! sorry, i just wrote this in like 2 minutes and didn't think more carefully about that potential issue. as for adding recursion, i just assumed everything was in the parent folder, so i didn't add that, but i appreciate the clarification! i'll review the edits and check it out. Mar 7, 2021 at 4:36
  • 1
    Looks good to me 👍 added those changes, just changed one thing for better syntax. Mar 7, 2021 at 4:39
  • You could use Python pathlib. It has glob, exists and with_suffix. For each mp3, you could simply check if the corresponding lrc file exists, which would simplify your code very much. I cannot test under Windows right now, but it's possible that glob.glob("/**/*.mp3") list every mp3 file on your computer, not just the current folder. Mar 7, 2021 at 13:03
0

Here is the low-tech approach I would use. From a command prompt, do dir /b|sort > list.txt. This produces the list of files in the file list.txt, ordered alphabetically.

Then open the file in Excel, or Google Sheets. The list of file names will appear in column A. In cell B1, enter =RIGHT(A1,LEN(A1)-FIND(".",A1)), and then copy this to all of column B (or, more properly, for as long as the file names exist); concretely, while on cell B1 press Ctrl-C, then select the whole column, and press Ctrl-V. This produces the list of extensions on column B. Then, on cell C1, enter =IF(B1=B2,A1,""), and again copy over the whole column. Now on column C you have the list of files with no lrc file (properly, this would also show a file with lrc but no mp3 file).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .