Skip to content
Browse files

Store music filesize and expose to the UI.

  • Loading branch information...
1 parent 81cc283 commit f668f405ed08ed16eef664235604b817ac7f2d09 @stuartm stuartm committed Jul 4, 2012
View
1 mythplugins/mythmusic/mythmusic/cdrip.cpp
@@ -358,6 +358,7 @@ void CDRipperThread::run(void)
if (m_tracks->at(trackno)->active)
{
titleTrack->setFilename(outfile);
+ titleTrack->setFileSize((quint64)QFileInfo(outfile).size());
titleTrack->dumpToDatabase();
}
}
View
15 mythplugins/mythmusic/mythmusic/filescanner.cpp
@@ -266,6 +266,7 @@ void FileScanner::AddFileToDB(const QString &filename)
LOG(VB_FILE, LOG_INFO,
QString("Reading metadata from %1").arg(filename));
Metadata *data = decoder->readMetadata();
+ data->setFileSize((quint64)QFileInfo(filename).size());
if (data)
{
QString album_cache_string;
@@ -491,8 +492,20 @@ void FileScanner::UpdateFileInDB(const QString &filename)
if (db_meta && disk_meta)
{
+ if (db_meta->ID() <= 0)
+ {
+ LOG(VB_GENERAL, LOG_ERR, QString("Asked to update track with "
+ "invalid ID - %1")
+ .arg(db_meta->ID()));
+ delete disk_meta;
+ delete db_meta;
+ return;
+ }
+
disk_meta->setID(db_meta->ID());
disk_meta->setRating(db_meta->Rating());
+ if (db_meta->PlayCount() > disk_meta->PlayCount())
+ disk_meta->setPlaycount(db_meta->Playcount());
QString album_cache_string;
@@ -518,6 +531,8 @@ void FileScanner::UpdateFileInDB(const QString &filename)
if (gid > 0)
disk_meta->setGenreId(gid);
+ disk_meta->setFileSize((quint64)QFileInfo(filename).size());
+
// Commit track info to database
disk_meta->dumpToDatabase();
View
2 mythplugins/mythmusic/mythmusic/importmusic.cpp
@@ -431,6 +431,8 @@ void ImportMusicDialog::addPressed()
}
}
+ meta->setFileSize((quint64)QFileInfo(saveFilename).size());
+
// update the database
meta->dumpToDatabase();
View
30 mythplugins/mythmusic/mythmusic/metadata.cpp
@@ -89,6 +89,7 @@ Metadata& Metadata::operator=(const Metadata &rhs)
m_albumArt = NULL;
m_format = rhs.m_format;
m_changed = rhs.m_changed;
+ m_fileSize = rhs.m_fileSize;
return *this;
}
@@ -181,7 +182,7 @@ bool Metadata::isInDatabase()
"music_songs.year, music_songs.track, music_songs.length, "
"music_songs.song_id, music_songs.rating, music_songs.numplays, "
"music_songs.lastplay, music_albums.compilation, music_songs.format, "
- "music_songs.track_count "
+ "music_songs.track_count, music_songs.size "
"FROM music_songs "
"LEFT JOIN music_directories "
"ON music_songs.directory_id=music_directories.directory_id "
@@ -213,6 +214,7 @@ bool Metadata::isInDatabase()
m_compilation = (query.value(12).toInt() > 0);
m_format = query.value(13).toString();
m_trackCount = query.value(14).toInt();
+ m_fileSize = (quint64)query.value(15).toULongLong();
retval = true;
}
@@ -394,16 +396,16 @@ void Metadata::dumpToDatabase()
if (m_id < 1)
{
strQuery = "INSERT INTO music_songs ( directory_id,"
- " artist_id, album_id, name, genre_id,"
- " year, track, length, filename,"
- " rating, format, date_entered, date_modified,"
- " numplays, track_count) "
+ " artist_id, album_id, name, genre_id,"
+ " year, track, length, filename,"
+ " rating, format, date_entered, date_modified,"
+ " numplays, track_count, size) "
"VALUES ( "
" :DIRECTORY, "
- " :ARTIST, :ALBUM, :TITLE, :GENRE,"
- " :YEAR, :TRACKNUM, :LENGTH, :FILENAME,"
- " :RATING, :FORMAT, :DATE_ADD, :DATE_MOD,"
- " :PLAYCOUNT,:TRACKCOUNT );";
+ " :ARTIST, :ALBUM, :TITLE, :GENRE,"
+ " :YEAR, :TRACKNUM, :LENGTH, :FILENAME,"
+ " :RATING, :FORMAT, :DATE_ADD, :DATE_MOD,"
+ " :PLAYCOUNT,:TRACKCOUNT, :SIZE );";
}
else
{
@@ -422,6 +424,7 @@ void Metadata::dumpToDatabase()
", date_modified = :DATE_MOD "
", numplays = :PLAYCOUNT "
", track_count = :TRACKCOUNT "
+ ", size = :SIZE "
"WHERE song_id= :ID ;";
}
@@ -447,6 +450,7 @@ void Metadata::dumpToDatabase()
query.bindValue(":ID", m_id);
query.bindValue(":TRACKCOUNT", m_trackCount);
+ query.bindValue(":SIZE", (quint64)m_fileSize);
if (!query.exec())
MythDB::DBError("Metadata::dumpToDatabase - updating music_songs",
@@ -729,6 +733,10 @@ void Metadata::toMap(MetadataMap &metadataMap, const QString &prefix)
metadataMap[prefix + "playcount"] = QString::number(m_playcount);
// FIXME we should use Filename() here but that will slow things down because of the hunt for the file
metadataMap[prefix + "filename"] = gMusicData->musicDir + m_filename;
+ QLocale locale = gCoreContext->GetQLocale();
+ QString tmpSize = locale.toString(m_fileSize *
+ (1.0 / (1024.0 * 1024.0)), 'f', 2);
+ metadataMap[prefix + "filesize"] = tmpSize;
}
void Metadata::decRating()
@@ -1058,7 +1066,8 @@ void AllMusic::resync()
"music_songs.track, music_songs.length, music_songs.directory_id, "
"CONCAT_WS('/', music_directories.path, music_songs.filename) AS filename, "
"music_songs.rating, music_songs.numplays, music_songs.lastplay, music_songs.date_entered, "
- "music_albums.compilation, music_songs.format, music_songs.track_count "
+ "music_albums.compilation, music_songs.format, music_songs.track_count, "
+ "music_songs.size "
"FROM music_songs "
"LEFT JOIN music_directories ON music_songs.directory_id=music_directories.directory_id "
"LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
@@ -1108,6 +1117,7 @@ void AllMusic::resync()
mdata->setArtistId(query.value(1).toInt());
mdata->setAlbumId(query.value(4).toInt());
mdata->setTrackCount(query.value(19).toInt());
+ mdata->setFileSize((quint64)query.value(20).toULongLong());
// Don't delete mdata, as PtrList now owns it
m_all_music.append(mdata);
View
5 mythplugins/mythmusic/mythmusic/metadata.h
@@ -112,6 +112,7 @@ class Metadata
m_albumArt(NULL),
m_id(lid),
m_filename(lfilename),
+ m_fileSize(0),
m_changed(false)
{
checkEmptyFields();
@@ -191,6 +192,9 @@ class Metadata
QString Filename(bool find = true) const;
void setFilename(const QString &lfilename) { m_filename = lfilename; }
+ uint64_t FileSize() const;
+ void setFileSize(uint64_t lfilesize) { m_fileSize = lfilesize; }
+
QString Format() const { return m_format; }
void setFormat(const QString &lformat) { m_format = lformat; }
@@ -276,6 +280,7 @@ class Metadata
IdType m_id;
QString m_filename;
+ uint64_t m_fileSize;
bool m_changed;
// Various formatting strings

0 comments on commit f668f40

Please sign in to comment.
Something went wrong with that request. Please try again.