1

I have separated some tracks from mp3 mixes using mp3splt.

BASH: (mp3splt -c('**!!***use .cue file***!!**') [cuefile.cue] [nonstopmix.mp3] ~for anyone interested, is in the Ubu repos~)

And I ended up with these filenames: "Antares" - 01 - "Xibalba".mp3 which is not a format I prefer, now I've made it a little project to change them with a shell script but its more difficult than I anticipated.

I want to change the filename from:

"Antares" - 01 - "Xibalba".mp

to:

01-Antares_-_Xibalba.mp3

so far I've used :

for var in *.mp3; do mv $var {var/"/}; done

and I could repeat that until I'm through, delete the 0x number and add one but I'd like to do it more efficient.

Could anyone give me a pointer (!not a script!) ? I'd still like to write it myself but there's so much options that I'm a bit lost.

so far I thought to use this program flow:

  1. read all the filenames containing .mp3 and declare as variable $var

  2. strip $var from quotes

  3. select 0x number, append delimiter _ (0x_)

  4. move 0x_ to the beginning of the string

  5. select remaining ' - - ' and change to '-'

done

which bash programs to use? especially changing the 0x puzzles me cuz I need a loop which increments this number and test if it is present in the filename variable and then it has to be changed.

4

2 回答 2

0

在 python 2.x 中很容易做到。您可以在任何您想要的语言中使用此逻辑。

import string
a=raw_input('Enter the name of song')
a=a.replace('"', "")
a=a.replace('.mp', ' .mp3')
words = a.split()
print words[2]+'-'+words[0]+'_-_'+words[4]+words[5]

逻辑:

我删除了“,然后将 .mp 转换为 .mp3,然后拆分字符串,创建一个列表(数组),然后根据需要打印元素。

于 2013-09-28T17:12:15.760 回答
0

尝试这样做:

rename -n 's/"(\w+)"\s+-\s*(\d+)\s*-\s*"(\w+)"\.mp/$2-$1_-_$3.mp3/' *mp

shell提示。它非常有用,您可以像我一样将一些技巧放在替换中。

当您的测试有效时,您可以移除-n(试运行模式开关)。

警告 还有其他同名的工具可能会也可能不会这样做,所以要小心。

如果您运行以下命令 ( linux)

$ file $(readlink -f $(type -p rename))

你有一个像

.../rename: Perl script, ASCII text executable

那么这似乎是正确的工具=)

如果不是,则使其成为默认值(通常已经如此)Debian和衍生,例如Ubuntu

$ sudo update-alternatives --set rename /path/to/rename

最后但同样重要的是,这个工具最初是由 Perl 的父亲 Larry Wall 编写的。

于 2013-09-28T13:08:16.017 回答