id3 tagger.py :  » Media-Sound-Audio » ID3.py » id3-py-1.2 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Media Sound Audio » ID3.py 
ID3.py » id3 py 1.2 » id3-tagger.py
#!/usr/bin/env python

# ID3 module example program
# $Id: id3-tagger.py,v 1.5 2002/04/05 02:33:39 che_fox Exp $
       
# version 1.2
# written 2 May 1999 by Ben Gertzfield <che@debian.org>

# This program is released under the GNU GPL, version 2 or later.

import getopt, string, re, sys
from ID3 import *

version = 1.2
name = 'id3-tagger.py'

def usage():
    sys.stderr.write(
"This is %s version %0.1f, a tool for setting ID3 tags in MP3 files.\n\n\
Usage: %s [-t title] [-a artist] [-A album] [-y year] [-c comment] \n\
       %s [-g genre] [-T tracknum] [-d] [-h] [-v] file1 [file2 ...]\n\n\
-d: Delete the ID3 tag from specified file(s) completely\n\
-h: Display this text\n\
-v: Display the version of this program\n\n\
With no arguments, display the ID3 tag of the given file(s).\n" % 
       (name, version, name, ' ' * len(name)))

def main():
    options = {}

    try:
  opts, args = getopt.getopt(sys.argv[1:], 't:a:A:y:c:g:T:dhvl')
    except getopt.error, msg:
  print msg
  usage()
  sys.exit(2)

    for opt, arg in opts:
  if opt == '-v':
      sys.stderr.write("This is %s version %0.1f.\n" % (name, version))
      sys.exit(0)
  if opt == '-h':
      usage()
      sys.exit(0)
  if opt == '-t':
      options['TITLE'] = arg
  if opt == '-a':
      options['ARTIST'] = arg
  if opt == '-A':
      options['ALBUM'] = arg
  if opt == '-y':
      options['YEAR'] = arg
  if opt == '-c':
      options['COMMENT'] = arg
  if opt == '-g':
      options['GENRE'] = arg
        if opt == '-T':
            options['TRACKNUMBER'] = arg
  if opt == '-d':
      options['delete'] = 1

    if len(args) == 0:
  usage()
  sys.exit(2)

    for file in args:
  try:
      id3info = ID3(file)

            needs_write = 0

            if len(options.keys()) > 0:
                needs_write = 1

            for k, v in options.items():
                if k == 'GENRE' and re.match("\d+$", v):
                    id3info[k] = string.atoi(v)
                else:
                    id3info[k] = v

      if options.has_key('delete'):
    id3info.delete()

      print id3info

            if needs_write:
                id3info.write()

  except InvalidTagError, msg:
      print "Invalid ID3 tag:", msg
      continue

main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.