Macos fix
This commit is contained in:
parent
b9ea1928b9
commit
d45173872b
5 changed files with 41 additions and 27 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@euterpe.js/euterpe",
|
"name": "@euterpe.js/euterpe",
|
||||||
"version": "1.0.11",
|
"version": "1.0.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!",
|
"description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@euterpe.js/player",
|
"name": "@euterpe.js/player",
|
||||||
"version": "1.0.6",
|
"version": "1.0.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "A simple, safe AudioContext web music player",
|
"description": "A simple, safe AudioContext web music player",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
|
|
|
@ -122,7 +122,7 @@ export class MusicPlayer {
|
||||||
*/
|
*/
|
||||||
try_seek_async(new_time: number) {
|
try_seek_async(new_time: number) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.track.context.state == "closed" || this.track.context.state == "suspended") {
|
if (this.track.context.state !== "running") {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
reject(new Error("Can't seek - track not playing"))
|
reject(new Error("Can't seek - track not playing"))
|
||||||
}
|
}
|
||||||
|
@ -141,9 +141,9 @@ export class MusicPlayer {
|
||||||
*/
|
*/
|
||||||
try_play_toggle_async() {
|
try_play_toggle_async() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") {
|
if (this.track.context.state !== "running") {
|
||||||
this.audio_context.resume().then(undefined, (e) =>
|
this.audio_context.resume().then(undefined, (e) =>
|
||||||
reject(new Error("Context closed or suspended" + JSON.stringify(e))))
|
reject(e))
|
||||||
}
|
}
|
||||||
if (this.audio_element.paused) {
|
if (this.audio_element.paused) {
|
||||||
this.audio_element.play().then((s) => {
|
this.audio_element.play().then((s) => {
|
||||||
|
@ -151,7 +151,7 @@ export class MusicPlayer {
|
||||||
resolve(s)
|
resolve(s)
|
||||||
}, (r) => {
|
}, (r) => {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
reject(new Error("failed to play audio elements" + JSON.stringify(r)))
|
reject(r)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.audio_element.pause()
|
this.audio_element.pause()
|
||||||
|
@ -165,7 +165,7 @@ export class MusicPlayer {
|
||||||
*/
|
*/
|
||||||
play_toggle_async() {
|
play_toggle_async() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") {
|
if (this.track.context.state !== "running") {
|
||||||
this.audio_context.resume()
|
this.audio_context.resume()
|
||||||
}
|
}
|
||||||
if (this.audio_element.paused) {
|
if (this.audio_element.paused) {
|
||||||
|
@ -174,7 +174,7 @@ export class MusicPlayer {
|
||||||
resolve(s)
|
resolve(s)
|
||||||
}, (r) => {
|
}, (r) => {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
reject(new Error(JSON.stringify(r)))
|
reject(r)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.audio_element.pause()
|
this.audio_element.pause()
|
||||||
|
@ -204,14 +204,14 @@ export class MusicPlayer {
|
||||||
try_play_async() {
|
try_play_async() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.is_playing) resolve(Error("Already playing"))
|
if (this.is_playing) resolve(Error("Already playing"))
|
||||||
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") {
|
if (this.track.context.state !== "running") {
|
||||||
this.audio_context.resume().then(() => {
|
this.audio_context.resume().then(() => {
|
||||||
this.audio_element.play().then((s) => {
|
this.audio_element.play().then((s) => {
|
||||||
this.is_playing = true
|
this.is_playing = true
|
||||||
resolve(s)
|
resolve(s)
|
||||||
}, (r) => {
|
}, (r) => {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
reject(new Error(JSON.stringify(r)))
|
reject(r)
|
||||||
})
|
})
|
||||||
}, (e) =>
|
}, (e) =>
|
||||||
reject(new Error("Context closed or suspended" + JSON.stringify(e))))
|
reject(new Error("Context closed or suspended" + JSON.stringify(e))))
|
||||||
|
@ -221,7 +221,7 @@ export class MusicPlayer {
|
||||||
resolve(s)
|
resolve(s)
|
||||||
}, (r) => {
|
}, (r) => {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
reject(new Error(JSON.stringify(r)))
|
reject(r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -237,7 +237,7 @@ export class MusicPlayer {
|
||||||
resolve(s)
|
resolve(s)
|
||||||
}, (r) => {
|
}, (r) => {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
reject(new Error(JSON.stringify(r)))
|
reject(r)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ export class MusicPlayer {
|
||||||
if (this.is_playing) return
|
if (this.is_playing) return
|
||||||
this.audio_element.play().catch((r) => {
|
this.audio_element.play().catch((r) => {
|
||||||
this.is_playing = false
|
this.is_playing = false
|
||||||
throw new Error(r)
|
throw r
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -274,12 +274,12 @@ export class MusicPlayer {
|
||||||
|
|
||||||
this.audio_element.addEventListener("error", function error_listener(e) {
|
this.audio_element.addEventListener("error", function error_listener(e) {
|
||||||
controller.abort()
|
controller.abort()
|
||||||
reject(new Error("Failed to load new song, error:" + JSON.stringify(e)))
|
reject(e)
|
||||||
}, { signal: controller.signal })
|
}, { signal: controller.signal })
|
||||||
|
|
||||||
this.audio_element.addEventListener("stalled", function stalled_listener(e) {
|
this.audio_element.addEventListener("stalled", function stalled_listener(e) {
|
||||||
controller.abort()
|
controller.abort()
|
||||||
reject(new Error("Failed to load new song, stalled: " + JSON.stringify(e)))
|
reject(e)
|
||||||
}, { signal: controller.signal })
|
}, { signal: controller.signal })
|
||||||
|
|
||||||
//once aborted, try to set current_song_duration
|
//once aborted, try to set current_song_duration
|
||||||
|
@ -408,7 +408,7 @@ export class MusicPlayerBuilder {
|
||||||
constructor(private audio_element: HTMLAudioElement) {
|
constructor(private audio_element: HTMLAudioElement) {
|
||||||
if (audio_element === undefined) throw Error("audio_element was undefined")
|
if (audio_element === undefined) throw Error("audio_element was undefined")
|
||||||
// ↓ For old browsers
|
// ↓ For old browsers
|
||||||
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
const AudioContext = window.AudioContext;
|
||||||
this.#audio_context = new AudioContext()
|
this.#audio_context = new AudioContext()
|
||||||
this.#track = this.#audio_context.createMediaElementSource(audio_element)
|
this.#track = this.#audio_context.createMediaElementSource(audio_element)
|
||||||
this.#gain = this.#audio_context.createGain()
|
this.#gain = this.#audio_context.createGain()
|
||||||
|
|
|
@ -8,21 +8,33 @@ import filehound from "filehound"
|
||||||
import { execSync, exec } from 'child_process'
|
import { execSync, exec } from 'child_process'
|
||||||
import { fstat, unlinkSync } from "fs"
|
import { fstat, unlinkSync } from "fs"
|
||||||
|
|
||||||
function generateNewPhotoSizes(file, currentExtention) {
|
function generate_new_photo_sizes(file, currentExtention) {
|
||||||
exec(`start ffmpeg -y -i "${file}.${currentExtention}" -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_ogw.webp" -vf scale=1000:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_1000w.webp" -vf scale=800:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_800w.webp" -vf scale=500:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_500w.webp" -vf scale=320:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_320w.webp" -vf scale=-1:64,gblur=sigma=10:steps=2 -lossless 0 -compression_level 6 -quality 85 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_placeholder.webp"`)
|
exec(`start ffmpeg -y -i "${file}.${currentExtention}" -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_ogw.webp" -vf scale=1000:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_1000w.webp" -vf scale=800:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_800w.webp" -vf scale=500:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_500w.webp" -vf scale=320:-1 -lossless 0 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_320w.webp" -vf scale=-1:64,gblur=sigma=10:steps=2 -lossless 0 -compression_level 6 -quality 85 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_placeholder.webp"`)
|
||||||
}
|
}
|
||||||
function generateNewAnimPhotoSizes(file, currentExtention) {
|
function generate_new_anim_photo_sizes(file, currentExtention) {
|
||||||
exec(`start ffmpeg -y -i "${file}.${currentExtention}" -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_ogw_static.webp" -vf scale=1000:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_1000w_static.webp" -vf scale=800:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_800w_static.webp" -vf scale=500:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_500w_static.webp" -vf scale=320:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_320w_static.webp" -vf scale=-1:64,gblur=sigma=10:steps=2 -lossless 0 -frames:v 1 -r 1 -compression_level 6 -quality 85 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_placeholder_static.webp"`)
|
exec(`start ffmpeg -y -i "${file}.${currentExtention}" -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_ogw_static.webp" -vf scale=1000:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_1000w_static.webp" -vf scale=800:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_800w_static.webp" -vf scale=500:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_500w_static.webp" -vf scale=320:-1 -lossless 0 -frames:v 1 -r 1 -quality 85 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_320w_static.webp" -vf scale=-1:64,gblur=sigma=10:steps=2 -lossless 0 -frames:v 1 -r 1 -compression_level 6 -quality 85 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_placeholder_static.webp"`)
|
||||||
exec(`start ffmpeg -y -i "${file}.${currentExtention}" -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_ogw.webp" -vf scale=1000:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_1000w.webp" -vf scale=800:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_800w.webp" -vf scale=500:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_500w.webp" -vf scale=320:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_320w.webp" -vf scale=-1:64,gblur=sigma=10:steps=2 -frames:v 1 -lossless 0 -c:v libwebp -compression_level 6 -quality 85 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_placeholder.webp"`)
|
exec(`start ffmpeg -y -i "${file}.${currentExtention}" -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_ogw.webp" -vf scale=1000:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_1000w.webp" -vf scale=800:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_800w.webp" -vf scale=500:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_500w.webp" -vf scale=320:-1 -lossless 0 -quality 85 -loop 0 -compression_level 6 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_320w.webp" -vf scale=-1:64,gblur=sigma=10:steps=2 -frames:v 1 -lossless 0 -c:v libwebp -compression_level 6 -quality 85 -metadata author="Djkáťo" -metadata copyright="https://djkato.net" "${file}_placeholder.webp"`)
|
||||||
}
|
}
|
||||||
function generateNewSounds(file, currentExtention) {
|
function generate_new_sounds_ogg(file, currentExtention) {
|
||||||
const path = file.substring(0, file.lastIndexOf("\\"))
|
const path = file.substring(0, file.lastIndexOf("\\"))
|
||||||
file = file.substring(file.lastIndexOf("\\") + 1)
|
file = file.substring(file.lastIndexOf("\\") + 1)
|
||||||
|
|
||||||
let command = ""
|
let command = ""
|
||||||
command += `cd "${path}" && start cmd /k "`
|
command += `cd "${path}" && start cmd /k "`
|
||||||
command += `ffmpeg -y -i "${file}.${currentExtention}" `
|
command += `ffmpeg -y -i "${file}.${currentExtention}" `
|
||||||
command += `-c:a libopus -b:a 128k "${file}.ogg"`
|
command += `-c:a libopus -b:a 96k "${file}.ogg"`
|
||||||
|
command += ` && exit"`
|
||||||
|
exec(command)
|
||||||
|
// console.log(command)
|
||||||
|
}
|
||||||
|
function generate_new_sounds_mp3(file, currentExtention) {
|
||||||
|
const path = file.substring(0, file.lastIndexOf("\\"))
|
||||||
|
file = file.substring(file.lastIndexOf("\\") + 1)
|
||||||
|
|
||||||
|
let command = ""
|
||||||
|
command += `cd "${path}" && start cmd /k "`
|
||||||
|
command += `ffmpeg -y -i "${file}.${currentExtention}" `
|
||||||
|
command += `-b:a 160k "${file}.mp3"`
|
||||||
command += ` && exit"`
|
command += ` && exit"`
|
||||||
exec(command)
|
exec(command)
|
||||||
// console.log(command)
|
// console.log(command)
|
||||||
|
@ -70,25 +82,27 @@ for (let i = 0; i < dirs.length; i++) {
|
||||||
}
|
}
|
||||||
for (let current_media of current_folder_files) {
|
for (let current_media of current_folder_files) {
|
||||||
current_media = [current_media.substring(0, current_media.lastIndexOf(".")), current_media.substring(current_media.lastIndexOf(".") + 1)]
|
current_media = [current_media.substring(0, current_media.lastIndexOf(".")), current_media.substring(current_media.lastIndexOf(".") + 1)]
|
||||||
if (current_media[1] == "wav" || current_media[1] == "mp3") {
|
if (current_media[1] == "wav") {
|
||||||
console.log(`${current_media[0]}.${current_media[1]}\n`)
|
console.log(`${current_media[0]}.${current_media[1]}\n`)
|
||||||
|
|
||||||
generateNewSounds(`${current_media[0]}`, `${current_media[1]}`)
|
generate_new_sounds_ogg(`${current_media[0]}`, `${current_media[1]}`)
|
||||||
|
generate_new_sounds_mp3(`${current_media[0]}`, `${current_media[1]}`)
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
if (current_media[1] == "png" || current_media[1] == "jpg") {
|
if (current_media[1] == "png" || current_media[1] == "jpg") {
|
||||||
console.log(`.\\${current_media[0]}.${current_media[1]}\n`)
|
console.log(`.\\${current_media[0]}.${current_media[1]}\n`)
|
||||||
|
|
||||||
generateNewPhotoSizes(`.\\${current_media[0]}`, `${current_media[1]}`)
|
generate_new_photo_sizes(`.\\${current_media[0]}`, `${current_media[1]}`)
|
||||||
}
|
}
|
||||||
else if (current_media[1] == "gif") {
|
else if (current_media[1] == "gif") {
|
||||||
console.log(`.\\${current_media[0]}.${current_media[1]}\n`)
|
console.log(`.\\${current_media[0]}.${current_media[1]}\n`)
|
||||||
|
|
||||||
generateNewAnimPhotoSizes(`.\\${current_media[0]}`, `${current_media[1]}`)
|
generate_new_anim_photo_sizes(`.\\${current_media[0]}`, `${current_media[1]}`)
|
||||||
}
|
}
|
||||||
else if (current_media[1] == "webm" || current_media[1] == "mov" || current_media[1] == "avi" || current_media[1] == "mp4") {
|
else if (current_media[1] == "webm" || current_media[1] == "mov" || current_media[1] == "avi" || current_media[1] == "mp4") {
|
||||||
//console.log(`Video: ${current_media[0]}.${current_media[1]}\n`)
|
console.log(`Video: ${current_media[0]}.${current_media[1]}\n`)
|
||||||
|
|
||||||
// generateNewVideoSizes(`${current_media[0]}`, `${current_media[1]}`, [2560, 1080, 720, 480])
|
generateNewVideoSizes(`${current_media[0]}`, `${current_media[1]}`, [2560, 1080, 720, 480])
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@euterpe.js/visualizer",
|
"name": "@euterpe.js/visualizer",
|
||||||
"version": "1.0.7",
|
"version": "1.0.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Music visualizer based on SVG and AudioContext",
|
"description": "Music visualizer based on SVG and AudioContext",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
|
|
Loading…
Reference in a new issue