mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 13:04:23 +00:00
updates that break stuff temporarily
This commit is contained in:
@@ -4,10 +4,10 @@ const path = require( 'path' );
|
||||
const cors = require( 'cors' );
|
||||
const fs = require( 'fs' );
|
||||
const bodyParser = require( 'body-parser' );
|
||||
const musicMetadata = require( 'music-metadata' );
|
||||
const dialog = require( 'electron' ).dialog;
|
||||
const session = require( 'express-session' );
|
||||
|
||||
|
||||
app.use( bodyParser.urlencoded( { extended: false } ) );
|
||||
app.use( bodyParser.json() );
|
||||
app.use( cors() );
|
||||
@@ -17,9 +17,6 @@ app.use( session( {
|
||||
resave: false,
|
||||
} ) );
|
||||
|
||||
let indexedData = {};
|
||||
let coverArtIndex = {};
|
||||
const allowedFileTypes = [ '.mp3', '.wav', '.flac' ];
|
||||
|
||||
let connectedClients = {};
|
||||
let changedStatus = [];
|
||||
@@ -123,59 +120,11 @@ app.get( '/openSongs', ( req, res ) => {
|
||||
|
||||
app.get( '/indexDirs', ( req, res ) => {
|
||||
if ( req.query.dir ) {
|
||||
// TODO: Load from json file
|
||||
if ( indexedData[ req.query.dir ] ) {
|
||||
res.send( indexedData[ req.query.dir ] );
|
||||
} else {
|
||||
fs.readdir( req.query.dir, { encoding: 'utf-8' }, ( err, dat ) => {
|
||||
if ( err ) {
|
||||
res.status( 404 ).send( 'ERR_DIR_NOT_FOUND' );
|
||||
return;
|
||||
};
|
||||
( async() => {
|
||||
// TODO: Check for songlist.csv or songlist.json file and use the data provided there for each song to override
|
||||
// what was found automatically. If no song title was found in songlist or metadata, use filename
|
||||
// TODO: Also save found information to those files and don't rerun checks if data is present
|
||||
let files = {};
|
||||
for ( let file in dat ) {
|
||||
if ( allowedFileTypes.includes( dat[ file ].slice( dat[ file ].indexOf( '.' ), dat[ file ].length ) ) ) {
|
||||
try {
|
||||
let metadata = await musicMetadata.parseFile( req.query.dir + '/' + dat[ file ] );
|
||||
files[ req.query.dir + '/' + dat[ file ] ] = {
|
||||
'artist': metadata[ 'common' ][ 'artist' ],
|
||||
'title': metadata[ 'common' ][ 'title' ],
|
||||
'year': metadata[ 'common' ][ 'year' ],
|
||||
'bpm': metadata[ 'common' ][ 'bpm' ],
|
||||
'genre': metadata[ 'common' ][ 'genre' ],
|
||||
'duration': Math.round( metadata[ 'format' ][ 'duration' ] ),
|
||||
'isLossless': metadata[ 'format' ][ 'lossless' ],
|
||||
'sampleRate': metadata[ 'format' ][ 'sampleRate' ],
|
||||
'bitrate': metadata[ 'format' ][ 'bitrate' ],
|
||||
'numberOfChannels': metadata[ 'format' ][ 'numberOfChannels' ],
|
||||
'container': metadata[ 'format' ][ 'container' ],
|
||||
'filename': req.query.dir + '/' + dat[ file ],
|
||||
}
|
||||
if ( metadata[ 'common' ][ 'picture' ] ) {
|
||||
files[ req.query.dir + '/' + dat[ file ] ][ 'hasCoverArt' ] = true;
|
||||
if ( req.query.coverart == 'true' ) {
|
||||
coverArtIndex[ req.query.dir + '/' + dat[ file ] ] = metadata[ 'common' ][ 'picture' ] ? metadata[ 'common' ][ 'picture' ][ 0 ][ 'data' ] : undefined;
|
||||
}
|
||||
} else {
|
||||
files[ req.query.dir + '/' + dat[ file ] ][ 'hasCoverArt' ] = false;
|
||||
}
|
||||
} catch ( err ) {
|
||||
console.error( err );
|
||||
files[ req.query.dir + '/' + dat[ file ] ] = 'ERROR';
|
||||
}
|
||||
} else if ( dat[ file ].slice( dat[ file ].indexOf( '.' ), dat[ file ].length ) === '.csv' ) {
|
||||
|
||||
} else if ( dat[ file ].slice( dat[ file ].indexOf( '.' ), dat[ file ].length ) === '.json' ) {
|
||||
|
||||
}
|
||||
}
|
||||
indexedData[ req.query.dir ] = files;
|
||||
res.send( files );
|
||||
} )();
|
||||
} );
|
||||
res.send( files );
|
||||
}
|
||||
} else {
|
||||
res.status( 400 ).send( 'ERR_REQ_INCOMPLETE' );
|
||||
@@ -202,9 +151,6 @@ app.get( '/getSongFile', ( req, res ) => {
|
||||
}
|
||||
} );
|
||||
|
||||
// TODO: Add get lyrics route later
|
||||
// 'lyrics': metadata[ 'common' ][ 'lyrics' ],
|
||||
|
||||
|
||||
app.use( ( request, response, next ) => {
|
||||
response.sendFile( path.join( __dirname + '' ) )
|
||||
|
||||
Reference in New Issue
Block a user