Commit 39b086d8 authored by Michael Murtaugh's avatar Michael Murtaugh

many

parent d579b6d4
......@@ -8,3 +8,4 @@ dist/feedplayer.js: src/feedplayer.js src/*.js
upload: dist/directory.js dist/directory.css
cp dist/directory.js dist/directory.css ~/mnt/1/public_html/lib/directory/
cp dist/directory.js dist/directory.css /var/www/html/lib/directory/
cp cgi-bin/*.cgi /usr/lib/cgi-bin
var d3 = require("d3-selection");
function $button (parent, textContent) {
var ret = document.createElement("button");
ret.textContent = textContent;
parent.appendChild(ret);
return ret;
}
function controller () {
var div = document.createElement("div"),
playbutton = document.createElement("button"),
nextbutton = document.createElement("button"),
prevbutton = document.createElement("button"),
var elt = document.createElement("div"),
playbutton = $button(elt, "play"),
// nextbutton = document.createElement("button"),
// prevbutton = document.createElement("button"),
timeslider = document.createElement("input"),
source = document.createElement("select"),
login = document.createElement("button");
// login = document.createElement("button"),
audio = document.createElement("audio"),
editing = document.createElement("span"),
format = $button(editing, "upload format"),
cover = $button(editing, "upload cover"),
ret = {},
dragging = false,
playAfterDrag = false;
playbutton.textContent = "play";
prevbutton.textContent = "prev";
nextbutton.textContent = "next";
timeslider.setAttribute("type", "range");
login.textContent = "login";
ret.elt = elt;
div.appendChild(playbutton);
div.appendChild(prevbutton);
div.appendChild(nextbutton);
div.appendChild(timeslider);
div.appendChild(source);
div.appendChild(login);
audio.addEventListener("play", x => {
playbutton.textContent = "pause";
});
audio.addEventListener("pause", x => {
playbutton.textContent = "play";
});
audio.addEventListener("timeupdate", x => {
if (dragging) { return; }
if (audio.duration) {
var curval = (audio.currentTime / audio.duration) * 10000;
timeslider.value = curval;
}
});
audio.addEventListener("ended", x=> {
console.log("audio.ended");
var next = d3.select("tr.file.playing + tr.file");
console.log("next");
if (next) {
play.call(next.node(), next.datum());
}
})
timeslider.setAttribute("min", 0);
timeslider.setAttribute("max", 10000);
timeslider.setAttribute("step", 1);
timeslider.addEventListener("mousedown", x=> {
dragging = true;
if (!audio.paused) {
audio.pause();
playAfterDrag = true;
} else {
playAfterDrag = false;
}
});
login.addEventListener("click", x=> {
loadscript.loadscript("/cgi-bin/aa/droptoupload.cgi?javascript").then(x=> {
console.log("loaded droptoupload");
});
timeslider.addEventListener("mouseup", x=> {
if (dragging) {
// console.log("stop dragging");
dragging = false;
if (audio.duration) {
var curtime = (timeslider.value / 10000) * audio.duration;
audio.currentTime = curtime;
if (playAfterDrag) {
audio.play();
}
}
}
});
playbutton.addEventListener("click", x=> {
if (audio.paused) {
audio.play();
} else {
audio.pause();
}
});
document.body.appendChild(div);
div.classList.add("aacontroller");
timeslider.setAttribute("type", "range");
elt.appendChild(playbutton);
//div.appendChild(prevbutton);
//div.appendChild(nextbutton);
elt.appendChild(timeslider);
//div.appendChild(source);
//div.appendChild(login);
editing.classList.add("editing");
elt.appendChild(editing);
// login.addEventListener("click", x=> {
// loadscript.loadscript("/cgi-bin/aa/droptoupload.cgi?javascript").then(x=> {
// console.log("loaded droptoupload");
// });
// });
document.body.appendChild(elt);
elt.classList.add("aacontroller");
// console.log("controller", div);
return div;
function play (d) {
console.log("play", this, d);
d3.selectAll(".playing").classed("playing", false);
d3.select(this).classed("playing", true);
if (d.type == "audio") {
play_audio.call(this, d);
}
}
ret.play = play;
function play_audio (d) {
audio.src = d.url;
audio.play();
}
ret.play_audio = play_audio;
return ret;
}
module.exports = controller;
var d3 = require("d3-selection"),
loadscript = require("./loadscript.js"),
droptoupload = require("./droptoupload.js"),
controller = require("./controller.js"),
make_controller = require("./controller.js"),
cookie = require("./cookie.js");
// polyfills
require("./trim.js");
function player (parent, data) {}
var controller;
/* Binds initial data items to each tr in the table with url == a[href] */
function init_table_data() {
var tr = d3.selectAll("table tbody tr");
tr = tr.filter( (d, i) => (i>=3 && i < tr.size()-1) );
tr.attr("class", "file");
var data = tr.nodes().map(x => ({
'url' : x.querySelector("td:nth-child(2) a[href]").getAttribute("href"),
'last-modified': x.querySelector("td:nth-child(3)").textContent.trim(),
......@@ -22,6 +24,20 @@ function init_table_data() {
console.log("init_table_data", data);
}
function set_default_data (selection) {
var files = d3.selectAll("table tbody tr.file");
files.each (d => {
var lurl = d.url.toLowerCase();
if (! d.type ) {
if (lurl.endsWith(".mp3") || lurl.endsWith(".ogg") || lurl.endsWith(".wav")) {
d.type = "audio";
} else if (lurl.endsWith("/")) {
d.type = "folder";
}
}
})
}
async function read_metadata(json_url) {
function get_thumb_url (d) {
if (!d.links) return;
......@@ -66,19 +82,35 @@ async function read_metadata(json_url) {
}
}
function activate_table () {
var tr = d3.selectAll("tr.file");
tr.on("click", function (d) {
if (d.type != "folder") {
d3.event.preventDefault();
controller.play.call(this, d);
}
});
}
async function init () {
var aa_auth = cookie.get("aa_auth");
console.log("aa_auth", aa_auth, aa_auth=="true");
controller()
controller = make_controller();
// linkplayer({ selection: "a" });
// Initialize data, prepare for join
init_table_data();
set_default_data();
var files = d3.selectAll("table tbody tr.file");
var data = files.data();
console.log("enriched data", data);
// read + join with stored metadata
var data = await read_metadata(".aa/index.json");
data = await read_metadata(".aa/index.json");
if (!data) {
console.log("no data, writing init_table_data to .aa/index.json");
console.log("no data: TODO write init_table_data to .aa/index.json");
}
activate_table();
//loadscript.loadscript("/lib/directory/video.js").then(x => {
// console.log("loaded video.js", videojs);
//});
......
......@@ -3,3 +3,11 @@ if (!String.prototype.trim) {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment