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 "coverfinder.h"
27 #include <mpeg/id3v2/frames/attachedpictureframe.h>
29 CoverFinder::CoverFinder(QObject *parent) :
32 _defaultCover = QImage(":/images/defaultcover.png");
33 SUFFIXES << "png" << "jpg" << "jpeg" << "bmp" << "gif";
34 NAMES << "cover" << "folder" << "album";
35 DIRS << "cover" << "folder" << ".cover" << ".folder";
38 bool CoverFinder::find(QString path) {
40 QFileInfoList items = dir.entryInfoList(QDir::Files);
41 QFileInfoList dirs = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Hidden);
43 foreach (QFileInfo item, items) {
44 if (SUFFIXES.contains(item.suffix().toLower())) {
46 if (NAMES.contains(item.baseName().toLower())) {
47 emit found(QImage(item.absoluteFilePath()));
52 foreach (QFileInfo item, pics) {
53 QImage i(item.absoluteFilePath());
54 if (0.8 <= (i.width()*1.0/(i.height()+1.0)) <= 1.2) {
59 foreach(QFileInfo item, dirs) {
60 if (DIRS.contains(item.fileName().toLower())) {
61 if (find(item.absoluteFilePath())) {
66 emit found(_defaultCover);
70 QImage &CoverFinder::defaultCover() {
74 bool CoverFinder::extract(QString file) {
76 QString suffix = info.suffix().toLower();
77 TagLib::ID3v2::Tag *tag = NULL;
78 if (suffix == "mp3") {
79 TagLib::MPEG::File f(QFile::encodeName(file).data());
81 if (f.isValid() && tag != NULL) {
82 TagLib::ID3v2::FrameList l = tag->frameList("APIC");
85 TagLib::ID3v2::AttachedPictureFrame *pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(l.front());
87 img.loadFromData((const uchar *) pic->picture().data(), pic->picture().size());