[Bash脚本]APE/Flac分轨转换成MP3,并正确写入id3v2

Posted on 2008年8月01日 20:26

脚本说明

#!/bin/bash

# Split the big single ape/flac file and then convert to mp3 format.
# Lastly, write the id3(version 2) tag info into the mp3s.
#
# Ensure that your cue file is *UTF-8* encoding. NO GB* id3!
#
# Required: mac, flac, lame, cuetools, mutagen, shntool
#
# Edited from Brian Archive CUE/FLAC Splitter v0.1
# ;-) vvoody <wxj.g.sh{at}gmail.com>


if [ "$1" == "--help" ]; then
     echo "======================================="
     echo " Usage: $0 your.ape|flac your.cue" 1>&2
     echo "======================================="
     exit 0
fi

if [ $# -lt 2 ]; then
     echo "======================================="
     echo " Usage: $0 your.ape|flac your.cue" 1>&2
     echo "======================================="
     exit 1
fi

hifile=$1 # .ape or .flac lossless audio file
cuefile=$2

tracks=$(cueprint -d '%N' "$cuefile")

# Store the idv3 info. We will write them to the mp3s later.
id3count=1
while [ $id3count -le $tracks ]; do
     artist[$id3count]=$(cueprint -n$id3count -t '%p' "$cuefile")
     album[$id3count]=$(cueprint -n$id3count -t '%T' "$cuefile")
     tracknum[$id3count]=$(cueprint -n$id3count -t '%02n' "$cuefile")
     title[$id3count]=$(cueprint -n$id3count -t '%t' "$cuefile")
     echo "Artist      - ${artist[$id3count]}"
     echo "Album       - ${album[$id3count]}"
     echo "Track No.   - ${tracknum[$id3count]}"
     echo "Track Title - ${title[$id3count]}"
     echo
     id3count=$[$id3count + 1]
done

echo "=================================================="

# Split and convert the single ape/flac file.
# Each mp3 name is like: "07.Yesterday Once More.mp3"
# Default bit rate is 128, you can customize it by using -b option.
# More output format, see `man shntool`
 shntool split -f "$cuefile" -t '%n.%t' -o 'cust ext=mp3 lame -b 192 - %f' "$hifile"

# Write the id3v2 into the mp3 files.
acount=1
for mp3file in *.mp3; do
     mid3v2 --artist="${artist[$acount]}" --album="${album[acount]}" --track="${tracknum[acount]}" \
         --song="${title[acount]}" "$mp3file"
     acount=$[$acount + 1]
done

# End of script.
#!/bin/bash

# Convert the ape/flac files(splited) to mp3 format.
# 01.a.flac, 02.xy.flac,... -> 01.a.mp3, 02.xy.mp3, ...
#
# ;-) vvoody <wxj.g.sh{at}gmail.com>

if [ "$1" == "--help" ]; then
    echo "Usage: $0 your.cue orig_format"
    exit 1
fi

cuefile=$1
ext=$2

count=1
for f in *.${ext}; do
    artist=$(cueprint -n$count -t '%p' "$cuefile")
    album=$(cueprint -n$count -t '%T' "$cuefile")
    tracknum=$(cueprint -n$count -t '%02n' "$cuefile")
    title=$(cueprint -n$count -t '%t' "$cuefile")
   
    shntool conv -i $ext -o 'cust ext=mp3 lame -b 192 - %f' "$f"
   
    mp3file="$(basename "$f" .$ext).mp3"
    echo "$mp3file"
    mid3v2 --artist="$artist" --album="$ablum" --track="$tracknum" \
        --song="$title" "$mp3file"

    count=$[$count + 1]
done
 

 

 

 

 

 

 

不错的bsp

Posted on 2008年7月31日 21:52

这个主题很赞!

测试些代码加亮。

C

 

/* Print the numbers between 1 and 1000. */
/* Add a rule: Don't use any loops. */
/* Add another rule: No recursions. */

#include <stdio.h>

#define A(x) x;x;x;x;x;x;x;x;x;x;

int main(void)
{
  int n = 1;
  A(A(A(printf("%d, ", n++))));
  return 0;
}

 

Python

 

# by Peter Norvig
import re, collections

def words(text): return re.findall('[a-z]+', text.lower())

def train(features):
     model = collections.defaultdict(lambda: 1)
     for f in features:
         model[f] += 1
     return model

 NWORDS = train(words(file('big.txt').read()))

 alphabet = 'abcdefghijklmnopqrstuvwxyz'

def edits1(word):
     n = len(word)
     return set([word[0:i]+word[i+1:] for i in range(n)] +                     # deletion
                [word[0:i]+word[i+1]+word[i]+word[i+2:] for i in range(n-1)] + # transposition
                [word[0:i]+c+word[i+1:] for i in range(n) for c in alphabet] + # alteration
                [word[0:i]+c+word[i:] for i in range(n+1) for c in alphabet])  # insertion

def known_edits2(word):
     return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS)

def known(words): return set(w for w in words if w in NWORDS)

def correct(word):
     candidates = known([word]) or known(edits1(word)) or known_edits2(word) or [word]
     return max(candidates, key=lambda w: NWORDS[w])

 

 

Shell

 

#!/bin/bash

list=`ps aux | grep $1 | grep -v "grep $1"`
pid=`echo $?`

echo $pid

if [ $pid = 0 ]; then
    for i in `echo $list | awk '{print $2}'`; do
        kill -9 $i 2>/dev/null
    done
else
    echo "No such process!"
fi

 

 

 

HTML

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>vvoody's woody house</title>
  <link type="text/css" rel="stylesheet" href="style.css" />
  <link rel="openid.server" href="http://www.myopenid.com/server" />
  <link rel="openid.delegate" href="http://vvoody.myopenid.com/" />
</head>
<body>
<h1>vvoody's &copy; Site-></h1>

<ul>
    <li><a href="blog/">blog</a></li>
    <li><a href="http://vvoody.org/blog/?page_id=9">Do you want to say sth. to me? </a></li>
</ul>
<p>
<b>Keep It Simple, Slack</b>
</p>
<p>
<b>Your heart is free. Have the courage to follow it.</b>
</p>
<!--<p>
-->
<!-- <a href="http://validator.w3.org/check?uri=referer">
-->
<!--  <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" />
</a>-->
<!-- <a href="http://jigsaw.w3.org/css-validator/">
-->
<!--  <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" />
</a>-->
<!--</p>
-->
</body>
</html>