diff --git a/config/webpack.common.js b/config/webpack.common.js index 62626079..ac0de97c 100644 --- a/config/webpack.common.js +++ b/config/webpack.common.js @@ -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]" } } ] diff --git a/js/index.js b/js/index.js index 9a99d577..a353dc2f 100644 --- a/js/index.js +++ b/js/index.js @@ -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); }); diff --git a/mp3/test.m3u b/mp3/test.m3u new file mode 100755 index 00000000..a0705248 --- /dev/null +++ b/mp3/test.m3u @@ -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 diff --git a/mp3/test/01 Ghosts I.mp3 b/mp3/test/01 Ghosts I.mp3 new file mode 100755 index 00000000..5f38f1d0 Binary files /dev/null and b/mp3/test/01 Ghosts I.mp3 differ diff --git a/mp3/test/02 Ghosts I.mp3 b/mp3/test/02 Ghosts I.mp3 new file mode 100755 index 00000000..a8b838a2 Binary files /dev/null and b/mp3/test/02 Ghosts I.mp3 differ diff --git a/mp3/test/03 Ghosts I.mp3 b/mp3/test/03 Ghosts I.mp3 new file mode 100755 index 00000000..89b56c98 Binary files /dev/null and b/mp3/test/03 Ghosts I.mp3 differ diff --git a/package.json b/package.json index 868fd435..81d6c807 100644 --- a/package.json +++ b/package.json @@ -139,5 +139,7 @@ ] }, "prettier": {}, - "dependencies": {} + "dependencies": { + "m3u-parser": "^1.0.3" + } } diff --git a/yarn.lock b/yarn.lock index 5837e935..1628410b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"