-- View the current index in the history and its validity
CREATEVIEWIFNOTEXISTSViewHistoryIndexAS
SELECT
HistoryPosition.index_histASIDX,-- the index in the history
IFNULL((SELECTHistory.index_histFROMHistory,HistoryPositionWHEREHistory.index_hist<HistoryPosition.index_histORDERBYHistory.index_histDESCLIMIT1),-1)PREV_IDX,-- get the previous id or a default invalid one if none
IFNULL((SELECTHistory.index_histFROMHistory,HistoryPositionWHEREHistory.index_hist>HistoryPosition.index_histORDERBYHistory.index_histASCLIMIT1),-1)NEXT_IDX,-- get the next id or a default invalid one if none
IFNULL((SELECTHistory.hashFROMHistory,HistoryPositionWHEREHistory.index_hist<HistoryPosition.index_histORDERBYHistory.index_histDESCLIMIT1),'')PREV_HASH,-- get the previous hash or a default invalid one if none
IFNULL((SELECTHistory.hashFROMHistory,HistoryPositionWHEREHistory.index_hist>HistoryPosition.index_histORDERBYHistory.index_histASCLIMIT1),'')NEXT_HASH,-- get the next hash or a default invalid one if none
CASEWHENHistoryPosition.index_histIN(SELECTindex_histFROMHistory)THENTRUEELSEFALSEENDVALID-- the validity of the current index
FROMHistoryPositionLIMIT1;
CREATEVIEWIFNOTEXISTSMpcHcIndexesASSELECTconfig_id,play_index,COUNT(play_index)FROMMpcHcGROUPBYconfig_id;-- View the indexes of all configurations in MpcHc playlists
CREATEVIEWIFNOTEXISTSViewPlaylistSummaryASSELECTBelongs.nameASPLNAME,COUNT(Belongs.hash)ASPLSIZEFROMBelongsGROUPBYBelongs.name;-- View all playlists with their number of elements
CREATEVIEWIFNOTEXISTSViewKaraCountASSELECTCOUNT(Kara.hash)ASLENFROMKara;-- View the total number of kara in the database
CREATEVIEWIFNOTEXISTSViewKaraAllASSELECTKARA,ID,HASHFROMViewKaraUNIONSELECTKARA,ID,HASHFROMViewNouveauKara;-- View all Kara, nouveaux or not
-- View all playlists with all their content, unused for the moment, will be because take into account the nouveau kara
CREATEVIEWIFNOTEXISTSViewPlaylistAS-- (PLNAME, HASH, KARA, KARAPATH, AUTHOR)
SELECT
Belongs.nameASPLNAME,
Belongs.hashASHASH,
CASEWHENnouveau=FALSETHEN('/home/kara/'||category||'/'||Kara.name||' - '||type||' - '||title||'.mkv')-- Path for a non-nouveau kara
ELSE('/home/kara/nouveaux/'||People.pseudo||'/'||category||'/'||Kara.name||' - '||type||' - '||title||'.mkv')-- Path for a nouveau kara
ENDKARAPATH,
KaraToPeople.pseudoASAUTHOR-- The author if available
FROMPlaylistJOINBelongsONBelongs.plname=Playlist.name-- Get the playlist
JOINKaraONBelongs.hash=Kara.hashLEFTOUTERJOINKaraToPeopleONKaraToPeople.hash=Kara.hash;-- And its correspondig kara
-- View the content of a config
CREATEVIEWIFNOTEXISTSConfigContentAS
SELECT
Config.nameASPLNAME,-- The name of the config i.e. the name of the dynamic playlist
Config.idASID,-- The id of the dynamic playlist
MpcHc.fromDatabaseASISDB,-- Is this file from the database or directly from the filesystem
CASE
WHENMpcHc.fromDatabase=FALSETHENMpcHc.filename-- If the file is from the filesystem get the fullpath with the extension
ELSE(SELECT('/home/kara/'||KARA||'.mkv')ASKARAFROMViewKaraAllWHEREViewKaraAll.HASH=MpcHc.hash)-- If it's from the db, get the filepath with the extension
ENDKARA,-- Always a valid path to directly pass it to mpv
MpcHc.play_indexASPLAYINDEX-- The index in the playlist of this kara