Media.cpp 17 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
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps)
264
{
265
    return VideoTrack::create( m_ml, codec, width, height, fps, m_id ) != nullptr;
266 267
}

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

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

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

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

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

299 300 301 302 303 304 305 306 307 308 309 310 311
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
312
void Media::setThumbnail(const std::string& thumbnail )
313
{
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
314
    if ( m_thumbnail == thumbnail )
315
        return;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
316
    m_thumbnail = thumbnail;
317 318 319 320 321 322
    m_changed = true;
}

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

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

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

358
std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, SortingCriteria sort, bool desc )
359
{
360
    std::string req;
361
    if ( sort == SortingCriteria::LastModificationDate )
362 363 364 365 366 367 368 369 370 371 372 373 374
    {
        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 )
    {
375
    case SortingCriteria::Duration:
376 377
        req += "duration";
        break;
378
    case SortingCriteria::InsertionDate:
379 380
        req += "insertion_date";
        break;
381
    case SortingCriteria::ReleaseDate:
382 383 384
        req += "release_date";
        break;
    default:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
385
        req += "title";
386 387 388 389 390 391
        break;
    }
    if ( desc == true )
        req += " DESC";

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

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

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

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

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

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

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

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

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;";
477 478 479 480

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

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

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


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

540
std::vector<MediaPtr> Media::fetchHistory( MediaLibraryPtr ml )
541 542 543
{
    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";
544
    return fetchAll<IMedia>( ml, req );
545
}
546 547

}