Media.cpp 17.1 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
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.
 *****************************************************************************/

23
#include <algorithm>
24
#include <cassert>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
25 26
#include <cstdlib>
#include <cstring>
27
#include <ctime>
28

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
29
#include "Album.h"
30
#include "AlbumTrack.h"
31
#include "Artist.h"
32
#include "AudioTrack.h"
33
#include "Media.h"
34
#include "File.h"
35
#include "Folder.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
36
#include "Label.h"
37
#include "logging/Logger.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
38
#include "Movie.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
39
#include "ShowEpisode.h"
40
#include "database/SqliteTools.h"
41
#include "VideoTrack.h"
42
#include "filesystem/IFile.h"
43 44
#include "filesystem/IDirectory.h"
#include "filesystem/IDevice.h"
45
#include "utils/Filename.h"
46

47 48 49
namespace medialibrary
{

50
const std::string policy::MediaTable::Name = "Media";
51
const std::string policy::MediaTable::PrimaryKeyColumn = "id_media";
52
int64_t Media::* const policy::MediaTable::PrimaryKey = &Media::m_id;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
53

54 55
Media::Media( MediaLibraryPtr ml, sqlite::Row& row )
    : m_ml( ml )
56
    , m_changed( false )
57
{
58 59
    row >> m_id
        >> m_type
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
60
        >> m_subType
61 62
        >> m_duration
        >> m_playCount
63
        >> m_lastPlayedDate
64 65
        >> m_progress
        >> m_rating
66
        >> m_insertionDate
67
        >> m_releaseDate
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
68
        >> m_thumbnail
69
        >> m_title
70
        >> m_filename
71 72
        >> m_isFavorite
        >> m_isPresent;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
73 74
}

75 76 77
Media::Media( MediaLibraryPtr ml, const std::string& title, Type type )
    : m_ml( ml )
    , m_id( 0 )
78
    , m_type( type )
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
79
    , m_subType( SubType::Unknown )
80
    , m_duration( -1 )
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
81
    , m_playCount( 0 )
82
    , m_lastPlayedDate( 0 )
83 84
    , m_progress( .0f )
    , m_rating( -1 )
85
    , m_insertionDate( time( nullptr ) )
86
    , m_releaseDate( 0 )
87
    , m_title( title )
88 89
    // When creating a Media, meta aren't parsed, and therefor, is the filename
    , m_filename( title )
90
    , m_isFavorite( false )
91
    , m_isPresent( true )
92
    , m_changed( false )
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
93
{
94 95
}

96
std::shared_ptr<Media> Media::create( MediaLibraryPtr ml, Type type, const fs::IFile& file )
97
{
98
    auto self = std::make_shared<Media>( ml, file.name(), type );
99
    static const std::string req = "INSERT INTO " + policy::MediaTable::Name +
100
            "(type, insertion_date, title, filename) VALUES(?, ?, ?, ?)";
101

102
    if ( insert( ml, self, req, type, self->m_insertionDate, self->m_title, self->m_filename ) == false )
103
        return nullptr;
104
    return self;
105 106
}

107
AlbumTrackPtr Media::albumTrack() const
108
{
109 110
    if ( m_subType != SubType::AlbumTrack )
        return nullptr;
111 112
    auto lock = m_albumTrack.lock();

113
    if ( m_albumTrack.isCached() == false )
114
        m_albumTrack = AlbumTrack::fromMedia( m_ml, m_id );
115
    return m_albumTrack.get();
116 117
}

118
void Media::setAlbumTrack( AlbumTrackPtr albumTrack )
119
{
120
    auto lock = m_albumTrack.lock();
121
    m_albumTrack = albumTrack;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
122 123
    m_subType = SubType::AlbumTrack;
    m_changed = true;
124 125
}

126
int64_t Media::duration() const
127 128 129 130
{
    return m_duration;
}

131
void Media::setDuration( int64_t duration )
132
{
133 134
    if ( m_duration == duration )
        return;
135
    m_duration = duration;
136
    m_changed = true;
137 138
}

139
ShowEpisodePtr Media::showEpisode() const
140
{
141 142
    if ( m_subType != SubType::ShowEpisode )
        return nullptr;
143

144 145
    auto lock = m_showEpisode.lock();
    if ( m_showEpisode.isCached() == false )
146
        m_showEpisode = ShowEpisode::fromMedia( m_ml, m_id );
147
    return m_showEpisode.get();
148 149
}

150
void Media::setShowEpisode( ShowEpisodePtr episode )
151
{
152 153
    auto lock = m_showEpisode.lock();
    m_showEpisode = episode;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
154 155
    m_subType = SubType::ShowEpisode;
    m_changed = true;
156 157
}

158
std::vector<LabelPtr> Media::labels()
159
{
160
    static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
161
            "INNER JOIN LabelFileRelation lfr ON lfr.label_id = l.id_label "
162
            "WHERE lfr.media_id = ?";
163
    return Label::fetchAll<ILabel>( m_ml, req, m_id );
164 165
}

166
int Media::playCount() const
167
{
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
168
    return m_playCount;
169 170
}

171
bool Media::increasePlayCount()
172
{
173 174 175 176 177
    static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
            "play_count = ?, last_played_date = ? WHERE id_media = ?";
    auto lastPlayedDate = time( nullptr );
    if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_playCount + 1, lastPlayedDate, m_id ) == false )
        return false;
178
    m_playCount++;
179 180
    m_lastPlayedDate = lastPlayedDate;
    return true;
181 182
}

183 184 185 186 187
float Media::progress() const
{
    return m_progress;
}

188
bool Media::setProgress( float progress )
189
{
190
    static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET progress = ? WHERE id_media = ?";
191
    if ( progress == m_progress || progress < 0 || progress > 1.0 )
192 193 194
        return true;
    if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, progress, m_id ) == false )
        return false;
195
    m_progress = progress;
196
    return true;
197 198 199 200 201 202 203
}

int Media::rating() const
{
    return m_rating;
}

204
bool Media::setRating( int rating )
205
{
206
    static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET rating = ? WHERE id_media = ?";
207
    if ( m_rating == rating )
208 209 210
        return true;
    if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, rating, m_id ) == false )
        return false;
211
    m_rating = rating;
212
    return true;
213 214
}

215 216 217 218 219
bool Media::isFavorite() const
{
    return m_isFavorite;
}

220
bool Media::setFavorite( bool favorite )
221
{
222
    static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET is_favorite = ? WHERE id_media = ?";
223
    if ( m_isFavorite == favorite )
224 225 226
        return true;
    if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, favorite, m_id ) == false )
        return false;
227
    m_isFavorite = favorite;
228
    return true;
229 230
}

231
const std::vector<FilePtr>& Media::files() const
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
232
{
233 234 235 236 237
    auto lock = m_files.lock();
    if ( m_files.isCached() == false )
    {
        static const std::string req = "SELECT * FROM " + policy::FileTable::Name
                + " WHERE media_id = ?";
238
        m_files = File::fetchAll<IFile>( m_ml, req, m_id );
239 240
    }
    return m_files;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
241 242
}

243
MoviePtr Media::movie() const
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
244
{
245 246 247
    if ( m_subType != SubType::Movie )
        return nullptr;

248 249
    auto lock = m_movie.lock();

250
    if ( m_movie.isCached() == false )
251
        m_movie = Movie::fromMedia( m_ml, m_id );
252
    return m_movie.get();
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
253 254
}

255
void Media::setMovie(MoviePtr movie)
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
256
{
257
    auto lock = m_movie.lock();
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
258
    m_movie = movie;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
259 260
    m_subType = SubType::Movie;
    m_changed = true;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
261 262
}

263 264
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps,
                          const std::string& language, const std::string& description )
265
{
266
    return VideoTrack::create( m_ml, codec, width, height, fps, m_id, language, description ) != nullptr;
267 268
}

269
std::vector<VideoTrackPtr> Media::videoTracks()
270
{
271 272
    static const std::string req = "SELECT * FROM " + policy::VideoTrackTable::Name +
            " WHERE media_id = ?";
273
    return VideoTrack::fetchAll<IVideoTrack>( m_ml, req, m_id );
274 275
}

276
bool Media::addAudioTrack( const std::string& codec, unsigned int bitrate,
277 278
                          unsigned int sampleRate, unsigned int nbChannels,
                          const std::string& language, const std::string& desc )
279
{
280
    return AudioTrack::create( m_ml, codec, bitrate, sampleRate, nbChannels, language, desc, m_id ) != nullptr;
281 282
}

283
std::vector<AudioTrackPtr> Media::audioTracks()
284
{
285 286
    static const std::string req = "SELECT * FROM " + policy::AudioTrackTable::Name +
            " WHERE media_id = ?";
287
    return AudioTrack::fetchAll<IAudioTrack>( m_ml, req, m_id );
288 289
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
290
const std::string &Media::thumbnail()
291
{
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
292
    return m_thumbnail;
293 294
}

295 296 297 298 299
unsigned int Media::insertionDate() const
{
    return m_insertionDate;
}

300 301 302 303 304 305 306 307 308 309 310 311 312
unsigned int Media::releaseDate() const
{
    return m_releaseDate;
}

void Media::setReleaseDate( unsigned int date )
{
    if ( m_releaseDate == date )
        return;
    m_releaseDate = date;
    m_changed = true;
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
313
void Media::setThumbnail(const std::string& thumbnail )
314
{
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
315
    if ( m_thumbnail == thumbnail )
316
        return;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
317
    m_thumbnail = thumbnail;
318 319 320 321 322 323
    m_changed = true;
}

bool Media::save()
{
    static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
324
            "type = ?, subtype = ?, duration = ?, progress = ?, release_date = ?,"
325
            "thumbnail = ?, title = ? WHERE id_media = ?";
326 327
    if ( m_changed == false )
        return true;
328
    if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_type, m_subType, m_duration,
329
                                       m_progress, m_releaseDate, m_thumbnail, m_title, m_id ) == false )
330 331 332 333
    {
        return false;
    }
    m_changed = false;
334 335 336
    return true;
}

337
std::shared_ptr<File> Media::addFile( const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs, IFile::Type type )
338
{
339
    auto file = File::create( m_ml, m_id, type, fileFs, parentFolder.id(), parentFolderFs.device()->isRemovable() );
340 341 342 343 344 345
    if ( file == nullptr )
        return nullptr;
    auto lock = m_files.lock();
    if ( m_files.isCached() )
        m_files.get().push_back( file );
    return file;
346 347
}

348
void Media::removeFile( File& file )
349
{
350 351 352
    file.destroy();
    auto lock = m_files.lock();
    if ( m_files.isCached() == false )
353
        return;
354
    m_files.get().erase( std::remove_if( begin( m_files.get() ), end( m_files.get() ), [&file]( const FilePtr& f ) {
355 356
        return f->id() == file.id();
    }));
357 358
}

359
std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, SortingCriteria sort, bool desc )
360
{
361
    std::string req;
362
    if ( sort == SortingCriteria::LastModificationDate )
363 364 365 366 367 368 369 370 371 372 373 374 375
    {
        req = "SELECT m.* FROM " + policy::MediaTable::Name + " m INNER JOIN "
                + policy::FileTable::Name + " f ON m.id_media = f.media_id"
                " WHERE m.type = ?"
                " AND ( f.type = ? OR f.type = ? )"
                " ORDER BY f.last_modification_date";
        if ( desc == true )
            req += " DESC";
        return fetchAll<IMedia>( ml, req, type, File::Type::Entire, File::Type::Main );
    }
    req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? AND is_present = 1 ORDER BY ";
    switch ( sort )
    {
376
    case SortingCriteria::Duration:
377 378
        req += "duration";
        break;
379
    case SortingCriteria::InsertionDate:
380 381
        req += "insertion_date";
        break;
382
    case SortingCriteria::ReleaseDate:
383 384 385
        req += "release_date";
        break;
    default:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
386
        req += "title";
387 388 389 390 391 392
        break;
    }
    if ( desc == true )
        req += " DESC";

    return fetchAll<IMedia>( ml, req, type );
393 394
}

395
int64_t Media::id() const
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
396 397 398 399
{
    return m_id;
}

400
IMedia::Type Media::type()
401 402 403 404
{
    return m_type;
}

405
IMedia::SubType Media::subType() const
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
406 407 408 409
{
    return m_subType;
}

410
void Media::setType( Type type )
411
{
412 413
    if ( m_type != type )
        return;
414
    m_type = type;
415
    m_changed = true;
416 417
}

418
const std::string &Media::title() const
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
419
{
420
    return m_title;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
421 422
}

423
void Media::setTitle( const std::string &title )
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
424
{
425 426
    if ( m_title == title )
        return;
427
    m_title = title;
428
    m_changed = true;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
429 430
}

431
bool Media::createTable( DBConnection connection )
432
{
433 434
    std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MediaTable::Name + "("
            "id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
435
            "type INTEGER,"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
436
            "subtype INTEGER,"
437
            "duration INTEGER DEFAULT -1,"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
438
            "play_count UNSIGNED INTEGER,"
439
            "last_played_date UNSIGNED INTEGER,"
440 441
            "progress REAL,"
            "rating INTEGER DEFAULT -1,"
442
            "insertion_date UNSIGNED INTEGER,"
443
            "release_date UNSIGNED INTEGER,"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
444
            "thumbnail TEXT,"
445
            "title TEXT,"
446
            "filename TEXT,"
447
            "is_favorite BOOLEAN NOT NULL DEFAULT 0,"
448
            "is_present BOOLEAN NOT NULL DEFAULT 1"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
449
            ")";
450 451
    static const std::string indexReq = "CREATE INDEX IF NOT EXISTS index_last_played_date ON "
            + policy::MediaTable::Name + "(last_played_date DESC)";
452 453
    static const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
                + policy::MediaTable::Name + "Fts USING FTS3("
454 455
                "title,"
                "labels"
456 457
            ")";
    return sqlite::Tools::executeRequest( connection, req ) &&
458
            sqlite::Tools::executeRequest( connection, indexReq ) &&
459
            sqlite::Tools::executeRequest( connection, vtableReq );
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
}

bool Media::createTriggers( DBConnection connection )
{
    static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS has_files_present AFTER UPDATE OF "
            "is_present ON " + policy::FileTable::Name +
            " BEGIN "
            " UPDATE " + policy::MediaTable::Name + " SET is_present="
                "(SELECT COUNT(id_file) FROM " + policy::FileTable::Name + " WHERE media_id=new.media_id AND is_present=1) "
                "WHERE id_media=new.media_id;"
            " END;";
    static const std::string triggerReq2 = "CREATE TRIGGER IF NOT EXISTS cascade_file_deletion AFTER DELETE ON "
            + policy::FileTable::Name +
            " BEGIN "
            " DELETE FROM " + policy::MediaTable::Name + " WHERE "
                "(SELECT COUNT(id_file) FROM " + policy::FileTable::Name + " WHERE media_id=old.media_id) = 0"
                " AND id_media=old.media_id;"
            " END;";
478 479 480 481

    static const std::string vtableInsertTrigger = "CREATE TRIGGER IF NOT EXISTS insert_media_fts"
            " AFTER INSERT ON " + policy::MediaTable::Name +
            " BEGIN"
482
            " INSERT INTO " + policy::MediaTable::Name + "Fts(rowid,title,labels) VALUES(new.id_media, new.title, '');"
483 484
            " END";
    static const std::string vtableDeleteTrigger = "CREATE TRIGGER IF NOT EXISTS delete_media_fts"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
485
            " BEFORE DELETE ON " + policy::MediaTable::Name +
486 487 488 489 490 491 492 493
            " BEGIN"
            " DELETE FROM " + policy::MediaTable::Name + "Fts WHERE rowid = old.id_media;"
            " END";
    static const std::string vtableUpdateTitleTrigger2 = "CREATE TRIGGER IF NOT EXISTS update_media_title_fts"
              " AFTER UPDATE OF title ON " + policy::MediaTable::Name +
              " BEGIN"
              " UPDATE " + policy::MediaTable::Name + "Fts SET title = new.title WHERE rowid = new.id_media;"
              " END";
494
    return sqlite::Tools::executeRequest( connection, triggerReq ) &&
495 496 497 498
            sqlite::Tools::executeRequest( connection, triggerReq2 ) &&
            sqlite::Tools::executeRequest( connection, vtableInsertTrigger ) &&
            sqlite::Tools::executeRequest( connection, vtableDeleteTrigger ) &&
            sqlite::Tools::executeRequest( connection, vtableUpdateTitleTrigger2 );
499
}
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
500

501
bool Media::addLabel( LabelPtr label )
502
{
503
    if ( m_id == 0 || label->id() == 0 )
504
    {
505
        LOG_ERROR( "Both file & label need to be inserted in database before being linked together" );
506 507 508
        return false;
    }
    const char* req = "INSERT INTO LabelFileRelation VALUES(?, ?)";
509
    if ( sqlite::Tools::executeInsert( m_ml->getConn(), req, label->id(), m_id ) == 0 )
510 511 512
        return false;
    const std::string reqFts = "UPDATE " + policy::MediaTable::Name + "Fts "
        "SET labels = labels || ' ' || ? WHERE rowid = ?";
513
    return sqlite::Tools::executeUpdate( m_ml->getConn(), reqFts, label->name(), m_id );
514 515
}

516
bool Media::removeLabel( LabelPtr label )
517
{
518
    if ( m_id == 0 || label->id() == 0 )
519
    {
520
        LOG_ERROR( "Can't unlink a label/file not inserted in database" );
521 522
        return false;
    }
523
    const char* req = "DELETE FROM LabelFileRelation WHERE label_id = ? AND media_id = ?";
524
    if ( sqlite::Tools::executeDelete( m_ml->getConn(), req, label->id(), m_id ) == false )
525 526 527
        return false;
    const std::string reqFts = "UPDATE " + policy::MediaTable::Name + "Fts "
            "SET labels = TRIM(REPLACE(labels, ?, '')) WHERE rowid = ?";
528
    return sqlite::Tools::executeUpdate( m_ml->getConn(), reqFts, label->name(), m_id );
529
}
530 531


532
std::vector<MediaPtr> Media::search( MediaLibraryPtr ml, const std::string& title )
533 534 535
{
    static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE"
            " id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts"
536 537
            " WHERE " + policy::MediaTable::Name + "Fts MATCH ?)"
            "AND is_present = 1";
538
    return Media::fetchAll<IMedia>( ml, req, title + "*" );
539
}
540

541
std::vector<MediaPtr> Media::fetchHistory( MediaLibraryPtr ml )
542 543 544
{
    static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE last_played_date IS NOT NULL"
            " ORDER BY last_played_date DESC LIMIT 100";
545
    return fetchAll<IMedia>( ml, req );
546
}
547 548

}