taginfo.cpp 3.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
   Babe - tiny music player
   Copyright (C) 2017  Camilo Higuita
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

   */

#include "taginfo.h"
#include "../../utils/bae.h"

using namespace BAE;

23 24 25
TagInfo::TagInfo(QObject *parent) : QObject(parent)
{}

26
TagInfo::~TagInfo()
27
{}
28

29
bool TagInfo::feed(const QString &url)
30 31
{
    this->path = url;
32 33
    this->file = TagLib::FileRef(path.toUtf8());
    return !file.isNull();
34 35 36 37
}

QString TagInfo::getAlbum() const
{
38 39
    return !QString::fromStdWString(file.tag()->album().toWString()).isEmpty()
            ? QString::fromStdWString(file.tag()->album().toWString())
40 41 42 43 44
            : SLANG[W::UNKNOWN];
}

QString TagInfo::getTitle() const
{
45 46
    return !QString::fromStdWString(file.tag()->title().toWString()).isEmpty()
            ? QString::fromStdWString(file.tag()->title().toWString())
47 48 49 50 51
            : fileName();
}

QString TagInfo::getArtist() const
{
52 53
    return QString::fromStdWString(file.tag()->artist().toWString()).size() > 0
            ? QString::fromStdWString(file.tag()->artist().toWString())
54 55 56
            : SLANG[W::UNKNOWN];
}

57
int TagInfo::getTrack() const { return static_cast<signed int>(file.tag()->track()); }
58 59 60

QString TagInfo::getGenre() const
{
61 62
    return QString::fromStdWString(file.tag()->genre().toWString()).size() > 0
            ? QString::fromStdWString(file.tag()->genre().toWString())
63 64 65 66 67 68 69 70 71 72 73
            : SLANG[W::UNKNOWN];
}

QString TagInfo::fileName() const
{
    return BAE::getNameFromLocation(path);
}

uint TagInfo::getYear() const
{
    //return BAE::getNameFromLocation(path);
74
    return file.tag()->year();
75 76 77 78 79
}


int TagInfo::getDuration() const
{
80

81
    return file.audioProperties()->length();
82 83 84 85
}

QString TagInfo::getComment() const
{
86 87
    return QString::fromStdWString(file.tag()->comment().toWString()).size() > 0
            ? QString::fromStdWString(file.tag()->genre().toWString())
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
            : SLANG[W::UNKNOWN];
}

QByteArray TagInfo::getCover() const
{
    QByteArray array;
    return array;
}

void TagInfo::setCover(const QByteArray &array)
{
    Q_UNUSED(array);

}

void TagInfo::setComment(const QString &comment)
{

106 107
    this->file.tag()->setComment(comment.toStdString());
    this->file.save();
108 109 110 111 112

}

void TagInfo::setAlbum(const QString &album)
{
113 114
    this->file.tag()->setAlbum(album.toStdString());
    this->file.save();
115 116 117 118 119

}

void TagInfo::setTitle(const QString &title)
{
120 121
    this->file.tag()->setTitle(title.toStdString());
    this->file.save();
122 123 124 125
}

void TagInfo::setTrack(const int &track)
{
126 127
    this->file.tag()->setTrack(static_cast<unsigned int>(track));
    this->file.save();
128 129 130 131
}

void TagInfo::setArtist(const QString &artist)
{
132 133
    this->file.tag()->setArtist(artist.toStdString());
    this->file.save();
134 135 136 137
}

void TagInfo::setGenre(const QString &genre)
{
138 139
    this->file.tag()->setGenre(genre.toStdString());
    this->file.save();
140
}