MythTV  master
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
MusicFileScanner Class Reference

#include <musicfilescanner.h>

Collaboration diagram for MusicFileScanner:
Collaboration graph
[legend]

Classes

struct  MusicFileData
 

Public Member Functions

 MusicFileScanner (bool force=false)
 
 ~MusicFileScanner (void)=default
 
void SearchDirs (const QStringList &dirList)
 Scan a list of directories recursively for music and albumart. Inserts, updates and removes any files any files found in the database. More...
 

Static Public Member Functions

static bool IsRunning (void)
 

Private Types

enum  MusicFileLocation { kFileSystem, kDatabase, kNeedUpdate, kBoth }
 
using MusicLoadedMap = QMap< QString, MusicFileData >
 

Private Member Functions

void BuildFileList (QString &directory, MusicLoadedMap &music_files, MusicLoadedMap &art_files, int parentid)
 Builds a list of all the files found descending recursively into the given directory. More...
 
void AddFileToDB (const QString &filename, const QString &startDir)
 Insert file details into database. If it is an audio file, read the metadata and insert that information at the same time. More...
 
void RemoveFileFromDB (const QString &filename, const QString &startDir)
 Removes a file from the database. More...
 
void UpdateFileInDB (const QString &filename, const QString &startDir)
 Updates a file in the database. More...
 
void ScanMusic (MusicLoadedMap &music_files)
 Check a list of files against musics files already in the database. More...
 
void ScanArtwork (MusicLoadedMap &music_files)
 Check a list of files against images already in the database. More...
 

Static Private Member Functions

static int GetDirectoryId (const QString &directory, const int &parentid)
 Get an ID for the given directory from the database. If it doesn't already exist in the database, insert it. More...
 
static bool HasFileChanged (const QString &filename, const QString &date_modified)
 Check if file has been modified since given date/time. More...
 
static void cleanDB ()
 Clear orphaned entries from the genre, artist, album and albumart tables. More...
 
static bool IsArtFile (const QString &filename)
 
static bool IsMusicFile (const QString &filename)
 
static void updateLastRunEnd (void)
 
static void updateLastRunStart (void)
 
static void updateLastRunStatus (QString &status)
 

Private Attributes

QStringList m_startDirs
 
IdCache m_directoryid
 
IdCache m_artistid
 
IdCache m_genreid
 
IdCache m_albumid
 
uint m_tracksTotal {0}
 
uint m_tracksUnchanged {0}
 
uint m_tracksAdded {0}
 
uint m_tracksRemoved {0}
 
uint m_tracksUpdated {0}
 
uint m_coverartTotal {0}
 
uint m_coverartUnchanged {0}
 
uint m_coverartAdded {0}
 
uint m_coverartRemoved {0}
 
uint m_coverartUpdated {0}
 
bool m_forceupdate {false}
 

Detailed Description

Definition at line 12 of file musicfilescanner.h.

Member Typedef Documentation

◆ MusicLoadedMap

using MusicFileScanner::MusicLoadedMap = QMap <QString, MusicFileData>
private

Definition at line 30 of file musicfilescanner.h.

Member Enumeration Documentation

◆ MusicFileLocation

Enumerator
kFileSystem 
kDatabase 
kNeedUpdate 
kBoth 

Definition at line 16 of file musicfilescanner.h.

Constructor & Destructor Documentation

◆ MusicFileScanner()

MusicFileScanner::MusicFileScanner ( bool  force = false)

Definition at line 16 of file musicfilescanner.cpp.

◆ ~MusicFileScanner()

MusicFileScanner::~MusicFileScanner ( void  )
default

Member Function Documentation

◆ SearchDirs()

void MusicFileScanner::SearchDirs ( const QStringList &  dirList)

Scan a list of directories recursively for music and albumart. Inserts, updates and removes any files any files found in the database.

Parameters
dirListList of directories to scan
Returns
Nothing.

Definition at line 649 of file musicfilescanner.cpp.

◆ IsRunning()

bool MusicFileScanner::IsRunning ( void  )
static

Definition at line 887 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ BuildFileList()

void MusicFileScanner::BuildFileList ( QString &  directory,
MusicLoadedMap music_files,
MusicLoadedMap art_files,
int  parentid 
)
private

Builds a list of all the files found descending recursively into the given directory.

Parameters
directoryDirectory to begin search
music_filesA pointer to the MusicLoadedMap to store the results
art_filesA pointer to the MusicLoadedMap to store the results
parentidThe id of the parent directory in the music_directories table. The root directory should have an id of 0
Returns
Nothing.

Definition at line 73 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ GetDirectoryId()

int MusicFileScanner::GetDirectoryId ( const QString &  directory,
const int &  parentid 
)
staticprivate

Get an ID for the given directory from the database. If it doesn't already exist in the database, insert it.

Parameters
directoryRelative path to directory, from base dir
parentidThe id of the parent directory in the music_directories table. The root directory should have an id of 0
Returns
Directory id

Definition at line 177 of file musicfilescanner.cpp.

Referenced by BuildFileList().

◆ HasFileChanged()

bool MusicFileScanner::HasFileChanged ( const QString &  filename,
const QString &  date_modified 
)
staticprivate

Check if file has been modified since given date/time.

Parameters
filenameFile to examine
date_modifiedDate to use in comparison
Returns
True if file has been modified, otherwise false

Definition at line 224 of file musicfilescanner.cpp.

Referenced by ScanMusic().

◆ AddFileToDB()

void MusicFileScanner::AddFileToDB ( const QString &  filename,
const QString &  startDir 
)
private

Insert file details into database. If it is an audio file, read the metadata and insert that information at the same time.

If it is an image file, just insert the filename and type.

Parameters
filenameFull path to file.
startDirThe starting directory fir the search. This will be removed making the stored name relative to the storage directory where it was found.
Returns
Nothing.

Definition at line 254 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ RemoveFileFromDB()

void MusicFileScanner::RemoveFileFromDB ( const QString &  filename,
const QString &  startDir 
)
private

Removes a file from the database.

Parameters
filenameFull path to file.
startDirThe starting directory fir the search. This will be removed making the stored name relative to the storage directory where it was found.
Returns
Nothing.

Definition at line 509 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ UpdateFileInDB()

void MusicFileScanner::UpdateFileInDB ( const QString &  filename,
const QString &  startDir 
)
private

Updates a file in the database.

Parameters
filenameFull path to file.
startDirThe starting directory fir the search. This will be removed making the stored name relative to the storage directory where it was found.
Returns
Nothing.

Definition at line 560 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ ScanMusic()

void MusicFileScanner::ScanMusic ( MusicLoadedMap music_files)
private

Check a list of files against musics files already in the database.

Parameters
music_filesMusicLoadedMap
Returns
Nothing.

Definition at line 784 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ ScanArtwork()

void MusicFileScanner::ScanArtwork ( MusicLoadedMap music_files)
private

Check a list of files against images already in the database.

Parameters
music_filesMusicLoadedMap
Returns
Nothing.

Definition at line 840 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ cleanDB()

void MusicFileScanner::cleanDB ( )
staticprivate

Clear orphaned entries from the genre, artist, album and albumart tables.

Returns
Nothing.

Definition at line 372 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ IsArtFile()

bool MusicFileScanner::IsArtFile ( const QString &  filename)
staticprivate

Definition at line 148 of file musicfilescanner.cpp.

Referenced by BuildFileList().

◆ IsMusicFile()

bool MusicFileScanner::IsMusicFile ( const QString &  filename)
staticprivate

Definition at line 158 of file musicfilescanner.cpp.

Referenced by BuildFileList().

◆ updateLastRunEnd()

void MusicFileScanner::updateLastRunEnd ( void  )
staticprivate

Definition at line 892 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ updateLastRunStart()

void MusicFileScanner::updateLastRunStart ( void  )
staticprivate

Definition at line 898 of file musicfilescanner.cpp.

Referenced by SearchDirs().

◆ updateLastRunStatus()

void MusicFileScanner::updateLastRunStatus ( QString &  status)
staticprivate

Definition at line 904 of file musicfilescanner.cpp.

Referenced by SearchDirs().

Member Data Documentation

◆ m_startDirs

QStringList MusicFileScanner::m_startDirs
private

Definition at line 56 of file musicfilescanner.h.

Referenced by BuildFileList(), ScanArtwork(), ScanMusic(), and SearchDirs().

◆ m_directoryid

IdCache MusicFileScanner::m_directoryid
private

Definition at line 57 of file musicfilescanner.h.

Referenced by AddFileToDB(), BuildFileList(), RemoveFileFromDB(), and UpdateFileInDB().

◆ m_artistid

IdCache MusicFileScanner::m_artistid
private

Definition at line 58 of file musicfilescanner.h.

Referenced by AddFileToDB(), and UpdateFileInDB().

◆ m_genreid

IdCache MusicFileScanner::m_genreid
private

Definition at line 59 of file musicfilescanner.h.

Referenced by AddFileToDB(), and UpdateFileInDB().

◆ m_albumid

IdCache MusicFileScanner::m_albumid
private

Definition at line 60 of file musicfilescanner.h.

Referenced by AddFileToDB(), and UpdateFileInDB().

◆ m_tracksTotal

uint MusicFileScanner::m_tracksTotal {0}
private

Definition at line 62 of file musicfilescanner.h.

Referenced by SearchDirs().

◆ m_tracksUnchanged

uint MusicFileScanner::m_tracksUnchanged {0}
private

Definition at line 63 of file musicfilescanner.h.

Referenced by ScanMusic(), and SearchDirs().

◆ m_tracksAdded

uint MusicFileScanner::m_tracksAdded {0}
private

Definition at line 64 of file musicfilescanner.h.

Referenced by AddFileToDB(), and SearchDirs().

◆ m_tracksRemoved

uint MusicFileScanner::m_tracksRemoved {0}
private

Definition at line 65 of file musicfilescanner.h.

Referenced by RemoveFileFromDB(), and SearchDirs().

◆ m_tracksUpdated

uint MusicFileScanner::m_tracksUpdated {0}
private

Definition at line 66 of file musicfilescanner.h.

Referenced by SearchDirs().

◆ m_coverartTotal

uint MusicFileScanner::m_coverartTotal {0}
private

Definition at line 67 of file musicfilescanner.h.

Referenced by SearchDirs().

◆ m_coverartUnchanged

uint MusicFileScanner::m_coverartUnchanged {0}
private

Definition at line 68 of file musicfilescanner.h.

Referenced by ScanArtwork(), and SearchDirs().

◆ m_coverartAdded

uint MusicFileScanner::m_coverartAdded {0}
private

Definition at line 69 of file musicfilescanner.h.

Referenced by AddFileToDB(), and SearchDirs().

◆ m_coverartRemoved

uint MusicFileScanner::m_coverartRemoved {0}
private

Definition at line 70 of file musicfilescanner.h.

Referenced by RemoveFileFromDB(), and SearchDirs().

◆ m_coverartUpdated

uint MusicFileScanner::m_coverartUpdated {0}
private

Definition at line 71 of file musicfilescanner.h.

Referenced by SearchDirs().

◆ m_forceupdate

bool MusicFileScanner::m_forceupdate {false}
private

Definition at line 73 of file musicfilescanner.h.

Referenced by ScanMusic().


The documentation for this class was generated from the following files: