2 * SomePlayer - An alternate music player for Maemo 5
3 * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "tagresolver.h"
27 using namespace SomePlayer::DataObjects;
29 TagResolver::TagResolver(QObject *parent) :
34 void TagResolver::decode(QStringList files) {
36 foreach (QString filename, files) {
37 TagLib::FileRef file_ref(QFile::encodeName(filename).data());
38 if (!file_ref.isNull()) {
39 TagLib::Tag *tag = file_ref.tag();
41 TagLib::AudioProperties *properties = file_ref.audioProperties();
42 if (NULL != properties) {
43 TrackMetadata meta(QString::fromStdWString(tag->title().toWString()),
44 QString::fromStdWString(tag->artist().toWString()),
45 QString::fromStdWString(tag->album().toWString()),
46 properties->length());
47 meta.setYear(tag->year());
48 Track track(meta, filename);
52 } else { // workaround
55 QFileInfo fi(filename);
56 meta.setArtist(fi.suffix().toUpper());
57 meta.setTitle(fi.baseName());
58 Track track(meta, filename);
65 void TagResolver::updateTags(Track track) {
66 TagLib::FileRef file_ref(QFile::encodeName(track.source()).data());
67 if (!file_ref.isNull()) {
68 TagLib::Tag *tag = file_ref.tag();
70 tag->setArtist(TagLib::String(track.metadata().artist().toStdWString()));
71 tag->setAlbum(TagLib::String(track.metadata().album().toStdWString()));
72 tag->setTitle(TagLib::String(track.metadata().title().toStdWString()));