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.
21 #include "tagresolver.h"
23 #include <QCryptographicHash>
26 using namespace SomePlayer::DataObjects;
28 Track::Track() : QObject() {
31 Track::Track(TrackMetadata metadata, QString source) : QObject() {
33 if (_metadata.title() == _UNKNOWN_TRACK_) {
34 QFileInfo info(source);
35 _metadata.setTitle(info.baseName());
41 Track::Track(const Track &track) : QObject() {
42 this->_metadata = track.metadata();
43 this->_source = track.source();
44 this->_count = track._count;
48 Track::Track(QString source) :QObject() {
49 _resolver = new TagResolver(this);
50 connect(_resolver, SIGNAL(decoded(Track)), this, SLOT(decoded(Track)));
53 _resolver->decode(foo);
57 TrackMetadata Track::metadata() const {
61 void Track::setMetadata(TrackMetadata meta) {
65 QString Track::source() const {
69 void Track::setSource(QString source) {
73 int Track::count() const{
77 void Track::setCount(int count) {
81 void Track::decoded(Track track) {
82 _source = track.source();
83 _metadata = track.metadata();
87 Track &Track::operator =(const Track &track) {
88 _source = track.source();
89 _metadata = track.metadata();
90 _count = track._count;
96 bool Track::operator ==(const Track &track) const {
97 return _source == track._source;
100 bool Track::operator >= (const Track &track) const {
101 return (metadata().title().compare(track.metadata().title()) >= 0);
104 bool Track::operator < (const Track &track) const {
105 return (metadata().title().compare(track.metadata().title()) < 0);
108 QString Track::mediaArtLocal() {
109 QString album = _metadata.album();
110 if (album == _UNKNOWN_ALBUM_) {
111 return QString("no_mediaartlocal");
113 QRegExp rsb("\\[.*\\]");
115 QRegExp rrb("\\(.*\\)");
116 QRegExp stripB("^[()_{}[]!@#$^&*+=|\\\\/\"'?<>~`\\s\\t]*");
117 QRegExp stripE("[()_{}[]!@#$^&*+=|\\\\/\"'?<>~`\\s\\t]*$");
118 album = album.replace(rsb, "");
119 album = album.replace(rfb, "");
120 album = album.replace(rrb, "");
121 album = album.replace(stripB, "");
122 album = album.replace(stripE, "");
123 album = album.replace(" ", " ");
124 album = album.replace("\t", " ");
125 album = album.toLower();
126 QByteArray first_hash = QCryptographicHash::hash(QString(" ").toUtf8(), QCryptographicHash::Md5).toHex();
127 QByteArray second_hash = QCryptographicHash::hash(QString(album).toUtf8(), QCryptographicHash::Md5).toHex();
128 return QString("album-%1-%2.jpeg").arg(first_hash.constData()).arg(second_hash.constData());