sorry for doing this.
This commit is contained in:
parent
5fc82a8bc7
commit
b3db294485
106 changed files with 86 additions and 259 deletions
872
oldshit/resources/lyrics/Vibrant.js
Normal file
872
oldshit/resources/lyrics/Vibrant.js
Normal file
|
@ -0,0 +1,872 @@
|
|||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
/*
|
||||
* quantize.js Copyright 2008 Nick Rabinowitz
|
||||
* Ported to node.js by Olivier Lesnicki
|
||||
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
// fill out a couple protovis dependencies
|
||||
/*
|
||||
* Block below copied from Protovis: http://mbostock.github.com/protovis/
|
||||
* Copyright 2010 Stanford Visualization Group
|
||||
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
||||
*/
|
||||
if (!pv) {
|
||||
var pv = {
|
||||
map: function(array, f) {
|
||||
var o = {};
|
||||
return f ? array.map(function(d, i) {
|
||||
o.index = i;
|
||||
return f.call(o, d);
|
||||
}) : array.slice();
|
||||
},
|
||||
naturalOrder: function(a, b) {
|
||||
return (a < b) ? -1 : ((a > b) ? 1 : 0);
|
||||
},
|
||||
sum: function(array, f) {
|
||||
var o = {};
|
||||
return array.reduce(f ? function(p, d, i) {
|
||||
o.index = i;
|
||||
return p + f.call(o, d);
|
||||
} : function(p, d) {
|
||||
return p + d;
|
||||
}, 0);
|
||||
},
|
||||
max: function(array, f) {
|
||||
return Math.max.apply(null, f ? pv.map(array, f) : array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Javascript port of the MMCQ (modified median cut quantization)
|
||||
* algorithm from the Leptonica library (http://www.leptonica.com/).
|
||||
* Returns a color map you can use to map original pixels to the reduced
|
||||
* palette. Still a work in progress.
|
||||
*
|
||||
* @author Nick Rabinowitz
|
||||
* @example
|
||||
|
||||
// array of pixels as [R,G,B] arrays
|
||||
var myPixels = [[190,197,190], [202,204,200], [207,214,210], [211,214,211], [205,207,207]
|
||||
// etc
|
||||
];
|
||||
var maxColors = 4;
|
||||
|
||||
var cmap = MMCQ.quantize(myPixels, maxColors);
|
||||
var newPalette = cmap.palette();
|
||||
var newPixels = myPixels.map(function(p) {
|
||||
return cmap.map(p);
|
||||
});
|
||||
|
||||
*/
|
||||
var MMCQ = (function() {
|
||||
// private constants
|
||||
var sigbits = 5,
|
||||
rshift = 8 - sigbits,
|
||||
maxIterations = 1000,
|
||||
fractByPopulations = 0.75;
|
||||
|
||||
// get reduced-space color index for a pixel
|
||||
|
||||
function getColorIndex(r, g, b) {
|
||||
return (r << (2 * sigbits)) + (g << sigbits) + b;
|
||||
}
|
||||
|
||||
// Simple priority queue
|
||||
|
||||
function PQueue(comparator) {
|
||||
var contents = [],
|
||||
sorted = false;
|
||||
|
||||
function sort() {
|
||||
contents.sort(comparator);
|
||||
sorted = true;
|
||||
}
|
||||
|
||||
return {
|
||||
push: function(o) {
|
||||
contents.push(o);
|
||||
sorted = false;
|
||||
},
|
||||
peek: function(index) {
|
||||
if (!sorted) sort();
|
||||
if (index === undefined) index = contents.length - 1;
|
||||
return contents[index];
|
||||
},
|
||||
pop: function() {
|
||||
if (!sorted) sort();
|
||||
return contents.pop();
|
||||
},
|
||||
size: function() {
|
||||
return contents.length;
|
||||
},
|
||||
map: function(f) {
|
||||
return contents.map(f);
|
||||
},
|
||||
debug: function() {
|
||||
if (!sorted) sort();
|
||||
return contents;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 3d color space box
|
||||
|
||||
function VBox(r1, r2, g1, g2, b1, b2, histo) {
|
||||
var vbox = this;
|
||||
vbox.r1 = r1;
|
||||
vbox.r2 = r2;
|
||||
vbox.g1 = g1;
|
||||
vbox.g2 = g2;
|
||||
vbox.b1 = b1;
|
||||
vbox.b2 = b2;
|
||||
vbox.histo = histo;
|
||||
}
|
||||
VBox.prototype = {
|
||||
volume: function(force) {
|
||||
var vbox = this;
|
||||
if (!vbox._volume || force) {
|
||||
vbox._volume = ((vbox.r2 - vbox.r1 + 1) * (vbox.g2 - vbox.g1 + 1) * (vbox.b2 - vbox.b1 + 1));
|
||||
}
|
||||
return vbox._volume;
|
||||
},
|
||||
count: function(force) {
|
||||
var vbox = this,
|
||||
histo = vbox.histo;
|
||||
if (!vbox._count_set || force) {
|
||||
var npix = 0,
|
||||
i, j, k;
|
||||
for (i = vbox.r1; i <= vbox.r2; i++) {
|
||||
for (j = vbox.g1; j <= vbox.g2; j++) {
|
||||
for (k = vbox.b1; k <= vbox.b2; k++) {
|
||||
index = getColorIndex(i, j, k);
|
||||
npix += (histo[index] || 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
vbox._count = npix;
|
||||
vbox._count_set = true;
|
||||
}
|
||||
return vbox._count;
|
||||
},
|
||||
copy: function() {
|
||||
var vbox = this;
|
||||
return new VBox(vbox.r1, vbox.r2, vbox.g1, vbox.g2, vbox.b1, vbox.b2, vbox.histo);
|
||||
},
|
||||
avg: function(force) {
|
||||
var vbox = this,
|
||||
histo = vbox.histo;
|
||||
if (!vbox._avg || force) {
|
||||
var ntot = 0,
|
||||
mult = 1 << (8 - sigbits),
|
||||
rsum = 0,
|
||||
gsum = 0,
|
||||
bsum = 0,
|
||||
hval,
|
||||
i, j, k, histoindex;
|
||||
for (i = vbox.r1; i <= vbox.r2; i++) {
|
||||
for (j = vbox.g1; j <= vbox.g2; j++) {
|
||||
for (k = vbox.b1; k <= vbox.b2; k++) {
|
||||
histoindex = getColorIndex(i, j, k);
|
||||
hval = histo[histoindex] || 0;
|
||||
ntot += hval;
|
||||
rsum += (hval * (i + 0.5) * mult);
|
||||
gsum += (hval * (j + 0.5) * mult);
|
||||
bsum += (hval * (k + 0.5) * mult);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ntot) {
|
||||
vbox._avg = [~~(rsum / ntot), ~~ (gsum / ntot), ~~ (bsum / ntot)];
|
||||
} else {
|
||||
//console.log('empty box');
|
||||
vbox._avg = [~~(mult * (vbox.r1 + vbox.r2 + 1) / 2), ~~ (mult * (vbox.g1 + vbox.g2 + 1) / 2), ~~ (mult * (vbox.b1 + vbox.b2 + 1) / 2)];
|
||||
}
|
||||
}
|
||||
return vbox._avg;
|
||||
},
|
||||
contains: function(pixel) {
|
||||
var vbox = this,
|
||||
rval = pixel[0] >> rshift;
|
||||
gval = pixel[1] >> rshift;
|
||||
bval = pixel[2] >> rshift;
|
||||
return (rval >= vbox.r1 && rval <= vbox.r2 &&
|
||||
gval >= vbox.g1 && gval <= vbox.g2 &&
|
||||
bval >= vbox.b1 && bval <= vbox.b2);
|
||||
}
|
||||
};
|
||||
|
||||
// Color map
|
||||
|
||||
function CMap() {
|
||||
this.vboxes = new PQueue(function(a, b) {
|
||||
return pv.naturalOrder(
|
||||
a.vbox.count() * a.vbox.volume(),
|
||||
b.vbox.count() * b.vbox.volume()
|
||||
)
|
||||
});;
|
||||
}
|
||||
CMap.prototype = {
|
||||
push: function(vbox) {
|
||||
this.vboxes.push({
|
||||
vbox: vbox,
|
||||
color: vbox.avg()
|
||||
});
|
||||
},
|
||||
palette: function() {
|
||||
return this.vboxes.map(function(vb) {
|
||||
return vb.color
|
||||
});
|
||||
},
|
||||
size: function() {
|
||||
return this.vboxes.size();
|
||||
},
|
||||
map: function(color) {
|
||||
var vboxes = this.vboxes;
|
||||
for (var i = 0; i < vboxes.size(); i++) {
|
||||
if (vboxes.peek(i).vbox.contains(color)) {
|
||||
return vboxes.peek(i).color;
|
||||
}
|
||||
}
|
||||
return this.nearest(color);
|
||||
},
|
||||
nearest: function(color) {
|
||||
var vboxes = this.vboxes,
|
||||
d1, d2, pColor;
|
||||
for (var i = 0; i < vboxes.size(); i++) {
|
||||
d2 = Math.sqrt(
|
||||
Math.pow(color[0] - vboxes.peek(i).color[0], 2) +
|
||||
Math.pow(color[1] - vboxes.peek(i).color[1], 2) +
|
||||
Math.pow(color[2] - vboxes.peek(i).color[2], 2)
|
||||
);
|
||||
if (d2 < d1 || d1 === undefined) {
|
||||
d1 = d2;
|
||||
pColor = vboxes.peek(i).color;
|
||||
}
|
||||
}
|
||||
return pColor;
|
||||
},
|
||||
forcebw: function() {
|
||||
// XXX: won't work yet
|
||||
var vboxes = this.vboxes;
|
||||
vboxes.sort(function(a, b) {
|
||||
return pv.naturalOrder(pv.sum(a.color), pv.sum(b.color))
|
||||
});
|
||||
|
||||
// force darkest color to black if everything < 5
|
||||
var lowest = vboxes[0].color;
|
||||
if (lowest[0] < 5 && lowest[1] < 5 && lowest[2] < 5)
|
||||
vboxes[0].color = [0, 0, 0];
|
||||
|
||||
// force lightest color to white if everything > 251
|
||||
var idx = vboxes.length - 1,
|
||||
highest = vboxes[idx].color;
|
||||
if (highest[0] > 251 && highest[1] > 251 && highest[2] > 251)
|
||||
vboxes[idx].color = [255, 255, 255];
|
||||
}
|
||||
};
|
||||
|
||||
// histo (1-d array, giving the number of pixels in
|
||||
// each quantized region of color space), or null on error
|
||||
|
||||
function getHisto(pixels) {
|
||||
var histosize = 1 << (3 * sigbits),
|
||||
histo = new Array(histosize),
|
||||
index, rval, gval, bval;
|
||||
pixels.forEach(function(pixel) {
|
||||
rval = pixel[0] >> rshift;
|
||||
gval = pixel[1] >> rshift;
|
||||
bval = pixel[2] >> rshift;
|
||||
index = getColorIndex(rval, gval, bval);
|
||||
histo[index] = (histo[index] || 0) + 1;
|
||||
});
|
||||
return histo;
|
||||
}
|
||||
|
||||
function vboxFromPixels(pixels, histo) {
|
||||
var rmin = 1000000,
|
||||
rmax = 0,
|
||||
gmin = 1000000,
|
||||
gmax = 0,
|
||||
bmin = 1000000,
|
||||
bmax = 0,
|
||||
rval, gval, bval;
|
||||
// find min/max
|
||||
pixels.forEach(function(pixel) {
|
||||
rval = pixel[0] >> rshift;
|
||||
gval = pixel[1] >> rshift;
|
||||
bval = pixel[2] >> rshift;
|
||||
if (rval < rmin) rmin = rval;
|
||||
else if (rval > rmax) rmax = rval;
|
||||
if (gval < gmin) gmin = gval;
|
||||
else if (gval > gmax) gmax = gval;
|
||||
if (bval < bmin) bmin = bval;
|
||||
else if (bval > bmax) bmax = bval;
|
||||
});
|
||||
return new VBox(rmin, rmax, gmin, gmax, bmin, bmax, histo);
|
||||
}
|
||||
|
||||
function medianCutApply(histo, vbox) {
|
||||
if (!vbox.count()) return;
|
||||
|
||||
var rw = vbox.r2 - vbox.r1 + 1,
|
||||
gw = vbox.g2 - vbox.g1 + 1,
|
||||
bw = vbox.b2 - vbox.b1 + 1,
|
||||
maxw = pv.max([rw, gw, bw]);
|
||||
// only one pixel, no split
|
||||
if (vbox.count() == 1) {
|
||||
return [vbox.copy()]
|
||||
}
|
||||
/* Find the partial sum arrays along the selected axis. */
|
||||
var total = 0,
|
||||
partialsum = [],
|
||||
lookaheadsum = [],
|
||||
i, j, k, sum, index;
|
||||
if (maxw == rw) {
|
||||
for (i = vbox.r1; i <= vbox.r2; i++) {
|
||||
sum = 0;
|
||||
for (j = vbox.g1; j <= vbox.g2; j++) {
|
||||
for (k = vbox.b1; k <= vbox.b2; k++) {
|
||||
index = getColorIndex(i, j, k);
|
||||
sum += (histo[index] || 0);
|
||||
}
|
||||
}
|
||||
total += sum;
|
||||
partialsum[i] = total;
|
||||
}
|
||||
} else if (maxw == gw) {
|
||||
for (i = vbox.g1; i <= vbox.g2; i++) {
|
||||
sum = 0;
|
||||
for (j = vbox.r1; j <= vbox.r2; j++) {
|
||||
for (k = vbox.b1; k <= vbox.b2; k++) {
|
||||
index = getColorIndex(j, i, k);
|
||||
sum += (histo[index] || 0);
|
||||
}
|
||||
}
|
||||
total += sum;
|
||||
partialsum[i] = total;
|
||||
}
|
||||
} else { /* maxw == bw */
|
||||
for (i = vbox.b1; i <= vbox.b2; i++) {
|
||||
sum = 0;
|
||||
for (j = vbox.r1; j <= vbox.r2; j++) {
|
||||
for (k = vbox.g1; k <= vbox.g2; k++) {
|
||||
index = getColorIndex(j, k, i);
|
||||
sum += (histo[index] || 0);
|
||||
}
|
||||
}
|
||||
total += sum;
|
||||
partialsum[i] = total;
|
||||
}
|
||||
}
|
||||
partialsum.forEach(function(d, i) {
|
||||
lookaheadsum[i] = total - d
|
||||
});
|
||||
|
||||
function doCut(color) {
|
||||
var dim1 = color + '1',
|
||||
dim2 = color + '2',
|
||||
left, right, vbox1, vbox2, d2, count2 = 0;
|
||||
for (i = vbox[dim1]; i <= vbox[dim2]; i++) {
|
||||
if (partialsum[i] > total / 2) {
|
||||
vbox1 = vbox.copy();
|
||||
vbox2 = vbox.copy();
|
||||
left = i - vbox[dim1];
|
||||
right = vbox[dim2] - i;
|
||||
if (left <= right)
|
||||
d2 = Math.min(vbox[dim2] - 1, ~~ (i + right / 2));
|
||||
else d2 = Math.max(vbox[dim1], ~~ (i - 1 - left / 2));
|
||||
// avoid 0-count boxes
|
||||
while (!partialsum[d2]) d2++;
|
||||
count2 = lookaheadsum[d2];
|
||||
while (!count2 && partialsum[d2 - 1]) count2 = lookaheadsum[--d2];
|
||||
// set dimensions
|
||||
vbox1[dim2] = d2;
|
||||
vbox2[dim1] = vbox1[dim2] + 1;
|
||||
// console.log('vbox counts:', vbox.count(), vbox1.count(), vbox2.count());
|
||||
return [vbox1, vbox2];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// determine the cut planes
|
||||
return maxw == rw ? doCut('r') :
|
||||
maxw == gw ? doCut('g') :
|
||||
doCut('b');
|
||||
}
|
||||
|
||||
function quantize(pixels, maxcolors) {
|
||||
// short-circuit
|
||||
if (!pixels.length || maxcolors < 2 || maxcolors > 256) {
|
||||
// console.log('wrong number of maxcolors');
|
||||
return false;
|
||||
}
|
||||
|
||||
// XXX: check color content and convert to grayscale if insufficient
|
||||
|
||||
var histo = getHisto(pixels),
|
||||
histosize = 1 << (3 * sigbits);
|
||||
|
||||
// check that we aren't below maxcolors already
|
||||
var nColors = 0;
|
||||
histo.forEach(function() {
|
||||
nColors++
|
||||
});
|
||||
if (nColors <= maxcolors) {
|
||||
// XXX: generate the new colors from the histo and return
|
||||
}
|
||||
|
||||
// get the beginning vbox from the colors
|
||||
var vbox = vboxFromPixels(pixels, histo),
|
||||
pq = new PQueue(function(a, b) {
|
||||
return pv.naturalOrder(a.count(), b.count())
|
||||
});
|
||||
pq.push(vbox);
|
||||
|
||||
// inner function to do the iteration
|
||||
|
||||
function iter(lh, target) {
|
||||
var ncolors = 1,
|
||||
niters = 0,
|
||||
vbox;
|
||||
while (niters < maxIterations) {
|
||||
vbox = lh.pop();
|
||||
if (!vbox.count()) { /* just put it back */
|
||||
lh.push(vbox);
|
||||
niters++;
|
||||
continue;
|
||||
}
|
||||
// do the cut
|
||||
var vboxes = medianCutApply(histo, vbox),
|
||||
vbox1 = vboxes[0],
|
||||
vbox2 = vboxes[1];
|
||||
|
||||
if (!vbox1) {
|
||||
// console.log("vbox1 not defined; shouldn't happen!");
|
||||
return;
|
||||
}
|
||||
lh.push(vbox1);
|
||||
if (vbox2) { /* vbox2 can be null */
|
||||
lh.push(vbox2);
|
||||
ncolors++;
|
||||
}
|
||||
if (ncolors >= target) return;
|
||||
if (niters++ > maxIterations) {
|
||||
// console.log("infinite loop; perhaps too few pixels!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// first set of colors, sorted by population
|
||||
iter(pq, fractByPopulations * maxcolors);
|
||||
// console.log(pq.size(), pq.debug().length, pq.debug().slice());
|
||||
|
||||
// Re-sort by the product of pixel occupancy times the size in color space.
|
||||
var pq2 = new PQueue(function(a, b) {
|
||||
return pv.naturalOrder(a.count() * a.volume(), b.count() * b.volume())
|
||||
});
|
||||
while (pq.size()) {
|
||||
pq2.push(pq.pop());
|
||||
}
|
||||
|
||||
// next set - generate the median cuts using the (npix * vol) sorting.
|
||||
iter(pq2, maxcolors - pq2.size());
|
||||
|
||||
// calculate the actual colors
|
||||
var cmap = new CMap();
|
||||
while (pq2.size()) {
|
||||
cmap.push(pq2.pop());
|
||||
}
|
||||
|
||||
return cmap;
|
||||
}
|
||||
|
||||
return {
|
||||
quantize: quantize
|
||||
}
|
||||
})();
|
||||
|
||||
module.exports = MMCQ.quantize
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
|
||||
/*
|
||||
Vibrant.js
|
||||
by Jari Zwarts
|
||||
|
||||
Color algorithm class that finds variations on colors in an image.
|
||||
|
||||
Credits
|
||||
--------
|
||||
Lokesh Dhakar (http://www.lokeshdhakar.com) - Created ColorThief
|
||||
Google - Palette support library in Android
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var CanvasImage, Swatch, Vibrant,
|
||||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
slice = [].slice;
|
||||
|
||||
window.Swatch = Swatch = (function() {
|
||||
Swatch.prototype.hsl = void 0;
|
||||
|
||||
Swatch.prototype.rgb = void 0;
|
||||
|
||||
Swatch.prototype.population = 1;
|
||||
|
||||
Swatch.yiq = 0;
|
||||
|
||||
function Swatch(rgb, population) {
|
||||
this.rgb = rgb;
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
Swatch.prototype.getHsl = function() {
|
||||
if (!this.hsl) {
|
||||
return this.hsl = Vibrant.rgbToHsl(this.rgb[0], this.rgb[1], this.rgb[2]);
|
||||
} else {
|
||||
return this.hsl;
|
||||
}
|
||||
};
|
||||
|
||||
Swatch.prototype.getPopulation = function() {
|
||||
return this.population;
|
||||
};
|
||||
|
||||
Swatch.prototype.getRgb = function() {
|
||||
return this.rgb;
|
||||
};
|
||||
|
||||
Swatch.prototype.getHex = function() {
|
||||
return "#" + ((1 << 24) + (this.rgb[0] << 16) + (this.rgb[1] << 8) + this.rgb[2]).toString(16).slice(1, 7);
|
||||
};
|
||||
|
||||
Swatch.prototype.getTitleTextColor = function() {
|
||||
this._ensureTextColors();
|
||||
if (this.yiq < 200) {
|
||||
return "#fff";
|
||||
} else {
|
||||
return "#000";
|
||||
}
|
||||
};
|
||||
|
||||
Swatch.prototype.getBodyTextColor = function() {
|
||||
this._ensureTextColors();
|
||||
if (this.yiq < 150) {
|
||||
return "#fff";
|
||||
} else {
|
||||
return "#000";
|
||||
}
|
||||
};
|
||||
|
||||
Swatch.prototype._ensureTextColors = function() {
|
||||
if (!this.yiq) {
|
||||
return this.yiq = (this.rgb[0] * 299 + this.rgb[1] * 587 + this.rgb[2] * 114) / 1000;
|
||||
}
|
||||
};
|
||||
|
||||
return Swatch;
|
||||
|
||||
})();
|
||||
|
||||
window.Vibrant = Vibrant = (function() {
|
||||
Vibrant.prototype.quantize = require('quantize');
|
||||
|
||||
Vibrant.prototype._swatches = [];
|
||||
|
||||
Vibrant.prototype.TARGET_DARK_LUMA = 0.26;
|
||||
|
||||
Vibrant.prototype.MAX_DARK_LUMA = 0.45;
|
||||
|
||||
Vibrant.prototype.MIN_LIGHT_LUMA = 0.55;
|
||||
|
||||
Vibrant.prototype.TARGET_LIGHT_LUMA = 0.74;
|
||||
|
||||
Vibrant.prototype.MIN_NORMAL_LUMA = 0.3;
|
||||
|
||||
Vibrant.prototype.TARGET_NORMAL_LUMA = 0.5;
|
||||
|
||||
Vibrant.prototype.MAX_NORMAL_LUMA = 0.7;
|
||||
|
||||
Vibrant.prototype.TARGET_MUTED_SATURATION = 0.3;
|
||||
|
||||
Vibrant.prototype.MAX_MUTED_SATURATION = 0.4;
|
||||
|
||||
Vibrant.prototype.TARGET_VIBRANT_SATURATION = 1;
|
||||
|
||||
Vibrant.prototype.MIN_VIBRANT_SATURATION = 0.35;
|
||||
|
||||
Vibrant.prototype.WEIGHT_SATURATION = 3;
|
||||
|
||||
Vibrant.prototype.WEIGHT_LUMA = 6;
|
||||
|
||||
Vibrant.prototype.WEIGHT_POPULATION = 1;
|
||||
|
||||
Vibrant.prototype.VibrantSwatch = void 0;
|
||||
|
||||
Vibrant.prototype.MutedSwatch = void 0;
|
||||
|
||||
Vibrant.prototype.DarkVibrantSwatch = void 0;
|
||||
|
||||
Vibrant.prototype.DarkMutedSwatch = void 0;
|
||||
|
||||
Vibrant.prototype.LightVibrantSwatch = void 0;
|
||||
|
||||
Vibrant.prototype.LightMutedSwatch = void 0;
|
||||
|
||||
Vibrant.prototype.HighestPopulation = 0;
|
||||
|
||||
function Vibrant(sourceImage, colorCount, quality) {
|
||||
this.swatches = bind(this.swatches, this);
|
||||
var a, allPixels, b, cmap, g, i, image, imageData, offset, pixelCount, pixels, r;
|
||||
if (typeof colorCount === 'undefined') {
|
||||
colorCount = 64;
|
||||
}
|
||||
if (typeof quality === 'undefined') {
|
||||
quality = 5;
|
||||
}
|
||||
image = new CanvasImage(sourceImage);
|
||||
imageData = image.getImageData();
|
||||
pixels = imageData.data;
|
||||
pixelCount = image.getPixelCount();
|
||||
allPixels = [];
|
||||
i = 0;
|
||||
while (i < pixelCount) {
|
||||
offset = i * 4;
|
||||
r = pixels[offset + 0];
|
||||
g = pixels[offset + 1];
|
||||
b = pixels[offset + 2];
|
||||
a = pixels[offset + 3];
|
||||
if (a >= 125) {
|
||||
if (!(r > 250 && g > 250 && b > 250)) {
|
||||
allPixels.push([r, g, b]);
|
||||
}
|
||||
}
|
||||
i = i + quality;
|
||||
}
|
||||
cmap = this.quantize(allPixels, colorCount);
|
||||
this._swatches = cmap.vboxes.map((function(_this) {
|
||||
return function(vbox) {
|
||||
return new Swatch(vbox.color, vbox.vbox.count());
|
||||
};
|
||||
})(this));
|
||||
this.maxPopulation = this.findMaxPopulation;
|
||||
this.generateVarationColors();
|
||||
this.generateEmptySwatches();
|
||||
image.removeCanvas();
|
||||
}
|
||||
|
||||
Vibrant.prototype.generateVarationColors = function() {
|
||||
this.VibrantSwatch = this.findColorVariation(this.TARGET_NORMAL_LUMA, this.MIN_NORMAL_LUMA, this.MAX_NORMAL_LUMA, this.TARGET_VIBRANT_SATURATION, this.MIN_VIBRANT_SATURATION, 1);
|
||||
this.LightVibrantSwatch = this.findColorVariation(this.TARGET_LIGHT_LUMA, this.MIN_LIGHT_LUMA, 1, this.TARGET_VIBRANT_SATURATION, this.MIN_VIBRANT_SATURATION, 1);
|
||||
this.DarkVibrantSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_VIBRANT_SATURATION, this.MIN_VIBRANT_SATURATION, 1);
|
||||
this.MutedSwatch = this.findColorVariation(this.TARGET_NORMAL_LUMA, this.MIN_NORMAL_LUMA, this.MAX_NORMAL_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||
this.LightMutedSwatch = this.findColorVariation(this.TARGET_LIGHT_LUMA, this.MIN_LIGHT_LUMA, 1, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||
return this.DarkMutedSwatch = this.findColorVariation(this.TARGET_DARK_LUMA, 0, this.MAX_DARK_LUMA, this.TARGET_MUTED_SATURATION, 0, this.MAX_MUTED_SATURATION);
|
||||
};
|
||||
|
||||
Vibrant.prototype.generateEmptySwatches = function() {
|
||||
var hsl;
|
||||
if (this.VibrantSwatch === void 0) {
|
||||
if (this.DarkVibrantSwatch !== void 0) {
|
||||
hsl = this.DarkVibrantSwatch.getHsl();
|
||||
hsl[2] = this.TARGET_NORMAL_LUMA;
|
||||
this.VibrantSwatch = new Swatch(Vibrant.hslToRgb(hsl[0], hsl[1], hsl[2]), 0);
|
||||
}
|
||||
}
|
||||
if (this.DarkVibrantSwatch === void 0) {
|
||||
if (this.VibrantSwatch !== void 0) {
|
||||
hsl = this.VibrantSwatch.getHsl();
|
||||
hsl[2] = this.TARGET_DARK_LUMA;
|
||||
return this.DarkVibrantSwatch = new Swatch(Vibrant.hslToRgb(hsl[0], hsl[1], hsl[2]), 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Vibrant.prototype.findMaxPopulation = function() {
|
||||
var j, len, population, ref, swatch;
|
||||
population = 0;
|
||||
ref = this._swatches;
|
||||
for (j = 0, len = ref.length; j < len; j++) {
|
||||
swatch = ref[j];
|
||||
population = Math.max(population, swatch.getPopulation());
|
||||
}
|
||||
return population;
|
||||
};
|
||||
|
||||
Vibrant.prototype.findColorVariation = function(targetLuma, minLuma, maxLuma, targetSaturation, minSaturation, maxSaturation) {
|
||||
var j, len, luma, max, maxValue, ref, sat, swatch, value;
|
||||
max = void 0;
|
||||
maxValue = 0;
|
||||
ref = this._swatches;
|
||||
for (j = 0, len = ref.length; j < len; j++) {
|
||||
swatch = ref[j];
|
||||
sat = swatch.getHsl()[1];
|
||||
luma = swatch.getHsl()[2];
|
||||
if (sat >= minSaturation && sat <= maxSaturation && luma >= minLuma && luma <= maxLuma && !this.isAlreadySelected(swatch)) {
|
||||
value = this.createComparisonValue(sat, targetSaturation, luma, targetLuma, swatch.getPopulation(), this.HighestPopulation);
|
||||
if (max === void 0 || value > maxValue) {
|
||||
max = swatch;
|
||||
maxValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return max;
|
||||
};
|
||||
|
||||
Vibrant.prototype.createComparisonValue = function(saturation, targetSaturation, luma, targetLuma, population, maxPopulation) {
|
||||
return this.weightedMean(this.invertDiff(saturation, targetSaturation), this.WEIGHT_SATURATION, this.invertDiff(luma, targetLuma), this.WEIGHT_LUMA, population / maxPopulation, this.WEIGHT_POPULATION);
|
||||
};
|
||||
|
||||
Vibrant.prototype.invertDiff = function(value, targetValue) {
|
||||
return 1 - Math.abs(value - targetValue);
|
||||
};
|
||||
|
||||
Vibrant.prototype.weightedMean = function() {
|
||||
var i, sum, sumWeight, value, values, weight;
|
||||
values = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
sum = 0;
|
||||
sumWeight = 0;
|
||||
i = 0;
|
||||
while (i < values.length) {
|
||||
value = values[i];
|
||||
weight = values[i + 1];
|
||||
sum += value * weight;
|
||||
sumWeight += weight;
|
||||
i += 2;
|
||||
}
|
||||
return sum / sumWeight;
|
||||
};
|
||||
|
||||
Vibrant.prototype.swatches = function() {
|
||||
return {
|
||||
Vibrant: this.VibrantSwatch,
|
||||
Muted: this.MutedSwatch,
|
||||
DarkVibrant: this.DarkVibrantSwatch,
|
||||
DarkMuted: this.DarkMutedSwatch,
|
||||
LightVibrant: this.LightVibrantSwatch,
|
||||
LightMuted: this.LightMuted
|
||||
};
|
||||
};
|
||||
|
||||
Vibrant.prototype.isAlreadySelected = function(swatch) {
|
||||
return this.VibrantSwatch === swatch || this.DarkVibrantSwatch === swatch || this.LightVibrantSwatch === swatch || this.MutedSwatch === swatch || this.DarkMutedSwatch === swatch || this.LightMutedSwatch === swatch;
|
||||
};
|
||||
|
||||
Vibrant.rgbToHsl = function(r, g, b) {
|
||||
var d, h, l, max, min, s;
|
||||
r /= 255;
|
||||
g /= 255;
|
||||
b /= 255;
|
||||
max = Math.max(r, g, b);
|
||||
min = Math.min(r, g, b);
|
||||
h = void 0;
|
||||
s = void 0;
|
||||
l = (max + min) / 2;
|
||||
if (max === min) {
|
||||
h = s = 0;
|
||||
} else {
|
||||
d = max - min;
|
||||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||
switch (max) {
|
||||
case r:
|
||||
h = (g - b) / d + (g < b ? 6 : 0);
|
||||
break;
|
||||
case g:
|
||||
h = (b - r) / d + 2;
|
||||
break;
|
||||
case b:
|
||||
h = (r - g) / d + 4;
|
||||
}
|
||||
h /= 6;
|
||||
}
|
||||
return [h, s, l];
|
||||
};
|
||||
|
||||
Vibrant.hslToRgb = function(h, s, l) {
|
||||
var b, g, hue2rgb, p, q, r;
|
||||
r = void 0;
|
||||
g = void 0;
|
||||
b = void 0;
|
||||
hue2rgb = function(p, q, t) {
|
||||
if (t < 0) {
|
||||
t += 1;
|
||||
}
|
||||
if (t > 1) {
|
||||
t -= 1;
|
||||
}
|
||||
if (t < 1 / 6) {
|
||||
return p + (q - p) * 6 * t;
|
||||
}
|
||||
if (t < 1 / 2) {
|
||||
return q;
|
||||
}
|
||||
if (t < 2 / 3) {
|
||||
return p + (q - p) * (2 / 3 - t) * 6;
|
||||
}
|
||||
return p;
|
||||
};
|
||||
if (s === 0) {
|
||||
r = g = b = l;
|
||||
} else {
|
||||
q = l < 0.5 ? l * (1 + s) : l + s - (l * s);
|
||||
p = 2 * l - q;
|
||||
r = hue2rgb(p, q, h + 1 / 3);
|
||||
g = hue2rgb(p, q, h);
|
||||
b = hue2rgb(p, q, h - (1 / 3));
|
||||
}
|
||||
return [r * 255, g * 255, b * 255];
|
||||
};
|
||||
|
||||
return Vibrant;
|
||||
|
||||
})();
|
||||
|
||||
|
||||
/*
|
||||
CanvasImage Class
|
||||
Class that wraps the html image element and canvas.
|
||||
It also simplifies some of the canvas context manipulation
|
||||
with a set of helper functions.
|
||||
Stolen from https://github.com/lokesh/color-thief
|
||||
*/
|
||||
|
||||
window.CanvasImage = CanvasImage = (function() {
|
||||
function CanvasImage(image) {
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.context = this.canvas.getContext('2d');
|
||||
document.body.appendChild(this.canvas);
|
||||
this.width = this.canvas.width = image.width;
|
||||
this.height = this.canvas.height = image.height;
|
||||
this.context.drawImage(image, 0, 0, this.width, this.height);
|
||||
}
|
||||
|
||||
CanvasImage.prototype.clear = function() {
|
||||
return this.context.clearRect(0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.update = function(imageData) {
|
||||
return this.context.putImageData(imageData, 0, 0);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.getPixelCount = function() {
|
||||
return this.width * this.height;
|
||||
};
|
||||
|
||||
CanvasImage.prototype.getImageData = function() {
|
||||
return this.context.getImageData(0, 0, this.width, this.height);
|
||||
};
|
||||
|
||||
CanvasImage.prototype.removeCanvas = function() {
|
||||
return this.canvas.parentNode.removeChild(this.canvas);
|
||||
};
|
||||
|
||||
return CanvasImage;
|
||||
|
||||
})();
|
||||
|
||||
}).call(this);
|
||||
|
||||
},{"quantize":1}]},{},[2]);
|
90
oldshit/resources/lyrics/index.html
Normal file
90
oldshit/resources/lyrics/index.html
Normal file
|
@ -0,0 +1,90 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Lyrics</title>
|
||||
<script type="text/javascript" src="Vibrant.js"></script>
|
||||
<script type="text/javascript" src="../js/lyrics.js"></script>
|
||||
<link rel="stylesheet" href="../css/lyricer.css">
|
||||
<link rel="stylesheet" href="https://www.apple.com/wss/fonts?families=SF+Pro,v4|SF+Pro+Icons,v1&display=swap">
|
||||
<link href="https://fonts.googleapis.com/css?family=M+PLUS+1p" rel="stylesheet">
|
||||
</head>
|
||||
<body style="margin: 0;">
|
||||
<img style="" id="backgroundImage"></img>
|
||||
<div style="width: 100%; height: 100%; opacity: 0.8; z-index: 1; background-color: rgba(0, 0, 0, 0.5); position: absolute;"></div>
|
||||
<div id ='info' style="z-index: 2;">
|
||||
<img id="albumart"></img>
|
||||
<div id="title"></div>
|
||||
<div id="details"></div>
|
||||
</div>
|
||||
|
||||
<div id="lyricer">
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
function changeStylesheetRule(stylesheet, selector, property, value) {
|
||||
selector = selector.toLowerCase();
|
||||
property = property.toLowerCase();
|
||||
value = value.toLowerCase();
|
||||
|
||||
for(var i = 0; i < stylesheet.cssRules.length; i++) {
|
||||
var rule = stylesheet.cssRules[i];
|
||||
if(rule.selectorText === selector) {
|
||||
rule.style[property] = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
stylesheet.insertRule(selector + " { " + property + ": " + value + "; }", 0);
|
||||
}
|
||||
var w = window.innerWidth;
|
||||
var h = window.innerHeight;
|
||||
document.getElementById("title").style.top = Math.floor(0.1*h + 0.40*w)+'px'
|
||||
document.getElementById("details").style.top = Math.floor(0.1*h + 0.42*w)+'px'
|
||||
var text = "";
|
||||
var lrc = new Lyricer({focus:'start'});
|
||||
lrc.setFocus('start');
|
||||
ipcRenderer.on('truelyrics', function (event, lrcfile) {
|
||||
if (lrc != null && lrcfile!= null && lrcfile.length > 0)
|
||||
lrc.setLrc(lrcfile);
|
||||
|
||||
});
|
||||
ipcRenderer.on('albumart', function (event, data) {
|
||||
document.getElementById("albumart").setAttribute('src',`${data}`);
|
||||
document.getElementById("backgroundImage").setAttribute('src',`${data}`);
|
||||
document.getElementById("backgroundImage").onload = function() {
|
||||
var vibrant = new Vibrant(this,128,3);
|
||||
for (var swatch in swatches);
|
||||
var swatches = vibrant.swatches();
|
||||
if (swatches.hasOwnProperty(swatch) && swatches[swatch])
|
||||
console.log(swatch, swatches[swatch].getHex());
|
||||
var selectedswatch = (swatches['LightVibrant'] != null ) ? swatches['LightVibrant'] : swatches['Vibrant'];
|
||||
changeStylesheetRule(document.styleSheets[0],'#lyricer ul li','color',selectedswatch.getHex());
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
ipcRenderer.on('updateMiniPlayerMetaData', function (event, track, artist, album) {
|
||||
console.log('ugh');
|
||||
var w = window.innerWidth;
|
||||
var h = window.innerHeight;
|
||||
document.getElementById("title").style.top = Math.floor(0.1*h + 0.40*w)+'px'
|
||||
document.getElementById("details").style.top = Math.floor(0.1*h + 0.42*w)+'px'
|
||||
document.getElementById("title").textContent = track;
|
||||
document.getElementById("details").textContent = artist + " - " + album ;
|
||||
});
|
||||
|
||||
ipcRenderer.on('ProgressTimeUpdate', function (event, data) {
|
||||
if (data < 0){data = 0};
|
||||
lrc.move(data);
|
||||
});
|
||||
|
||||
lrc.setLrc(text);
|
||||
window.addEventListener("lyricerclick", function(e){
|
||||
ipcRenderer.send('ProgressTimeUpdateFromLyrics',e.detail.time);
|
||||
console.log('clicked on ' + e.detail.time);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
190
oldshit/resources/lyrics/musixmatch.html
Normal file
190
oldshit/resources/lyrics/musixmatch.html
Normal file
|
@ -0,0 +1,190 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Lyrics</title>
|
||||
<script type="text/javascript" src="../js/lyrics.js"></script>
|
||||
<link rel="stylesheet" href="../css/lyricer.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=M+PLUS+1p" rel="stylesheet">
|
||||
</head>
|
||||
<body style="margin: 0;">
|
||||
<img style="" id="backgroundImage" alt="Background Image"></img>
|
||||
<div style="width: 100%; height: 100%; opacity: 0.8; z-index: 1; background-color: rgba(0, 0, 0, 0.5); position: absolute;"></div>
|
||||
<div id="lyricer">
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
var text = "";
|
||||
var lrcfile = "";
|
||||
var lrc = new Lyricer();
|
||||
var prevartist = '';
|
||||
var prevtrack = '';
|
||||
var prevlyrics = ['','','','','']; //track, artist, songid, lyrics, translated lyrics
|
||||
var globaltoken = '';
|
||||
function revisedRandId() {
|
||||
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
|
||||
}
|
||||
/* get token */
|
||||
function getToken(mode, track, artist, songid, lang, time) {
|
||||
var url = "https://apic-desktop.musixmatch.com/ws/1.1/token.get?app_id=web-desktop-app-v1.0&t="+revisedRandId();
|
||||
var req = new XMLHttpRequest();
|
||||
req.overrideMimeType("application/json");
|
||||
req.open('GET', url, true);
|
||||
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
||||
req.onload = function() {
|
||||
var jsonResponse = JSON.parse(this.responseText);
|
||||
var status2 = jsonResponse["message"]["header"]["status_code"] ;
|
||||
if (status2 == 200){
|
||||
token = jsonResponse["message"]["body"]["user_token"] ?? '';
|
||||
if (token != "" && token != "UpgradeOnlyUpgradeOnlyUpgradeOnlyUpgradeOnly"){
|
||||
console.log('200 token');
|
||||
// token good
|
||||
globaltoken = token;
|
||||
if (mode == 1){
|
||||
getMXMSubs(track, artist, token, lang, time);
|
||||
} else {
|
||||
getMXMTrans(songid, lang, token);
|
||||
}
|
||||
} else {
|
||||
console.log('fake 200 token');
|
||||
if (mode == 1){
|
||||
ipcRenderer.send('LyricsMXMFailed','');
|
||||
}
|
||||
}} else {
|
||||
console.log('token 4xx');
|
||||
if (mode == 1){
|
||||
ipcRenderer.send('LyricsMXMFailed','');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
req.send();
|
||||
}
|
||||
function getMXMSubs(track, artist, token, lang, time) {
|
||||
var usertoken = encodeURIComponent(token);
|
||||
var timecustom = `&f_subtitle_length=${time}&q_duration=${time}&f_subtitle_length_max_deviation=40`;
|
||||
var url = "https://apic-desktop.musixmatch.com/ws/1.1/macro.subtitles.get?format=json&namespace=lyrics_richsynched&subtitle_format=lrc&q_artist="+artist+"&q_track="+track+"&usertoken="+usertoken+timecustom+"&app_id=web-desktop-app-v1.0&t="+revisedRandId();
|
||||
var req = new XMLHttpRequest();
|
||||
req.overrideMimeType("application/json");
|
||||
req.open('GET', url, true);
|
||||
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
||||
req.onload = function() {
|
||||
var jsonResponse = JSON.parse(this.responseText);
|
||||
console.log(jsonResponse);
|
||||
var status1 = jsonResponse["message"]["header"]["status_code"] ;
|
||||
|
||||
if (status1 == 200){
|
||||
var id = '';
|
||||
try{
|
||||
if (jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["header"]["status_code"] == 200 && jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["header"]["status_code"] == 200) {
|
||||
prevartist = artist;
|
||||
prevtrack = track;
|
||||
id = jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["body"]["track"]["track_id"] ?? '';
|
||||
lrcfile = jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["body"]["subtitle_list"][0]["subtitle"]["subtitle_body"];}
|
||||
|
||||
// /* MXM Instrumentals detection */
|
||||
// else if (jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["header"]["instrumental"] == 1){
|
||||
// print('Nah');
|
||||
// ipcRenderer.send('LyricsHandlerNE','[00:00] Instrumental. / Lyrics not found.');
|
||||
// return '';
|
||||
// }
|
||||
|
||||
if (lrcfile == "" ){
|
||||
// track not found
|
||||
console.log('track not found');
|
||||
prevlyrics = [track,artist,'','',''];
|
||||
ipcRenderer.send('LyricsMXMFailed','');
|
||||
} else {
|
||||
lrcfile = lrcfile.concat("\r\n");
|
||||
var timearr = lrcfile.match(/\[([0-9]+):([0-9.]+)]/g);
|
||||
timearr.unshift('[00:00.000]');
|
||||
for (i = 0; i < timearr.length -1 ; i++){
|
||||
var rawTime = timearr[i+1].match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/);
|
||||
var hours = (rawTime[2] != null) ? (rawTime[1].replace(":", "")) : "0";
|
||||
var minutes =(rawTime[2] != null) ? (hours * 60 + rawTime[2].replace(":", "") * 1 + ":") : ((rawTime[1] != null) ? rawTime[1] : "00:");
|
||||
var seconds = (rawTime[3] != null) ? (rawTime[3]) : "00";
|
||||
var milliseconds = (rawTime[4] != null) ? (rawTime[4]) : ".000";
|
||||
var lrcTime = minutes + seconds + milliseconds;
|
||||
|
||||
var rawTime2 = timearr[i].match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/);
|
||||
var hours2 = (rawTime2[2] != null) ? (rawTime2[1].replace(":", "")) : "0";
|
||||
var minutes2 = (rawTime2[2] != null) ? (hours2 * 60 + rawTime2[2].replace(":", "") * 1 + ":") : ((rawTime2[1] != null) ? rawTime2[1] : "00:");
|
||||
var seconds2 = (rawTime2[3] != null) ? (rawTime2[3]) : "00";
|
||||
var milliseconds2 = (rawTime2[4] != null) ? (rawTime2[4]) : ".000";
|
||||
var lrcTime2 = minutes2 + seconds2 + milliseconds2;
|
||||
|
||||
if ( minutes.replace(":","") * 60 + seconds * 1 - minutes2.replace(":","") * 60 - seconds2 * 1 > 10) {
|
||||
|
||||
if (minutes2 + (seconds2*1+10) + milliseconds2 != '00:10.000'){
|
||||
lrcfile = lrcfile.concat(`[${minutes2 + (seconds2*1+10) + milliseconds2}]lrcInstrumental` + "\r\n");}
|
||||
else {lrcfile = lrcfile.concat(`[00:00.00]lrcInstrumental` + "\r\n");}
|
||||
}
|
||||
}
|
||||
console.log(lrcfile);
|
||||
ipcRenderer.send('LyricsHandlerNE',lrcfile);
|
||||
if(lrcfile != null && lrcfile != ''){
|
||||
// load translation
|
||||
getMXMTrans(id, lang, token);
|
||||
} else {
|
||||
ipcRenderer.send('LyricsMXMFailed','');
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
// track not found ??
|
||||
console.log('track not found ??');
|
||||
ipcRenderer.send('LyricsMXMFailed','');
|
||||
}
|
||||
} else { //4xx rejected
|
||||
getToken(1, track, artist, '', lang, time);}
|
||||
}
|
||||
req.send();
|
||||
}
|
||||
function getMXMTrans(id, lang, token){
|
||||
if (lang != "disabled" && id != ''){
|
||||
var usertoken = encodeURIComponent(token);
|
||||
var url2 = "https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&selected_language="+lang+"&track_id="+id+"&comment_format=text&part=user&format=json&usertoken="+usertoken+"&app_id=web-desktop-app-v1.0&t="+revisedRandId();
|
||||
var req2 = new XMLHttpRequest();
|
||||
req2.overrideMimeType("application/json");
|
||||
req2.open('GET', url2, true);
|
||||
req2.setRequestHeader("authority", "apic-desktop.musixmatch.com");
|
||||
req2.onload = function() {
|
||||
var jsonResponse2 = JSON.parse(this.responseText);
|
||||
console.log(jsonResponse2);
|
||||
var status2 = jsonResponse2["message"]["header"]["status_code"] ;
|
||||
if (status2 == 200){
|
||||
try{
|
||||
var lyrics = jsonResponse2["message"]["body"]["translations_list"];
|
||||
console.log(lyrics);
|
||||
if (lyrics.length > 0) {
|
||||
ipcRenderer.send('LyricsHandlerTranslation',lyrics);}
|
||||
}catch(e){
|
||||
/// not found trans -> ignore
|
||||
}
|
||||
} else { //4xx rejected
|
||||
getToken(2,'', '', id, lang, '');
|
||||
}
|
||||
}
|
||||
req2.send();
|
||||
}
|
||||
}
|
||||
|
||||
ipcRenderer.on('mxmcors', function (event, track, artist, lang, time) {
|
||||
console.log("hello");
|
||||
if (track != "" & track != "No Title Found"){
|
||||
if ( globaltoken != null && globaltoken != '' ) {
|
||||
console.log("we good");
|
||||
getMXMSubs(track, artist, token, lang, time)
|
||||
} else {
|
||||
console.log("get token");
|
||||
getToken(1,track, artist, '', lang, time);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
lrc.setLrc(text);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
81
oldshit/resources/lyrics/netease.html
Normal file
81
oldshit/resources/lyrics/netease.html
Normal file
|
@ -0,0 +1,81 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Lyrics</title>
|
||||
<script type="text/javascript" src="../js/lyrics.js"></script>
|
||||
<link rel="stylesheet" href="../css/lyricer.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=M+PLUS+1p" rel="stylesheet">
|
||||
</head>
|
||||
<body style="margin: 0;">
|
||||
<img style="" id="backgroundImage" alt="Background Image"></img>
|
||||
<div style="width: 100%; height: 100%; opacity: 0.8; z-index: 1; background-color: rgba(0, 0, 0, 0.5); position: absolute;"></div>
|
||||
<div id="lyricer">
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
function changeStylesheetRule(stylesheet, selector, property, value) {
|
||||
selector = selector.toLowerCase();
|
||||
property = property.toLowerCase();
|
||||
value = value.toLowerCase();
|
||||
|
||||
for(var i = 0; i < stylesheet.cssRules.length; i++) {
|
||||
var rule = stylesheet.cssRules[i];
|
||||
if(rule.selectorText === selector) {
|
||||
rule.style[property] = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
stylesheet.insertRule(selector + " { " + property + ": " + value + "; }", 0);
|
||||
}
|
||||
|
||||
var text = "";
|
||||
var lrc = new Lyricer();
|
||||
ipcRenderer.on('neteasecors', function (event, lrcfile) {
|
||||
if (lrcfile.startsWith("netease=")){
|
||||
try{
|
||||
var url = "https://music.163.com/api/search/pc?s="+lrcfile.substring(8)+"&type=1&limit=1";
|
||||
var req = new XMLHttpRequest();
|
||||
req.overrideMimeType("application/json");
|
||||
req.open('GET', url, true);
|
||||
req.onload = function() {
|
||||
try{
|
||||
var jsonResponse = JSON.parse(req.responseText);
|
||||
var id = jsonResponse["result"]["songs"][0]["id"];
|
||||
var url2 = "https://music.163.com/api/song/lyric?os=pc&id="+id+"&lv=-1&kv=-1&tv=-1";
|
||||
var req2 = new XMLHttpRequest();
|
||||
req2.overrideMimeType("application/json");
|
||||
req2.open('GET', url2, true);
|
||||
req2.onload = function() {
|
||||
try{
|
||||
var jsonResponse2 = JSON.parse(req2.responseText);
|
||||
var lyrics = jsonResponse2["lrc"]["lyric"];
|
||||
ipcRenderer.send('LyricsHandlerNE',lyrics);
|
||||
window.close();}
|
||||
catch (e) {
|
||||
ipcRenderer.send('LyricsHandlerNE','[00:00] Instrumental. / Lyrics not found.');
|
||||
window.close();
|
||||
}
|
||||
};
|
||||
req2.send();
|
||||
}catch(e){
|
||||
ipcRenderer.send('LyricsHandlerNE','[00:00] Instrumental. / Lyrics not found.');
|
||||
window.close();
|
||||
}
|
||||
};
|
||||
req.send();
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
ipcRenderer.send('LyricsHandlerNE','[00:00] Instrumental. / Lyrics not found.');
|
||||
window.close();
|
||||
} }
|
||||
else{}
|
||||
});
|
||||
|
||||
|
||||
lrc.setLrc(text);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
121
oldshit/resources/lyrics/youtube.html
Normal file
121
oldshit/resources/lyrics/youtube.html
Normal file
|
@ -0,0 +1,121 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Lyrics</title>
|
||||
<script type="text/javascript" src="../js/lyrics.js"></script>
|
||||
<link rel="stylesheet" href="../css/lyricer.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=M+PLUS+1p" rel="stylesheet">
|
||||
</head>
|
||||
<body style="margin: 0;">
|
||||
<img style="" id="backgroundImage" alt="Background Image"></img>
|
||||
<div style="width: 100%; height: 100%; opacity: 0.8; z-index: 1; background-color: rgba(0, 0, 0, 0.5); position: absolute;"></div>
|
||||
<div id="lyricer">
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
const { ipcRenderer } = require('electron');
|
||||
const yt = require('youtube-search-without-api-key');
|
||||
var text = "";
|
||||
var lrcfile = "";
|
||||
var lrc = new Lyricer();
|
||||
var prevartist = '';
|
||||
var prevtrack = '';
|
||||
var prevlyrics = ['','','','','']; //track, artist, songid, lyrics, translated lyrics
|
||||
var globaltoken = '';
|
||||
function revisedRandId() {
|
||||
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
|
||||
}
|
||||
|
||||
async function getYTSubs(track, artist, lang) {
|
||||
|
||||
console.log(decodeURIComponent(track) +" "+ decodeURIComponent(artist) + " official video");
|
||||
const videos = await yt.search(decodeURIComponent(track) +" "+ decodeURIComponent(artist) + " official video");
|
||||
try{
|
||||
if (videos != null & videos.length > 0){
|
||||
var id = videos[0]['id']['videoId'];
|
||||
getYTTrans(id,lang);
|
||||
}
|
||||
}catch(e){}
|
||||
}
|
||||
function getYTTrans(id, lang){
|
||||
if (lang != "disabled" && id != ''){
|
||||
var url2 = `http://video.google.com/timedtext?lang=${lang}&v=${id}`;
|
||||
var req2 = new XMLHttpRequest();
|
||||
|
||||
req2.open('GET', url2, true);
|
||||
req2.onload = function() {
|
||||
const ttmlLyrics = this.responseText;
|
||||
let lyrics = "";
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(ttmlLyrics, "text/xml");
|
||||
const lyricsLines = doc.getElementsByTagName('text');
|
||||
const endTime = [0];
|
||||
try {
|
||||
for (let element of lyricsLines) {
|
||||
rawTime = element.getAttribute('start').match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/);
|
||||
hours = (rawTime[2] != null) ? (rawTime[1].replace(":", "")) : "0";
|
||||
minutes = (rawTime[2] != null) ? (hours * 60 + rawTime[2].replace(":", "") * 1 + ":") : ((rawTime[1] != null) ? rawTime[1] : "00:");
|
||||
seconds = (rawTime[3] != null) ? (rawTime[3]) : "00";
|
||||
milliseconds = (rawTime[4] != null) ? (rawTime[4]) : ".000";
|
||||
lrcTime = minutes + seconds + milliseconds;
|
||||
const rawTime2 = element.getAttribute('dur').match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/);
|
||||
const hours2 = (rawTime2[2] != null) ? (rawTime2[1].replace(":", "")) : "0";
|
||||
const minutes2 = (rawTime2[2] != null) ? (hours2 * 60 + rawTime2[2].replace(":", "") * 1 + ":") : ((rawTime2[1] != null) ? rawTime2[1] : "00:");
|
||||
const seconds2 = (rawTime2[3] != null) ? (rawTime2[3]) : "00";
|
||||
const milliseconds2 = (rawTime2[4] != null) ? (rawTime2[4]) : ".000";
|
||||
const lrcTime2 = minutes2 + seconds2 + milliseconds2;
|
||||
if (minutes.replace(":", "") * 60 + seconds * 1 - endTime[endTime.length - 1] > 10) {
|
||||
const time = endTime[endTime.length - 1];
|
||||
const minutes = Math.floor(time / 60);
|
||||
const secs = time - minutes * 60;
|
||||
lyrics = lyrics.concat(`[${minutes}:${secs}]lrcInstrumental` + "\r\n");
|
||||
}
|
||||
endTime.push(minutes.replace(":", "") * 60 + minutes2.replace(":", "") * 60 + seconds2 * 1 + seconds * 1);
|
||||
lyrics = lyrics.concat(`[${lrcTime}]${element.textContent}` + "\r\n");
|
||||
|
||||
}
|
||||
if (lyrics != ""){
|
||||
console.log(lyrics);
|
||||
ipcRenderer.send('LyricsHandlerNE',lyrics);
|
||||
}
|
||||
} catch(e) {
|
||||
lyrics = "";
|
||||
for (let element of lyricsLines) {
|
||||
rawTime = element.getAttribute('begin').match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/);
|
||||
hours = (rawTime[2] != null) ? (rawTime[1].replace(":", "")) : "0";
|
||||
minutes = (rawTime[2] != null) ? (hours * 60 + rawTime[2].replace(":", "") * 1 + ":") : ((rawTime[1] != null) ? rawTime[1] : "00:");
|
||||
seconds = (rawTime[3] != null) ? (rawTime[3]) : "00";
|
||||
milliseconds = (rawTime[4] != null) ? (rawTime[4]) : ".000";
|
||||
lrcTime = minutes + seconds + milliseconds;
|
||||
lyrics = lyrics.concat(`[${lrcTime}]${element.textContent}` + "\r\n");
|
||||
|
||||
}
|
||||
if (lyrics != ""){
|
||||
console.log(lyrics);
|
||||
ipcRenderer.send('LyricsHandlerNE',lyrics);
|
||||
}
|
||||
}
|
||||
if (lyrics == ""){
|
||||
ipcRenderer.send('LyricsYTFailed',"");
|
||||
console.log('yt no found')
|
||||
}
|
||||
// window.close();
|
||||
|
||||
}
|
||||
req2.send();
|
||||
}
|
||||
}
|
||||
|
||||
ipcRenderer.on('ytcors', function (event, track, artist, lang) {
|
||||
console.log("hello");
|
||||
if (track != "" && track != "No Title Found"){
|
||||
console.log("we good");
|
||||
getYTSubs(track, artist, lang)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
lrc.setLrc(text);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue