Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi ,
I have a *very* newbie question :-)
Amarok has a problem displaying utf-8 id3v2 tags properly and I found the solution on the amarok web site. However, they give a perl script saying that it solves the problem but I never used perl script before and I have no idea how to do it and what I am supposed to do with this line of code:
Code:
#!/usr/bin/perl
die "File $ARGV[0] doesn't exist" unless -f $ARGV[0];
use MP3::Mplib;
my $mp3 = MP3::Mplib->new($ARGV[0]);
my $v2tag = $mp3->get_v2tag;
print "Error writing tags of $ARGV[0]\n" unless $mp3->set_v2tag($v2tag,&UTF8);
Hi, you can put this code into a file like mp3-utf8.pl, chmod it to have the x bit (like 'chmod +x mp3-utf8.pl') and execute it with the mp3 file as an argument, like './mp3-utf8.pl mysong.mp3'.
Alternative to chmod, you could run the script with 'perl mp3-utf8.pl' with which you tell 'perl' to go and run the script mp3-utf8.pl
A little explanation for each line of code for your information:
#!/usr/bin/perl ### The 'shabang' line, telling the kernel to use perl as interpreter for this file. die "File $ARGV[0] doesn't exist" unless -f $ARGV[0]; ### exit if the file passed as an argument isn't a file (like non-existent or a directory, for instance). use MP3::Mplib; ### 'use' tells perl to load a module, called MP3::MPlib my $mp3 = MP3::Mplib->new($ARGV[0]); ### instantiate an object with the loaded module. it is 'loading' the mp3 file passed as an argument. the object is called '$mp3' my $v2tag = $mp3->get_v2tag; ### with this line, the tag is retrieved from the mp3 file into the variable '$v2tag'. print "Error writing tags of $ARGV[0]\n" unless $mp3->set_v2tag($v2tag,&UTF8); ### says: tell there is a problem unless you are successful in writing the previously read tag into the file, using UTF8 encoding.
I hope this answers your question... or I may have interpreted your question completely wrong... in that case, sorry for the redundant response..
If you want something else answered, please respond, I might be able to help you out. . . ?
Thank you very much for your answer, I was not expecting that much :-)
I still have a last prob with that: is there a way I automate this process? I mean it's a script supposed to help amarok to display correctly id3-v2 tags correctly using utf8. I am guessing that this script should be run by amarok in background all the time ( correct me if I'm wrong) and I was wondering how to tell amarok to do so...
thanks for your help,
A.
This script seems to be designed to alter mp3 files.. once run on an mp3 file, the file is prepared to be read correctly by amarok. Try it out on one mp3 file that amarok has trouble with. copy it to a new filename, run this script on it, and open the 'altered' file with amarok.. determine if it worked fine.
This script is not meant to run 'while amarok runs'...
Hi,
Thank you very much. Actually it works great and now it looks like I am going to be able to "repair" all these tags. However, I still have a little issue: I have to do that on all the songs using unicode charaters and I have * alot* of them, is it possible to have a command that apply these script to *all* the mp3 file within a given directory (the unicode one are in a separated directory), because doing everything by hand... would be *very* long... there are around a thousand songs to alter...
Thanks again for your help!
A.
Thanks for your answer but this gives me an error:
doing it within the mp3 directory I get:
$ ls *.mp3 | xargs /home/arnaud/mp3-utf8.pl
ls: *mp3: No such file or directory
File doesn't exist at /home/arnaud/mp3-utf8.pl line 2.
Any ideas?
A.
Thanks but my script is in the right place (/home/arnaud/mp3-utf8.pl). However the problem is that the mp3 files are all in different folders. I was looking for a way to affect all the mp3 files within my mp3 directory in spite of the fact that in this directory mp3 files are organized in their own different folders. Well if it's too much of a pain I'll just removed those folders and put all the mp3 files in only one directory.
Thanks,
A.
Go to the 'main folder' in which all the mp3 files are (or in subdirectories of that folder (ie, the root folder of arr mp3 files)).
for i in `find . -name *mp3`; do echo "Processing $i"; <directory-to-script>/mp3-utf8.pl $i;done
That would do it from the shell prompt...
Also, the script could be redesigned to handle directories instead of single files... but that would be a redesign, this is quicker.
Hi thanks for your answer!
Actually it gives me a lot of error saying that a file doesn't exist at /home/arnaud/mp3/mp3-utf8.pl line 2.
I tried previously with for f in `find /mp3 -name \*.mp3`; do ./mp3-utf8.pl "$f"; done
but same result...
Any ideas?
Thanks a lot!
A.
Originally posted by Arnaud_B Hi thanks for your answer! I actually did it with $perl mp3-utf8.pl `find /mp3 -name \*.mp3` and it seems to work like that... could you explain me the difference between this and the command you suggested me?
Thanks a lot!
A.
For what Eddybaby1023 writes to work, the script would have to be redesigned, as it would receive lots of parameters, while it can only take one. Here's a redesign to process a lot of subderictories in one run:
Just give it a directory to process recursively.
Code:
#!/usr/bin/perl
use strict;
use MP3::Mplib;
my $directory=shift or die "Give a directory to process recursively\n"; #Argument directory is read into variable $directory
if(! -d $directory)
{
die "Directory $directory doesn't exist\n";
}
# the directory exists, now we are reading its contents and do our job.
#### Functions ####
###############################################################################
#
# processDirectory
#
# To process a directory recursively. It calls itself with new arguments
# (directories) when it finds one.
#
# input parameters: 1: a directory to process.
# output: none
#
###############################################################################
sub processDirectory
{
my $dirToProcess=shift;
opendir DH,"$dirToProcess";
my @files=readdir DH; # Read directory contents into array
closedir DH;
foreach my $item (@files) # Loop through array with files
{
next if $item =~ /^\.\.?$/; # Skip directories '.' ond '..' for obvious reasons
if(-d "$dirToProcess/$item") # Is this item a directory?
{
processDirectory("$dirToProcess/$item");
next;
}
if(-f "$dirToProcess/$item" && $item =~ /\.(mp3|MP3)$/) # Is this item a File AND does it end on mp3 or MP3 ?
{
rewriteFile("$dirToProcess/$item");
next;
}
# This is obviously no mp3 file or directory
warn "Skipped: $dirToProcess/$item: no mp3 file\n";
}
}
###############################################################################
#
# rewriteFile
#
# To do the actual rewriting (this was the original script in fact.
# I do not have these libraries, so I couldn't test the error handling
#
# input parameters: 1: a file (mp3) to rewrite the tags of
# output: none
#
###############################################################################
sub rewriteFile
{
my $fileToRewrite=shift;
my $mp3 = MP3::Mplib->new($fileToRewrite);
my $v2tag = $mp3->get_v2tag;
$mp3->set_v2tag($v2tag,&UTF8) or warn("Error writing to file $fileToRewrite: $!\n");
print "Processed: $fileToRewrite\n";
}
#### Main program (very small :) ) ####
processDirectory($directory);
wow... thanks a lot rhoekstra. From what I understand
the script will be applied to all files and files within subfolders right?
ok I am going to try now and let you know...
Thanks a lot for that much help!!
A.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.