|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『楼 主』:
一起帮忙用批处理帮MP3找出未配歌词
使用 LLM 解释/回答一下
现在的很多MP3都能显示歌词了,要正常显示的话,歌词文件(*.lrc)必须与歌曲文件(*.mp3)同名,且在同一个目录内。!!!
而我们往往很难发现歌词是否有对应的歌词文件,于是我参考以前发的类似贴做了个批处理,尽管有很多不足之处.^^恳请众位前辈不吝赐教。
假设MP3对应的盘符为G:\
G:\Music是专门存放歌曲的目录,因为现在不少MP3都能读取数层目录,所以把不同类的歌分在不同的目录里面,在使用的时候能够更加顺手。
假设G:\Music下又有两个目录
G:\Music\01
G:\Music\02
批处理如下。
@echo off
del G:\list.txt>nul 2>nul
echo ---G:Music\01 >G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt)
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt)
notepad G:\list.txt
exit
经试验能用。我是新手,这种很简单的操作却写出了这么一大堆代码,老觉得别扭,希望大家帮我把这段简化一下,如果有问题,也恳请大家提出来啊~~~
Last edited by junyee on 2006-10-1 at 22:49 ]
Nowadays, many MP3 players can display lyrics. For normal display, the lyric file (*.lrc) must have the same name as the song file (*.mp3) and be in the same directory.!!!
But it's often difficult for us to find out whether there is a corresponding lyric file. So I made a batch script referring to similar previous posts, although there are many deficiencies.^^ I sincerely ask all seniors for your valuable advice.
Suppose the drive letter corresponding to the MP3 is G:\
G:\Music is a special directory for storing songs. Because many current MP3 players can read multiple levels of directories, so categorizing different types of songs into different directories can make using them more convenient.
Suppose there are two more directories under G:\Music
G:\Music\01
G:\Music\02
The batch script is as follows.
@echo off
del G:\list.txt>nul 2>nul
echo ---G:Music\01 >G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt)
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do (if not exist %%~ni.lrc echo %%~ni>>G:\list.txt)
notepad G:\list.txt
exit
It has been tested to work. I'm a newbie. I feel awkward to write so many lines of code for such a simple operation. I hope everyone can help simplify it. If there are any problems, I also sincerely ask everyone to point them out.
Last edited by junyee on 2006-10-1 at 22:49 ]
|
|
2006-10-1 21:17 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
@echo off
echo _____________________G:Music\01 >G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
echo _____________________G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
start G:\list.txt
exit
楼主的代码写得不错吗!!! 我去掉del因为下面echo ---G:Music\01 >G:\list.txt这一句会刷新内容. (只要文件属性不是只读!)
两个for语句处属于for与if两个复合语句的嵌套, 不用括号也可以.
notepad G:\list.txt这一句改成start G:\list.txt是因为DOS下的打开应用程序, 因为后缀都是关联好了的, 系统会自动调用记事本来打开它 .
Last edited by pengfei on 2006-10-1 at 23:18 ]
@echo off
echo _____________________G:Music\01 >G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
echo _____________________G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
start G:\list.txt
exit
The landlord's code is written well!!! I removed del because the line echo ---G:Music\01 >G:\list.txt below will refresh the content. (As long as the file attribute is not read-only!)
The two for statements are the nesting of two compound statements, for and if, and parentheses are not needed.
The line notepad G:\list.txt is changed to start G:\list.txt because in DOS, to open an application, since the suffixes are all associated, the system will automatically call Notepad to open it.
Last edited by pengfei on 2006-10-1 at 23:18 ]
|
|
2006-10-1 21:45 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
其实你的代码已经够简洁了,能修改的就只是对一些代码进行一些优化而已,特别是 notepad G:\list.txt 这一句有点问题,一旦你使用了这一句,那么,只有等G:\list.txt被关闭之后,批处理窗口才会退出,并且,末尾的exit语句可以不用。修改你的代码如下:
@echo off
del /a /f /q G:\list.txt 2>nul
echo ---G:Music\01 >>G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
start G:\list.txt
刚发完,却发现pengfei已经在2楼给出了代码,呵呵,手脚够快的呀。
不过去掉del语句不太妥当,因为不知道G:\list.txt 是何属性,万一是只读属性呢,echo重定向到G:\list.txt 就会无法写入!所以我这段代码仍然保留了del语句,并且加了 /a /f 参数来强制删除,并加了静默参数 /q;又考虑到可能不存在G:\list.txt ,所以又用 2>nul 来屏蔽错误信息在屏幕上的显示。
Last edited by namejm on 2006-10-1 at 22:09 ]
Actually, your code is already quite concise. The only thing that can be modified is to optimize some parts of the code. Especially, there is a problem with the line `notepad G:\list.txt`. Once you use this line, the batch processing window will not exit until G:\list.txt is closed, and the exit statement at the end can be omitted. Modify your code as follows:
@echo off
del /a /f /q G:\list.txt 2>nul
echo ---G:Music\01 >>G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
start G:\list.txt
Just after posting, I found that pengfei has already given the code on the second floor. Hehe, he's really quick.
But it's not appropriate to remove the del statement because I don't know the attributes of G:\list.txt. If it's in read-only attribute, the echo redirection to G:\list.txt will not be able to write! So my code still retains the del statement, and adds the /a /f parameters to force deletion, and adds the silent parameter /q; also considering that G:\list.txt may not exist, so uses 2>nul to shield the display of error messages on the screen.
Last edited by namejm on 2006-10-1 at 22:09 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-1 22:03 |
|
|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
kc唉,,我还老觉得不够简洁呢。。
不过。可不可以用什么方法把上面语名再精减一下呢?因为
echo ---G:Music\01 >>G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
做的是重复动作只是目录名不同而已,如果在G:\music下有很多文件夹的话,岂不是更长了?
kcOh, I still feel it's not concise enough..
But, is there any way to further simplify the above command? Because
echo ---G:Music\01 >>G:\list.txt
cd /d G:\music\01
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
echo ---G:Music\02 >>G:\list.txt
cd /d G:\Music\02
for %%i in (*.mp3 *.wma) do if not exist %%~ni.lrc echo %%~ni>>G:\list.txt
What's done here is repetitive actions with only different directory names. If there are many folders under G:\music, it will be even longer?
|
|
2006-10-1 22:35 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
可以试试下面的代码(暂时没有考虑到各种可能的错误,比如mp3格式的和wma格式的文件同名的问题):
@echo off
setlocal enabledelayedexpansion
del /a /f /q G:\list.txt 2>nul
for /r %%i in (.) do (
set route=%%i
set route=!route:~0,-2!
echo -------!route!>>G:\list.txt
for %%j in ("%%i\*.mp3" "%%i\*.wma") do (
if not exist %%~nj.lrc echo %%~nj>>G:\list.txt
)
)
start notepad G:\list.txt
You can try the following code (temporarily not considering various possible errors, such as the problem of files with the same name in mp3 format and wma format):
@echo off
setlocal enabledelayedexpansion
del /a /f /q G:\list.txt 2>nul
for /r %%i in (.) do (
set route=%%i
set route=!route:~0,-2!
echo -------!route!>>G:\list.txt
for %%j in ("%%i\*.mp3" "%%i\*.wma") do (
if not exist %%~nj.lrc echo %%~nj>>G:\list.txt
)
)
start notepad G:\list.txt
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-1 23:03 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
当前目录下所有文件夹都可以
注:文件夹不能有空格、敏感字符
@echo on
cd.>list.txt
setlocal enabledelayedexpansion
for /f %%i in ('dir/ad/b/s') do (
set D=%%i
call :List !D:%cd%\=!)
exit
:List
for %%i in ("%1\*.mp3" "%1\*.wma") do if not exist "%1\%%~ni.lrc" >>list.txt echo %1\%%~ni
goto :eof
如果想区分mp3格式的和wma格式,改为“>>list.txt echo %1\%%i”
All folders in the current directory are okay.
Note: Folders should not have spaces or sensitive characters.
@echo on
cd.>list.txt
setlocal enabledelayedexpansion
for /f %%i in ('dir/ad/b/s') do (
set D=%%i
call :List !D:%cd%\=!)
exit
:List
for %%i in ("%1\*.mp3" "%1\*.wma") do if not exist "%1\%%~ni.lrc" >>list.txt echo %1\%%~ni
goto :eof
If you want to distinguish between MP3 format and WMA format, change it to ">>list.txt echo %1\%%i"
|
|
2006-10-1 23:30 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
@echo off
del/a/f/q list.txt 2>nul & for /f "delims=" %%i in ('dir/s/a-d/b *.mp3 *.wma') do ( if not exist "%%~di%%~pi%%~ni.lrc" echo %%i>>list.txt )
start list.txt
我也试试
Last edited by NaturalJ0 on 2006-10-2 at 00:01 ]
```
@echo off
del/a/f/q list.txt 2>nul & for /f "delims=" %%i in ('dir/s/a-d/b *.mp3 *.wma') do ( if not exist "%%~di%%~pi%%~ni.lrc" echo %%i>>list.txt )
start list.txt
```
I also try
Last edited by NaturalJ0 on 2006-10-2 at 00:01 ]
|
|
2006-10-1 23:54 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
大家写的都不错啊, 我也贴一段. 遍历当前目录下的每一个目录. 列出没有歌词的歌曲名, 同时注明所在目录. 对于路径中存在空格的问题应该可以处理. 也会搜索当前目录, 如果没有文件会提示找不到文件...
namejm版主说的只读文件, 将不能写入. 这一点很重要, 所在还是选择DEL. 如果同一目录出现两种格式文件的同名, 这一点不能做任何处理, 因为lrc只能有一个, 所以还得重命名另一种格式的文件.
@echo off
set route=%cd%
if exist list.txt del /a list.txt
setlocal enabledelayedexpansion
for /r %%m in (.) do (
set list=%%m
set list=!list:~0,-2!
cd /d !list!
set num=
for /f "tokens=*" %%i in ('dir /a-d /b *.mp3 *.wma') do (
if "!num!"==" " echo ===!list!===>>"%route%\list.txt" & set num=
if not exist %%~ni.lrc echo %%i>>"%route%\list.txt"
)
)
start "" "%route%\list.txt"
更多的音乐类型请在第二个for语句中按当前格式添加.
Last edited by pengfei on 2006-10-2 at 05:34 ]
Everyone's writing is pretty good. I'll also post a section. Traverse each directory under the current directory. List the song names without lyrics and note the directory they are in. The problem of spaces in the path should be handleable. It will also search the current directory, and if there are no files, it will prompt that no files are found...
Moderator namejm said about read-only files, which cannot be written. This is very important, so still choose DEL. If there are two formats of files with the same name in the same directory, this cannot be handled in any way, because there can only be one lrc, so the other format file has to be renamed.
@echo off
set route=%cd%
if exist list.txt del /a list.txt
setlocal enabledelayedexpansion
for /r %%m in (.) do (
set list=%%m
set list=!list:~0,-2!
cd /d !list!
set num=
for /f "tokens=*" %%i in ('dir /a-d /b *.mp3 *.wma') do (
if "!num!"==" " echo ===!list!===>>"%route%\list.txt" & set num=
if not exist %%~ni.lrc echo %%i>>"%route%\list.txt"
)
)
start "" "%route%\list.txt"
For more music types, add according to the current format in the second for statement.
Last edited by pengfei on 2006-10-2 at 05:34 ]
|
|
2006-10-2 00:21 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
发现5楼namejm兄的代码, 原来不用dir也可以列出目录的匹配文件. 呵呵~ 学习了...
下面的代码和8楼实现一样的功能, 一个for来完成. 速度还可以!
@echo off
set route=%cd%
set term=
set take=set list=%%~dpi
if exist file.txt del /a file.txt
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('dir /s /a-d /b *.mp3 *.wma') do (
!take!
if "!list!"=="%%~dpi" (
set take=
) else (
set term= & set take=set list=%%~dpi
)
if "!term!"==" " echo ===%%~dpi===>>"%route%\file.txt" & set term=
if not exist %%~dpni.lrc echo %%~nxi>>"%route%\file.txt"
)
start "" "%route%\file.txt"
Last edited by pengfei on 2006-10-2 at 05:34 ]
Found the code from user namejm on floor 5. It turns out that you can list matching files in a directory without using dir. Hehe~ Learned something...
The following code has the same function as the one on floor 8, completed with a single for. The speed is also decent!
@echo off
set route=%cd%
set term=
set take=set list=%%~dpi
if exist file.txt del /a file.txt
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('dir /s /a-d /b *.mp3 *.wma') do (
!take!
if "!list!"=="%%~dpi" (
set take=
) else (
set term= & set take=set list=%%~dpi
)
if "!term!"==" " echo ===%%~dpi===>>"%route%\file.txt" & set term=
if not exist %%~dpni.lrc echo %%~nxi>>"%route%\file.txt"
)
start "" "%route%\file.txt"
Last edited by pengfei on 2006-10-2 at 05:34 ]
|
|
2006-10-2 02:09 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
命令行简单显示版:
@for /r %i in (*.mp3 *.wma) do @if not exist "%~ni.lrc" echo. %%i
严格格式排版版:
@del /a /f /q G:\list.txt 2>nul
@for /r %%i in (*.mp3 *.wma) do @if not exist "%%~dpni.lrc" call :sub "%%i"
@goto :EOF
:sub
@if "%~dp1" NEQ "%dir%" set "dir=%~dp1" &echo. ---%dir%>>G:\list.txt
@if not exist "%~dpn1.lrc" echo. %~n1>>G:\list.txt
@goto :EOF
Simple command-line display version:
@for /r %i in (*.mp3 *.wma) do @if not exist "%~ni.lrc" echo. %%i
Strictly formatted version:
@del /a /f /q G:\list.txt 2>nul
@for /r %%i in (*.mp3 *.wma) do @if not exist "%%~dpni.lrc" call :sub "%%i"
@goto :EOF
:sub
@if "%~dp1" NEQ "%dir%" set "dir=%~dp1" &echo. ---%dir%>>G:\list.txt
@if not exist "%~dpn1.lrc" echo. %~n1>>G:\list.txt
@goto :EOF
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-10-2 05:18 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
:sub
@if "%~dp1" NEQ "%dir%" set "dir=%~dp1" &echo. ---%dir%>>G:\list.txt
@if not exist "%~dpn1.lrc" echo. %~n1>>G:\list.txt
@goto :EOF
发现%%i 重新赋予%1居然还可以使用for的变量扩充.....
:sub
@if "%~dp1" NEQ "%dir%" set "dir=%~dp1" &echo. ---%dir%>>G:\list.txt
@if not exist "%~dpn1.lrc" echo. %~n1>>G:\list.txt
@goto :EOF
Found that %%i is reassigned to %1, and it can still use the variable expansion of for.....
|
|
2006-10-2 08:27 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
要是可以弄到像芊芊静听那样自动下载歌词就好了
It would be nice if we could get something like Qianqian Jingting that automatically downloads lyrics.
|
|
2006-10-3 08:01 |
|
|
yayumyself
初级用户
 
积分 36
发帖 14
注册 2006-9-6
状态 离线
|
|
2007-6-21 17:35 |
|
|
yayumyself
初级用户
 
积分 36
发帖 14
注册 2006-9-6
状态 离线
|
『第 14 楼』:
这个是检测有没有歌词没有对应的音乐文件
使用 LLM 解释/回答一下
@echo off&setlocal enabledelayedexpansion&color 1f
mode con:cols=50 lines=25
title 删除mp3上未匹配的歌词 http://hi.baidu.com/xinghuo
set n=0
if "%~1"=="" (
echo 请直接拖放包含音乐的文件夹到此文件上
ping /n 6 127.0.0.1>nul&exit
) else (
echo 当前检测目录为:%~1
)
echo _________
for %%i in ("%1\*.lrc") do (
if not exist %1\%%~ni.wma (
if not exist %1\%%~ni.mp3 set/a n+=1&set name!n!=%%i&echo %%~nxi --Not Find )
)
echo.
if %n%==0 echo 所有歌词都匹配&echo 程序来自: http://hi.baidu.com/xinghuo&pause>nul&exit
set /p sure=是否删除这些歌词文件(Y),其他键退出:
if /i "%sure%"=="y" (
cls
echo 正在删除...
for /l %%a in (1,1,%n%) do (
del "!name%%a!" 2>nul
)
echo.&echo ^^_^^,世界清静了!
echo 程序来自: http://hi.baidu.com/xinghuo
)
pause>nul
exit
@echo off&setlocal enabledelayedexpansion&color 1f
mode con:cols=50 lines=25
title Delete Unmatched Lyrics from MP3 http://hi.baidu.com/xinghuo
set n=0
if "%~1"=="" (
echo Please directly drag and drop the folder containing music onto this file
ping /n 6 127.0.0.1>nul&exit
) else (
echo Current detection directory is: %~1
)
echo _________
for %%i in ("%1\*.lrc") do (
if not exist %1\%%~ni.wma (
if not exist %1\%%~ni.mp3 set/a n+=1&set name!n!=%%i&echo %%~nxi --Not Find )
)
echo.
if %n%==0 echo All lyrics are matched&echo Program from: http://hi.baidu.com/xinghuo&pause>nul&exit
set /p sure=Do you want to delete these lyric files?(Y), press other keys to exit:
if /i "%sure%"=="y" (
cls
echo Deleting...
for /l %%a in (1,1,%n%) do (
del "!name%%a!" 2>nul
)
echo.&echo ^^_^^, The world is quiet!
echo Program from: http://hi.baidu.com/xinghuo
)
pause>nul
exit
|
|
2007-6-21 18:21 |
|