LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 12-28-2009, 07:10 AM   #1
RAFAL
Member
 
Registered: Feb 2006
Location: Warsaw, Poland
Distribution: openSUSE 11.4, openSUSE 12.3, SLES 11, Archlinux
Posts: 129

Rep: Reputation: 16
LAME - copy id3 tags


Hi
does anybody know option for LAME which will allow me to copy id3 tags (including picture) ?

I have written small bash script to lower bitrate of all mp3 files in the folder. When I copy my songs to mp3 player like iPod I don't need songs with 320kbps. Therefore I use lame in command line to change from 320kbps to 128kbps. This works fine. The problem is that new mp3 files lost all id3 tags but id3 tags are very useful with iPod.

I am looking for option when I execute LAME to copy all id3 tags. I found only options to set ID3 info, but maybe there is only one option I have to use with LAME.

regards
Rafal
 
Old 12-29-2009, 01:21 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
You could use the id3v2 program to set many id3v2 tags, however it seems to just display data on APIC tags.

To be able to script extracting the picture from the original, and insert it into your new file, I think you would need to use id3lib to do it. Either directly (C++ programming) or via a scripting language with a id3lib library module.

Have a look at id3lib-ruby. http://id3lib-ruby.rubyforge.org/
This page has an example adding an attached picture frame.
 
Old 12-29-2009, 03:02 PM   #3
RAFAL
Member
 
Registered: Feb 2006
Location: Warsaw, Poland
Distribution: openSUSE 11.4, openSUSE 12.3, SLES 11, Archlinux
Posts: 129

Original Poster
Rep: Reputation: 16
solved

Quote:
Originally Posted by jschiwal View Post
You could use the id3v2 program to set many id3v2 tags, however it seems to just display data on APIC tags.

To be able to script extracting the picture from the original, and insert it into your new file, I think you would need to use id3lib to do it. Either directly (C++ programming) or via a scripting language with a id3lib library module.

Have a look at id3lib-ruby. http://id3lib-ruby.rubyforge.org/
This page has an example adding an attached picture frame.
Hi

In the meantime I have solved the problem as follows:
I have created small python script using mutagen.
Everything works perfectly.My script uses LAME to change bit rate and copies all tags I need (including picture). I have small problem with ZENITY (folder selection) but its another topic.
Apparently LAME does not support ID3 tags which is visible if I use it in terminal:
ID3v2 found. Be aware that the ID3 tag is currently lost when transcoding.


regards
Rafal
 
Old 12-30-2009, 01:21 PM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Thanks for posting that link. I may incorporate it in my ogg2mp3 script. It used ogginfo to get the tags and then added the ones available in lame. Sounds like mutagen would work much better for this, if I'm not to lazy to edit it.
 
Old 05-15-2011, 11:31 PM   #5
FutureNerd
LQ Newbie
 
Registered: May 2011
Posts: 2

Rep: Reputation: 0
Code to copy tags using mutagen

I had the same issue as Rafal and followed his advice to use mutagen. I hit a couple wrinkles so I thought I would paste my code here in case someone else googles to here looking for the same functionality. The slightly goofy arrangement lets this act like both a script (with -h or --help):

Code:
$ copy_id3.py --help
usage: copy_id3.py [-h] [-v] source_file destination_file

Copy ID3 tags from one mp3 file to another.

positional arguments:
  source_file       name of mp3 file to get tags from
  destination_file  name of mp3 file to copy tags into

optional arguments:
  -h, --help        show this help message and exit
  -v, --verbose     Display the resulting set of tags when done.
$
...and as a module (with help()):

Code:
>>> import copy_id3
>>> help(copy_id3)
Help on module copy_id3:

NAME
    copy_id3 - Copy ID3 tags from one mp3 file to another.

FILE
    /fs/bin/copy_id3.py

FUNCTIONS
    copy_id3(srcname, destname, verbose=False)
        Copy ID3 tags from srcname to destname.
argparse is available for older Pythons but was only added to the standard library in 2.7. Of course you can strip out the niceties. The core of this thing is only about six lines including the import. Have fun.

--Steve


Code:
#!/usr/bin/env python
""" Copy ID3 tags from one mp3 file to another. """

import mutagen
import argparse


def _main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        'srcname', metavar='source_file', type=str,
        help='name of mp3 file to get tags from')
    parser.add_argument(
        'destname', metavar='destination_file', type=str,
        help='name of mp3 file to copy tags into')
    parser.add_argument(
        '-v', '--verbose', action="store_true",
        help='Display the resulting set of tags when done.')
    args = parser.parse_args()
    copy_id3(args.srcname, args.destname, args.verbose)


def copy_id3(srcname, destname, verbose=False):
    """ Copy ID3 tags from srcname to destname. """
    src = mutagen.File(srcname, easy=True)
    dest = mutagen.File(destname, easy=True)
    for k in src:
        dest[k] = src[k]
    dest.save()
    if verbose:
        print "Copied ID3 tags from %(srcname)r to %(destname)r--result:" % locals()
        print dest.pprint()


if __name__ == "__main__":
    _main()
 
Old 09-13-2011, 05:23 PM   #6
JurgyMan
Member
 
Registered: Jan 2004
Location: USA
Distribution: Gentoo
Posts: 59

Rep: Reputation: 15
FutureNerd, I'd like to employ your script... but get below python error
I've no exposure to python; any ideas?

python copyid3.py
File "copyid3.py", line 31
print "Copied ID3 tags from %(srcname)r to %(destname)r--result:" % locals()
^
SyntaxError: invalid syntax
 
Old 09-16-2011, 09:44 PM   #7
FutureNerd
LQ Newbie
 
Registered: May 2011
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by JurgyMan View Post
FutureNerd, I'd like to employ your script... but get below python error
I've no exposure to python; any ideas?

python copyid3.py
File "copyid3.py", line 31
print "Copied ID3 tags from %(srcname)r to %(destname)r--result:" % locals()
^
SyntaxError: invalid syntax
JurgyMan: I guess something happened when you cut & pasted the text in-- check the indent of that line compared to on this page. Or it could be the previous line. Anyway, once you get that fixed you'll just get another error because you need to install mutagen, and maybe argparse, and you need to type in the from and to filenames.

Go to meetup.com and search for Python! Find someone there to help you getting started! Consume Python. Enjoy Python. Socialize only with those who do Python. Produce more Python.

--Steve
 
  


Reply

Tags
conversion, id3, lame, mp3


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Truncated ID3 Tags Napalm Llama Linux - Software 9 03-17-2006 02:48 AM
Converting ID3 tags from v2.3 to v2.4 dotancohen Linux - Software 2 02-17-2006 03:41 PM
id3 tags don't seem to appear Valhalla Linux - Software 1 12-13-2005 12:17 PM
Reading Id3 tags jpc82 Programming 7 10-10-2005 09:50 AM
Accessing ID3 Tags oulevon Programming 2 11-15-2002 04:13 AM


All times are GMT -5. The time now is 08:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration