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"
26 using namespace SomePlayer::DataObjects;
28 TagResolver::TagResolver(QObject *parent) :
33 void TagResolver::decode(QStringList files) {
34 foreach (QString filename, files) {
35 TagLib::FileRef file_ref(QFile::encodeName(filename).data());
36 if (!file_ref.isNull()) {
37 TagLib::Tag *tag = file_ref.tag();
39 TagLib::AudioProperties *properties = file_ref.audioProperties();
40 if (NULL != properties) {
41 TrackMetadata meta(QString::fromStdWString(tag->title().toWString()),
42 QString::fromStdWString(tag->artist().toWString()),
43 QString::fromStdWString(tag->album().toWString()),
44 properties->length());
45 Track track(0, meta, filename);
49 } else { // workaround
52 QFileInfo fi(filename);
53 meta.setArtist(fi.suffix().toUpper());
54 meta.setTitle(fi.baseName());
55 Track track(0, meta, filename);
62 void TagResolver::updateTags(Track track) {
63 TagLib::FileRef file_ref(QFile::encodeName(track.source()).data());
64 if (!file_ref.isNull()) {
65 TagLib::Tag *tag = file_ref.tag();
67 tag->setArtist(TagLib::String(track.metadata().artist().toStdWString()));
68 tag->setAlbum(TagLib::String(track.metadata().album().toStdWString()));
69 tag->setTitle(TagLib::String(track.metadata().title().toStdWString()));