File indexing completed on 2025-01-19 04:23:50
0001 /* 0002 Babe - tiny music player 0003 Copyright (C) 2017 Camilo Higuita 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 3 of the License, or 0007 (at your option) any later version. 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0011 GNU General Public License for more details. 0012 You should have received a copy of the GNU General Public License 0013 along with this program; if not, write to the Free Software Foundation, 0014 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0015 0016 */ 0017 0018 #include "taginfo.h" 0019 #include "../../utils/bae.h" 0020 0021 using namespace BAE; 0022 0023 TagInfo::TagInfo(const QString &url, QObject *parent) 0024 : QObject(parent) 0025 { 0026 this->setFile(url); 0027 } 0028 0029 TagInfo::TagInfo(QObject *parent) 0030 : QObject(parent) 0031 {} 0032 0033 TagInfo::~TagInfo() 0034 { 0035 delete this->file; 0036 } 0037 0038 bool TagInfo::isNull() 0039 { 0040 return this->file->isNull(); 0041 } 0042 0043 QString TagInfo::getAlbum() const 0044 { 0045 const auto value = QString::fromStdWString(file->tag()->album().toWString()); 0046 return !value.isEmpty() ? value : SLANG[W::UNKNOWN]; 0047 } 0048 0049 QString TagInfo::getTitle() const 0050 { 0051 const auto value = QString::fromStdWString(file->tag()->title().toWString()); 0052 return !value.isEmpty() ? value : fileName(); 0053 } 0054 0055 QString TagInfo::getArtist() const 0056 { 0057 const auto value = QString::fromStdWString(file->tag()->artist().toWString()); 0058 return !value.isEmpty() ? value : SLANG[W::UNKNOWN]; 0059 } 0060 0061 int TagInfo::getTrack() const 0062 { 0063 return static_cast<signed int>(file->tag()->track()); 0064 } 0065 0066 QString TagInfo::getGenre() const 0067 { 0068 const auto value = QString::fromStdWString(file->tag()->genre().toWString()); 0069 return !value.isEmpty() ? value : SLANG[W::UNKNOWN]; 0070 } 0071 0072 QString TagInfo::fileName() const 0073 { 0074 return QFileInfo(path).fileName(); 0075 } 0076 0077 uint TagInfo::getYear() const 0078 { 0079 return file->tag()->year(); 0080 } 0081 0082 void TagInfo::setFile(const QString &url) 0083 { 0084 this->path = url; 0085 QFileInfo _file(this->path); 0086 0087 if (_file.isReadable() && _file.exists()) { 0088 this->file = new TagLib::FileRef(TagLib::FileName(path.toUtf8())); 0089 } else 0090 this->file = new TagLib::FileRef(); 0091 } 0092 0093 int TagInfo::getDuration() const 0094 { 0095 return file->audioProperties()->length(); 0096 } 0097 0098 QString TagInfo::getComment() const 0099 { 0100 const auto value = QString::fromStdWString(file->tag()->comment().toWString()); 0101 return !value.isEmpty() ? value : SLANG[W::UNKNOWN]; 0102 } 0103 0104 QByteArray TagInfo::getCover() const 0105 { 0106 QByteArray array; 0107 return array; 0108 } 0109 0110 void TagInfo::setCover(const QByteArray &array) 0111 { 0112 Q_UNUSED(array); 0113 } 0114 0115 void TagInfo::setComment(const QString &comment) 0116 { 0117 this->file->tag()->setComment(comment.toStdString()); 0118 this->file->save(); 0119 } 0120 0121 void TagInfo::setAlbum(const QString &album) 0122 { 0123 this->file->tag()->setAlbum(album.toStdString()); 0124 this->file->save(); 0125 } 0126 0127 void TagInfo::setTitle(const QString &title) 0128 { 0129 this->file->tag()->setTitle(title.toStdString()); 0130 this->file->save(); 0131 } 0132 0133 void TagInfo::setTrack(const int &track) 0134 { 0135 this->file->tag()->setTrack(static_cast<unsigned int>(track)); 0136 this->file->save(); 0137 } 0138 0139 void TagInfo::setYear(const int &year) 0140 { 0141 this->file->tag()->setYear(static_cast<unsigned int>(year)); 0142 this->file->save(); 0143 } 0144 0145 void TagInfo::setArtist(const QString &artist) 0146 { 0147 this->file->tag()->setArtist(artist.toStdString()); 0148 this->file->save(); 0149 } 0150 0151 void TagInfo::setGenre(const QString &genre) 0152 { 0153 this->file->tag()->setGenre(genre.toStdString()); 0154 this->file->save(); 0155 }