RaspberryPI als Automatischer AudioCD-Ripper

feissmaik
Entwickler Team
Beiträge: 2576
Registriert: So 17. Apr 2011, 11:39
Been thanked: 1 time
Kontaktdaten:

RaspberryPI als Automatischer AudioCD-Ripper

Beitrag von feissmaik »

Ein kleines Project um mithilfe eines an den RPI angeschlossenen USB-CDRom automatisch AudioCDs zu rippen...

Die Idee ist einfach nur die CD einzulegen und der RaspberryPI kümmert sich um alles weitere - wenn er fertig ist wird die CD wieder ausgeworfen :D

Was wird benötigt:
  • USB CDRom Laufwerk
  • UDEV
  • abcde
  • unten stehendes C++ Script
WTH is abcde ?
Spoiler
Show
Abcde is a frontend command-line utility (actually, a shell script) that grabs tracks off a CD, encodes them to ogg or mp3 format, and tags them, all in one go.

Your finished Oggs/MP3's are, by default, stored in a subdirectory of the
current directory (named after the artist) with a filename based on the
track title. Spaces are replaced by underscores, and apostrophes and
control codes are filtered out. Colons are replaced with an underscore and a
hyphen. The end result usually looks like: Our_Lady_Peace/Supermans_Dead.mp3
This filename munging is customizable - edit the mungefilename function in
your abcde.conf to change it.

Abcde supports:

CDDA using cdparanoia or cdda2wav
Ogg Vorbis using oggenc or vorbize
MP3 using lame, gogo, bladeenc, mp3enc, xingmp3enc, or l3enc
CDDB using cd-discid, wget, and FreeDB
Ogg commenting using vorbiscomment
Tagging using id3 and id3v2
m3u playlists
Distributed remote MP3 encoding using distmp3
Simultaneous reading and encoding
SMP systems
Resuming interrupted sessions
Noninteractivity
Error logging of background processes
Various Artists discs of all types
Custom filename output and munging
Passing arbitrary options to subprocesses
Ejecting CD's after reading
Encoder nicing
Grabbing arbitrary ranges of tracks

Code: Alles auswählen

apt-get install abcde
Weitere Tools sind auch hier gelistet: http://wiki.ubuntuusers.de/CDs_rippen#Terminal
(da gibts auch nen Link zu ner Beschreibung von abcde)
abcde muss dann über die /etc/abcde.conf so konfiguriert werden dass die gerippten Dateien direkt auf einen externen Datenträger geschrieben werden (OUTPUTDIR) - ob das ein Netzwerk Mount ist oder ein USB-Stick ist relativ egal, hauptsache nicht auf die SD Karte sonst lebt die nicht mehr lange :?

Die Konfigurationsdatei ist zwar erschlagend umfangreich, man sollte sie sich aber trotzdem gründlichst anschauen ;)


UDEV muss man ausserdem unbedingt über /etc/udev/rules/99-cd.rule konfigurieren, damit es als aller letztes ausgeführt wird.. In der UDEV Rule steht dann drin das ein kleines C++ Programm ausgeführt wird, welches feststellt ob es sich um eine AudioCD handelt - und falls das der fall ist, wird der Ripper ausgeführt

/etc/udev/rules/99-cd.rule:
Spoiler
Show

Code: Alles auswählen

SUBSYSTEM=="block", KERNEL=="sr0", ENV{DKD_MEDIA_AVAIABLE}=="1", RUN+="/bin/detectdisc"

Das C++ Programm nutzt die in Linux intergierten Bibliotheken zum erkennen ob es sich bei der eingelegten CD um eine AudioCD handelt und führt nur dann abcde aus:
(die Options müsste man entsprechend noch anpassen, oder die abcde.conf anpassen)
Spoiler
Show

Code: Alles auswählen

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
	string command = "abcde -d /dev/cdrom -N -o mp3 -q high -x";  /* define command to get executed */
	int dev,type;
	if((dev=open("/dev/cdrom",O_RDONLY | O_NONBLOCK)) == -1)
		printf("Fehler open()\n");
	type=ioctl(dev,CDROM_DISC_STATUS);
	if(type==CDS_AUDIO)
		printf("Audio Disc!!\n");
		system(command.c_str());  /* execute command */
		return 0;
	else
		printf("Keine Audio Disc\n");
		return 1;
}
Die Ausgabe könnte man auch noch in ein Logfile umleiten, was zB im /var/www/ liegt sodass man dann auch noch prüfen könnte ob das Rippen erfolgreich war...

Script in zB detectdisc.cpp copy&pasten (Dateiendung ist wichtig) und zum kompilieren:

Code: Alles auswählen

g++ -o /bin/detectdisc detectdisc.cpp
Danach steht die ausführbare Binary als /bin/detectdisc bereit, also zum testen einfach detectdisc eingeben



...Soviel zur Theorie... Mein USB-CDRom ist leider nich nicht da aber vorbereitet hab ichs schonmal :P
Du musst nicht kämpfen um zu siegen

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast