1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2008 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # libtagupdate.py -- tag updating/writing library
23 # thomas perl <thp@perli.net> 20070315
28 # for ogg/vorbis (vorbiscomment utility)
32 from liblogger
import log
39 log('(tagupdate) eyed3 not found -- tag update disabled')
42 # do we provide tagging functions to the user?
43 def tagging_supported():
48 tag_update_methods
= {}
50 def update_metadata_on_file( filename
, **metadata
):
51 global tag_update_methods
54 if ext
in tag_update_methods
:
55 log('Updating tag for %s', filename
)
56 return tag_update_methods
[ext
]( filename
, **metadata
)
58 log('Do not know how to update file extension %s :/', ext
)
62 def update_tag_ogg( filename
, **metadata
):
63 data
= '\n'.join( [ '%s=%s' % ( i
.upper(), metadata
[i
] ) for i
in metadata
] + [''])
65 p
= popen2
.Popen3('vorbiscomment -w "%s"' % filename
)
71 result
= p
.wait() == 0
74 log('Error while running vorbiscomment. Is it installed?! (vorbis-tools)')
78 tag_update_methods
['ogg'] = update_tag_ogg
81 def update_tag_mp3( filename
, **metadata
):
83 log('eyeD3 not found -> please install. no tags have been updated.')
86 tag
= eyeD3
.tag
.Tag( fileName
= filename
)
87 tag
.remove( eyeD3
.tag
.ID3_ANY_VERSION
)
88 tag
.setVersion( eyeD3
.tag
.ID3_ANY_VERSION
)
91 if key
.lower() == 'artist':
92 tag
.setArtist( metadata
[key
])
93 elif key
.lower() == 'title':
94 tag
.setTitle( metadata
[key
])
95 elif key
.lower() == 'album':
96 tag
.setAlbum( metadata
[key
])
97 elif key
.lower() == 'genre':
98 tag
.setGenre(metadata
[key
])
100 return tag
.update( eyeD3
.tag
.ID3_V2
) == 1 and tag
.update( eyeD3
.tag
.ID3_V1
) == 1
102 tag_update_methods
['mp3'] = update_tag_mp3