Sketch out m3u support

This commit is contained in:
Jordan Eldredge 2018-10-24 22:41:41 -07:00
parent 6f43b4b8b3
commit 82f2b7a0b6
8 changed files with 44 additions and 3 deletions

View file

@ -24,13 +24,13 @@ module.exports = {
}
},
{
test: /\.(wsz|mp3|png|ico|jpg|svg)$/,
test: /\.(wsz|mp3|png|ico|jpg|svg|m3u)$/,
use: [
{
loader: "file-loader",
options: {
emitFile: true,
name: "[path][name]-[hash].[ext]"
name: "[path][name].[ext]"
}
}
]

View file

@ -3,6 +3,7 @@
import Raven from "raven-js";
import createMiddleware from "raven-for-redux";
import isButterchurnSupported from "butterchurn/lib/isSupported.min";
import { parse } from "m3u-parser";
import osx from "../skins/MacOSXAqua1-5.wsz";
import topaz from "../skins/TopazAmp1-2.wsz";
import visor from "../skins/Vizor1-01.wsz";
@ -10,6 +11,10 @@ import xmms from "../skins/XMMS-Turquoise.wsz";
import zaxon from "../skins/ZaxonRemake1-0.wsz";
import green from "../skins/Green-Dimension-V2.wsz";
import base from "../skins/base-2.91-png.wsz";
import m3u from "../mp3/test.m3u";
import "../mp3/test/01 Ghosts I.mp3";
import "../mp3/test/02 Ghosts I.mp3";
import "../mp3/test/03 Ghosts I.mp3";
import internetArchive from "../skins/Internet-Archive.wsz";
import MilkdropWindow from "./components/MilkdropWindow";
import screenshotInitialState from "./screenshotInitialState";
@ -291,4 +296,21 @@ Raven.context(async () => {
await bindToIndexedDB(webamp, clearState, useState);
await webamp.renderWhenReady(document.getElementById("app"));
function getParentDirectory(url) {
const r = /[^\/]*$/;
return url.replace(r, ""); // '/this/is/a/folder/'
}
const parentDirectory = getParentDirectory(m3u);
const resonse = await fetch(m3u);
const text = await resonse.text();
const playlist = await parse(text);
const m3uTracks = playlist.map(m3uTrack => ({
url: `${parentDirectory}${m3uTrack.file}`,
duration: m3uTrack.duration,
defaultName: m3uTrack.title
}));
webamp.setTracksToPlay(m3uTracks);
});

7
mp3/test.m3u Executable file
View file

@ -0,0 +1,7 @@
#EXTM3U
#EXTINF:168,01 Ghosts I.mp3
test/01%20Ghosts%20I.mp3
#EXTINF:196,02 Ghosts I.mp3
test/02%20Ghosts%20I.mp3
#EXTINF:230,03 Ghosts I.mp3
test/03%20Ghosts%20I.mp3

BIN
mp3/test/01 Ghosts I.mp3 Executable file

Binary file not shown.

BIN
mp3/test/02 Ghosts I.mp3 Executable file

Binary file not shown.

BIN
mp3/test/03 Ghosts I.mp3 Executable file

Binary file not shown.

View file

@ -139,5 +139,7 @@
]
},
"prettier": {},
"dependencies": {}
"dependencies": {
"m3u-parser": "^1.0.3"
}
}

View file

@ -1376,6 +1376,10 @@ block-stream@*:
dependencies:
inherits "~2.0.0"
bluebird@^3.1.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.2.tgz#1be0908e054a751754549c270489c1505d4ab15a"
bluebird@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
@ -5492,6 +5496,12 @@ lru-cache@^4.1.1:
pseudomap "^1.0.2"
yallist "^2.1.2"
m3u-parser@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/m3u-parser/-/m3u-parser-1.0.3.tgz#220fbdd5e54ccda7c230fcb09b59fd5ab4ba06a3"
dependencies:
bluebird "^3.1.1"
macaddress@^0.2.8:
version "0.2.8"
resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"