Skip to content

Commit

Permalink
merge beta to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
StarGazer1258 committed Jun 23, 2019
2 parents 3791166 + 730105c commit eca4007
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 408 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "beatdrop",
"description": "A desktop app for downloading Beat Saber songs.",
"author": "Nathaniel Johns (StarGazer1258)",
"version": "2.5.2",
"version": "2.5.5",
"private": false,
"license": "CC-BY-NC-SA-4.0",
"repository": {
Expand Down
33 changes: 19 additions & 14 deletions src/actions/detailsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LOAD_DETAILS, CLEAR_DETAILS, SET_DETAILS_LOADING, SET_VIEW, DISPLAY_WAR
import { SONG_DETAILS } from '../views'

import AdmZip from 'adm-zip'
import { hashAndWriteToMetadata } from './queueActions'
const { remote } = window.require('electron')
const fs = remote.require('fs')
const path = remote.require('path')
Expand All @@ -10,7 +11,7 @@ const path = remote.require('path')
* Loads and presents the details page for a song from a file.
* @param {string} file The path to the song
*/
export const loadDetailsFromFile = file => dispatch => {
export const loadDetailsFromFile = file => (dispatch, getState) => {
dispatch({
type: CLEAR_DETAILS
})
Expand All @@ -27,19 +28,23 @@ export const loadDetailsFromFile = file => dispatch => {
let details = JSON.parse(data)
let dir = path.dirname(file)
details.coverURL = `file://${ path.join(dir, (details.coverImagePath || details._coverImageFilename)) }`
details.file = path.join(dir, 'info.json' || 'info.dat')
dispatch({
type: LOAD_DETAILS,
payload: details
})
dispatch({
type: LOAD_DETAILS,
payload: { audioSource: `file://${ path.join(dir, details._songFilename) }` }
})
dispatch({
type: SET_DETAILS_LOADING,
payload: false
})
details.file = path.join(dir, 'info.dat')
hashAndWriteToMetadata(path.join(dir, 'info.dat'))(dispatch, getState)
.then(hash => {
details.hash = hash
dispatch({
type: LOAD_DETAILS,
payload: details
})
dispatch({
type: LOAD_DETAILS,
payload: { audioSource: `file://${ path.join(dir, details._songFilename) }` }
})
dispatch({
type: SET_DETAILS_LOADING,
payload: false
})
})
})
}

Expand Down
54 changes: 11 additions & 43 deletions src/actions/playlistsActions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FETCH_LOCAL_PLAYLISTS, LOAD_NEW_PLAYLIST_IMAGE, SET_NEW_PLAYLIST_OPEN, SET_PLAYLIST_PICKER_OPEN, CLEAR_PLAYLIST_DIALOG, LOAD_PLAYLIST_DETAILS, LOAD_PLAYLIST_SONGS, CLEAR_PLAYLIST_DETAILS, SET_PLAYLIST_EDITING, SET_VIEW, SET_LOADING, DISPLAY_WARNING } from './types'
import { PLAYLIST_LIST, PLAYLIST_DETAILS } from '../views'
import { defaultPlaylistIcon } from '../b64Assets'
import { hashAndWriteToMetadata } from './queueActions';

const { remote } = window.require('electron')
const fs = remote.require('fs')
const path = remote.require('path')
const md5 = remote.require('md5')

export const fetchLocalPlaylists = (doSetView) => (dispatch, getState) => {
let state = getState()
Expand Down Expand Up @@ -313,51 +313,19 @@ export const addSongToPlaylist = (song, playlistFile) => (dispatch, getState) =>
return
}
let playlist = JSON.parse(data)
if(song.hash || song.hashMd5) {
if(song.key) {
playlist.songs.push({
hash: song.hash || song.hashMd5,
key: song.key,
songName: song.name || song.songName
})
} else {
playlist.songs.push({
hash: song.hash || song.hashMd5,
songName: song.name || song.songName
})
}
if(song.hash) {
playlist.songs.push({
hash: song.hash,
songName: song.name || song._songName
})
} else {
if(song.file) {
let file = song.file
delete song.file
let to_hash = ''
for(let i = 0; i < song.difficultyLevels.length; i++) {
try {
to_hash += fs.readFileSync(path.join(path.dirname(file), song.difficultyLevels[i].jsonPath), 'UTF8')
} catch(err) {
dispatch({
type: DISPLAY_WARNING,
action: { text: 'Error reading difficulty level information, the song\'s files may be corrupt. Try redownloading the song and try again.' }
})
return
}
}
let hash = md5(to_hash)
song.hash = hash
fs.writeFile(file, JSON.stringify(song), 'UTF8', (err) => { if(err) return })
if(song.key) {
playlist.songs.push({
hash: hash,
key: song.key,
songName: song.name || song.songName
})
} else {
hashAndWriteToMetadata(song.file)(dispatch, getState)
.then(hash => {
playlist.songs.push({
hash: hash,
songName: song.name || song.songName
hash,
songName: song.name || song._songName
})
}
}
})
}

fs.writeFile(playlistFile, JSON.stringify(playlist), 'UTF8', (err) => {
Expand Down
Loading

0 comments on commit eca4007

Please sign in to comment.