dir2ogg is a python script which converts mp3, m4a, and wav files into ogg-vorbis format. It was inspired by the perl script mp32ogg. The script requires that you have python, oggenc (part of the vorbis-tools package) , and mpg123 (or mpg321 with the appropriate symlink). dir2ogg supports id3 tags, this feature requires you to install pyid3lib. pyid3lib is a python module that allows manipulation of id3 tags. It is not in the standard library, however, it is freely available from http://pyid3lib.sourceforge.net/, and is simple to install. If you choose not to install this module you can still use the script, and scratch tags will be created using the filename as basis. If you want to convert m4a files you must have faad installed..

If you want a quick peek at the source you can preview dir2ogg.
note for those looking to convert m4a to mp3:

Looking at my webalizer stats I can see that a large number of people are coming to this page using a search query like 'convert m4a to mp3'. My script does not convert to mp3s, but I am loathe to allow anyone to leave my site unsatisfied...so here you go:

$ faad foobar.m4a # convert to wav
$ lame foobar.wav foobar.mp3 # convert to mp3

Steve Nixon has sent in a shell script which automates the above commands. Thanks Steve...
If you are using windows you may want to have a look at BonkEnc. Tip courtesy of Wim Vander Schelden.
download dir2ogg

The current stable version:

* dir2ogg version 0.9.1 : Released April 1, 2005. [md5]

Older versions:

* dir2ogg version 0.9 : Released January 27, 2005. [md5]
* dir2ogg version 0.9pre1 : Released December 9, 2004. [md5]
* dir2ogg version 0.8 : Released September 27, 2004. [md5]
* dir2ogg version 0.7 : Released August 23, 2004.
* dir2ogg version 0.6 : Released May 24, 2004.
* dir2ogg version 0.5 : Released May 14, 2004.
* dir2ogg version 0.4 : Released October 8, 2003.
* dir2ogg version 0.03 : Released September 12, 2003.
* dir2ogg version 0.02 : Released a while ago ;)
* dir2ogg version 0.01: crusty old shell script version. Only included here to elicit flames. Released many moons ago...

I have also written an Ebuild script for those that run Gentoo. Note: These are redundant, as dir2ogg is in the portage tree now. Version 0.8 is marked stable for x86, amd64, and sparc. Really though, as long as your platform supports python, vorbis-tools, and mpg123, dir2ogg should work just fine for you.

* dir2ogg-0.9.1.ebuild
* dir2ogg-0.9.ebuild
* dir2ogg-0.8.ebuild

It has been brought to my attention that Christian Marillat maintains a collection of primarily multimedia debian packages, of which one is for dir2ogg. Add the following to your /etc/apt/sources.list to access it:

deb ftp://ftp.nerim.net/debian-marillat/ unstable main
deb-src ftp://ftp.nerim.net/debian-marillat/ unstable main

Ok, so I didn't know this but apparently you can use a gentoo ebuild to make rpms out of any package in portage. I gave it a try and sure enough, it spits out an rpm for dir2ogg. Now, I don't use any distros that uses the rpm package manager, so this thing is _completely_ untested by me or anyone else! That being said I am kind of curious. If you want to try this go nuts, and please send a note on how it goes ;)

* dir2ogg-0.8.i386.rpm

Installation and Usage

dir2ogg is very simple to install and use. The tar package contains five files. 1) a README with installation instructions and other info. Make sure you read this file for the most recent info. 2) dir2ogg: the script itself. 3) dir2ogg.1: the manpage. 4) LICENCE: the Artistic License, under which dir2ogg is released. 5) install.sh: A bash script for automating installation.

Command line gurus will probably just want a quick glance at the man page.

Installation is as easy as:

$ tar xzf dir2ogg-0.8.tar.gz
$ cd dir2ogg
$ sh install.sh # install the script and manpage

This will have to be done as root of course. Usage is just as easy. To convert a single mp3:

$ dir2ogg foo.mp3

To convert an mp3, an m4a and a wav:

$ dir2ogg foo.mp3 bar.m4a baz.wav

Alternatively, you can use shell-globbing:

$ dir2ogg fooBand-*.mp3
$ dir2ogg *{.m4a,.mp3}

To convert directories you simply pass the directories as arguments, or alternatively you can cd to the directory you wish to act upon and use '.' to denote the current directory.

Single directories:

$ dir2ogg -d /path/to/mp3directory
$ cd /path/to/another/mp3directory
$ dir2ogg -d .

Multiple directories:

$ dir2ogg -d /path/1/ /path/2 /path/3
$ dir2ogg -d . foo/ foo/bar/

dir2ogg 0.9 command line flags:

General options:

-h or --help
Print quick usage details.
-qN or --quality=N
Ogg quality. 'N' is an integer between 1 and 10. Default is 4. See 'man oggenc'.
-v or --verbose
Increase verbosity. At this point all it does is list the id3 tags that will be written, and print a list of files that will be converted when used with -d.
-s or --shell-protect
Convert spaces in filenames to underscores.
-x or --delete-mp3
Deletes original mp3 file after converting.
-a or --delete-m4a
Deletes original m4a file after converting.
-p or --preserve-wav
Preserves wav files. By default they are deleted after converting.
-d or --directory
Convert all mp3s in a directory. At this time only one directory can be named per run.

Options that are only used with -d or --directory:

-m or --convert-m4a
Convert m4a files in directory as well as mp3s
-w or --convert-wav
Convert wav files in directory as well as mp3s
-n or --no-mp3
Do not convert mp3 files. This only makes sense when used with -m and/or -w

Command line flags can be made in any order. When using -d or --directory dir2ogg expects exactly one argument after the options.

More examples:

$ dir2ogg -s "song with spaces.mp3"

converts to song_with_spaces.ogg

$ dir2ogg -dx .

converts all mp3s in the current directory, mp3s are deleted

$ dir2ogg -p --quality=6 "Some Band - Some Song.m4a"

converts to "Some Band - Some Song.ogg". Temporary wav file is preserved, ogg quality is set to '6'

$ dir2ogg -dwm .

converts all mp3, m4a, and wav files in current directory

What kind of narcissistic loser would post a screenshot of a cli app? Me, of course. Here's dir2ogg in action
Known bugs and Caveats:

December 1, 2004:
Fixed bug where m4a files with spaces break the script. My bad, sorry folks.

Older versions of dir2ogg do not check the exit status of mpg123 or faad. This means that if your mp3 or m4a is corrupted, or otherwise triggers an error it will NOT be handled. This is bad if say, your using the -x or -a flag, because the original file will be deleted even though the conversion was not successful. This is fixed in versions 0.9pre1 and 0.9.

Converting from MP3 or M4A to OGG is a conversion between two lossy formats. This is fine if you just want to free up some disk space, but if you're a hard-core audiophile you may be disappointed. I really can't notice a difference in quality with 'naked' ears myself. You might want to do your conversion, then compare with the original before erasing them.

Some special characters in filenames will break the script.

Please send bug reports to this address.
0.9.1 :: April 1, 2005

This release allows multiple directories to be specified on the command line. Also, there is now support for the 'track number' id3 tag. It will show up as either '5' which shows track 5, or '5,17' which shows track 5 of 17 on the original album.
0.9 :: January 27, 2005

The changes between 0.9 and 0.9pre1 are trivial, so everything below applies to 0.9. To reiterate, your filename _may_ be changed, and error checking for mpg123, oggenc, and faad is included. Have fun!
0.9pre1 :: December 9, 2004

In dir2ogg 0.9pre1 the special characters '"', '*', '!', and ';' will be removed from filenames. The special character '&' will be converted to 'and'. These characters are known to break the script when fed to bash. If you don't like the idea of this script changing your filenames that's fair enough, but I submit these characters have no business being in proper unix filenames anyway. If I get the time I will try to change this so they are escaped rather than removed.

Also in this version, the exit status of mpg123, faad, and oggenc is checked, and should be handled apropriately. This means if you are using the 'x' or 'a' flags, your original file won't be deleted if mpg123 throws an error. Something you would expect of course, but with me it takes time for such 'features' ;)

And finally after two years I added some sanity checks on the filename/directory arguments passed to the script. So now if you mistype a filename you will get a stern warning about your file not being found from dir2ogg instead of a 50 line traceback from python.
0.8 :: September 27, 2004

dir2ogg 0.8 is pretty much a re-write from scratch. The original dir2ogg was not much more than an exercise for me. I was "scratching an itch" as ESR might say. I found myself converting mp3s to oggs quite frequently, and thought that others may be doing this as well, which is why I released dir2ogg in the first place. As my skill in Python increased, I added more features to dir2ogg...and the more I added to my original code the cruftier it got.

dir2ogg is now object-oriented instead of procedural. In addition to hundreds of unseen advantages, this will allow me to add new features in the future easily and cleanly. Along with a base of cleaner and more efficient code, dir2ogg 0.8 includes these benefits:

* Full support of GNU style short and long options.
* Ability to specify multiple filenames on the command line.
* In the absence of 'real' ID3 tags, scratch tags are created for all files.
* Coloured output to easily tell dir2ogg's output from oggenc's, faad's and mpg123's output.
* Many small bug-fixes.

0.8pre1 :: September 23, 2004

I am putting the finishing touches on a complete re-write of dir2ogg. Version 0.8 is going to be vastly superior to 0.7 for many reasons including full support for GNU-style long and short command line options, extensive exception handling, improved program logic, the ability to specify multiple files on the command line, and many, many more.
0.7 :: August 23, 2004

Version 0.7 has support for converting m4a and wav files to ogg format. To convert m4a files you will need faad installed. This version also fixes some bugs, including adding uppercase file extensions to the list of files to be converted ie: MP3, M4A, and WAV. Even if you don't intend to convert m4a files, you should still use this version.
0.6 :: May 24, 2004

This version introduces new command line flags. Deleting the .wav and .mp3 files is now user-controlled, there is an option to preserve the shell-protected filename, and there is also a verbose flag. Plus the '-dir' flag is now obsolete. Please us 'd' instead. NOTE: the new command line option flags do not need to be preceded by a dash. There cannot be any spaces between options on the command line. See Installation and Usage below...
0.5 :: May 14, 2004

dir2ogg 0.5 is in the Ibiblio Linux Archive.

dir2ogg now allows spaces in your filenames. The script uses sed to convert spaces to underscores, the conversion is made, then the underscores are reverted back to spaces. This is not fool-proof however...some special characters will cause the script to break. dir2ogg tries to deal with this gracefully, but I cannot anticipate every filename possible (there are some doozies when downloading mp3s from windows users ;)). Generally, if you use sensible filenames this will not be a problem for you. Keep in mind that you will still have to escape the filenames for bash ie: dir2ogg "song with spaces.mp3". Using "dir2ogg -dir ." will work fine however. Please read the updated manpage for more details.
0.4 :: October 8, 2003

I have bumped the version number up to 0.4 to reflect its 'stable' status. For almost everyone this is the version you will want to use. Also of note: dir2ogg is now a part of the Ibiblio Linux archive. It's home will always be this page, but my site is not always up...so you will always be able to get it from Ibiblio.


このページは、ossanが2011年2月21日 09:58に書いたブログ記事です。