mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 01:18:27 +00:00

- rewrote and/or optimized all service modules - rewrote matching and processing modules to optimize readability and performance - added support for reddit gifs - fixed various issues with twitter error explanations - code optimizations and enhancements (such as finally getting rid of ==, prettier and more readable formatting, etc) - added branch information - all functions in currentCommit submodule run only once and cache received data - added a test script. only twitter and soundcloud are 100% covered and tested atm, will add tests (and probably fixes) for the rest of services in next commits - changed some localization strings for russian - added more clarity to rate limit message - moved services folder into processing folder
30 lines
946 B
JavaScript
30 lines
946 B
JavaScript
import { services, quality as mq } from "../config.js";
|
|
|
|
// TO-DO: remake entirety of this module to be more of how quality picking is done in vimeo module
|
|
function closest(goal, array) {
|
|
return array.sort().reduce(function (prev, curr) {
|
|
return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev);
|
|
});
|
|
}
|
|
|
|
export default function(service, quality, maxQuality) {
|
|
if (quality === "max") return maxQuality;
|
|
|
|
quality = parseInt(mq[quality], 10)
|
|
maxQuality = parseInt(maxQuality, 10)
|
|
|
|
if (quality >= maxQuality || quality === maxQuality) return maxQuality;
|
|
|
|
if (quality < maxQuality) {
|
|
if (!services[service]["quality"][quality]) {
|
|
let s = Object.keys(services[service]["quality_match"]).filter((q) => {
|
|
if (q <= quality) {
|
|
return true
|
|
}
|
|
})
|
|
return closest(quality, s)
|
|
}
|
|
return quality
|
|
}
|
|
}
|