특정 노래 길이의 노래에 대한 mp3 컬렉션 검색

특정 노래 길이의 노래에 대한 mp3 컬렉션 검색

특정 길이의 노래에 대해 mp3 파일 디렉토리를 어떻게 검색합니까? 전:

findmp3 -min=03:00 -max=03:15 /music/mp3/ebm/

emb/노래 길이가 3분에서 3분 15분 사이인 디렉터리 의 모든 mp3 파일을 반환합니다 .

저는 Linux Mint, Ubuntu, CentOS를 사용합니다.

답변1

먼저 설치하려면 mp3info배포판의 저장소에 있어야 합니다(아직 언급하지 않았으므로 일종의 Linux를 사용하고 있다고 가정합니다). 데비안 기반 배포판이 있다면 다음과 같이 할 수 있습니다.

sudo apt-get install mp3info

일단 mp3info설치되면 다음 명령을 사용하여 디렉토리 music에서 특정 길이의 노래를 검색할 수 있습니다.

find music/ -name "*mp3" | 
  while IFS= read -r f; do 
   length=$(mp3info -p "%S" "$f"); 
   if [[ "$length" -ge "180" && "$length" -le "195" ]]; then 
     echo "$f"; 
   fi;  
done

위의 명령은 music/mp3 파일을 검색하고 길이가 180초(3:00) 이상 195초(3:15) 이하인 경우 이름과 길이를 인쇄합니다. man mp3info출력 형식에 대한 자세한 내용은 을 참조하세요 .

MM:SS 형식으로 시간을 입력하려면 좀 더 복잡해집니다.

#!/usr/bin/env bash

## Convert MM:SS to seconds.
## The date is random, you can use your birthday if you want.
## The important part is not specifying a time so that 00:00:00
## is returned.
d=$(date -d "1/1/2013" +%s);

## Now add the number of minutes and seconds
## you give as the first argument
min=$(date -d "1/1/2013 00:$1" +%s);
## The same for the second arument
max=$(date -d "1/1/2013 00:$2" +%s);

## Search the target directory for files
## of the correct length.
find "$3" -name "*mp3" | 
  while IFS= read -r file; do 
   length=$(mp3info -p "%m:%s" "$file"); 
   ## Convert the actual length of the song (mm:ss format)
   ## to seconds so it can be compared.
   lengthsec=$(date -d "1/1/2013 00:$length" +%s);

   ## Compare the length to the $min and $max
   if [[ ($lengthsec -ge $min ) && ($lengthsec -le $max ) ]]; then 
       echo "$file"; 
   fi; 
done

위 스크립트를 findmp3다음과 같이 저장하고 실행해 보세요.

findmp3 3:00 3:15 music/

답변2

기존 도구가 있는지 의심됩니다 findmp3. 유닉스 철학에 따라 파일 find찾기 .mp3, 찾은 각 파일의 길이를 보고하는 또 다른 도구 find및 일부 셸/텍스트 처리 접착제를 구축할 수 있습니다.

SoX사운드 파일 작업에 일반적으로 사용 가능한 유틸리티입니다(sox는 텍스트 파일에 대한 sed 또는 awk의 사운드를 나타냅니다). 명령soxi사운드 파일에 대한 정보를 표시합니다. 특히 soxi -D기간을 초 단위로 인쇄합니다.

.mp3파일에 대해 아래 코드 조각은 soxi해당 출력을 호출하고 구문 분석합니다. 기간이 원하는 범위 내에 있으면 sh호출이 성공 상태를 반환하므로 -print파일 이름을 인쇄하는 작업이 실행됩니다.

find /music/mp3/ebm -type f -name .mp3 -exec sh -c '
    d=$(soxi -D "$0")
    d=${d%.*} # truncate to an integer number of seconds
    [ $((d >= 3*60 && d < 3*60+15)) -eq 1 ]
' {} \; -print

bash, ksh93 또는 zsh에서는 find. ksh에서 set -o globstar먼저 실행하십시오. Bash에서는 shopt -s globstar먼저 실행하십시오. bash에서는(ksh나 zsh에서는 제외) **/디렉터리에 대한 기호 링크를 통해 반복됩니다.

for f in /music/mp3/ebm/**/*.mp3; do
  d=$(soxi -D "$0")
  d=${d%.*} # truncate to an integer number of seconds (needed in bash only, ksh93 and zsh understand floating point numbers)
  if ((d >= 3*60 && d < 3*60+15)); then
    echo "$f"
  fi
done

답변3

사용 ffmpeg:

find . -name \*.mp3|while IFS= read -r l;do ffprobe -v 0 -i "$l" -show_streams|awk -F= '$1=="duration"&&$2>=180&&$2<=195'|read&&echo "$l";done

mp3info짧막 한 농담:

find . -name \*.mp3 -exec mp3info -p '%S %f\n' {} +|awk '$1>=180&&$1<=195'|cut -d' ' -f2-

또는 OS X에서는:

mdfind 'kMDItemDurationSeconds>=180&&kMDItemDurationSeconds<=195&&kMDItemContentType=public.mp3' -onlyin .

답변4

ffmpeg -i  yourmp3.mp3  2>&1 | grep Duration | sed 's/Duration: \(.*\), start/\1/g'  |awk {'print $1'}

위 명령을 사용하면 기간을 얻을 수 있으므로 기간에 대한 도메인을 지정하도록 스크립트를 작성할 수 있습니다. 또한 다음을 사용할 수 있습니다.

find yourPath -iname "*mp3" -exec ffmpeg -i  {}   2>&1 | grep Duration | sed 's/Duration: \(.*\), start/\1/g'  |awk {'print $1'}

yourPath를 mp3 저장소의 루트로 바꾸십시오.

관련 정보