Skip to content

Commit

Permalink
Use unproxied playback since proxies is so slow and latency. Volume b…
Browse files Browse the repository at this point in the history
…oost was removed (it's not allowed by CORS)
  • Loading branch information
malisipi committed Jun 27, 2023
1 parent de54775 commit faef6bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 41 deletions.
7 changes: 0 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@
"title": "Always use HSL",
"description": "Use HSL if it is available in streams"
},
{
"type": "bool",
"default": -1,
"conf": "volume-boost-300",
"title": "Volume Boost (300%)",
"description": "Allow to boosting volume up to 300%. (It can be harm your ears and speakers)"
},
{
"type": "bool",
"default": 1,
Expand Down
8 changes: 6 additions & 2 deletions js/backend-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ dv.backend = {
__get_region: () => {
return navigator.language.slice(-2).toUpperCase();
},
__get_unproxied_playback_url: (old_url) => {
let url_object=new URL(old_url);
return old_url.replace(url_object.host, url_object.searchParams.get("host"));
},
network_saving: false,
get_trending_videos: async (reload = false) => {
let tp_resource = await fetch(dv.backend.__host+"/trending?region="+dv.backend.__get_region(), { cache: dv.backend.__get_fetch_policy(reload) });
Expand Down Expand Up @@ -88,7 +92,7 @@ dv.backend = {
let src = asrcs[src_index];

video.sources.audio.push({
url: src.url,
url: dv.backend.__get_unproxied_playback_url(src.url),
quality: src.quality,
codec: src.codec,
bitrate: src.bitrate,
Expand All @@ -100,7 +104,7 @@ dv.backend = {
let src = vsrcs[src_index];

video.sources.video.push({
url: src.url,
url: dv.backend.__get_unproxied_playback_url(src.url),
quality: src.quality,
codec: src.codec,
bitrate: src.bitrate,
Expand Down
4 changes: 0 additions & 4 deletions windows/css/player.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ body {

& input[type="range"].volume {
max-width: 75px;

&[max="300"] {
max-width: 225px;
}
}

[external_file]:is(body) & :is(.subtitles, .audio-only) {
Expand Down
29 changes: 3 additions & 26 deletions windows/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,16 @@ var dv = {
audio: null,
audio_only: false,
volume_management: {
gain_node: {
video: null,
audio: null
},
init: async() => {
if(await dv.storage.conf.get("volume-boost-300") == 1) {
document.querySelector("input.volume").setAttribute("max", 300);
};

let elements = ["video", "audio"];
for(let element_index in elements){
let type = elements[element_index];
let audio_ctx = new AudioContext();
let source = audio_ctx.createMediaElementSource(dv[type]);

dv.volume_management.gain_node[type] = audio_ctx.createGain();
dv.volume_management.gain_node[type].gain.value = 1;
source.connect(dv.volume_management.gain_node[type]);

dv.volume_management.gain_node[type].connect(audio_ctx.destination);
}
},
set: (volume=100) => {
dv.volume_management.gain_node["audio"].gain.value = volume / 100;
dv.volume_management.gain_node["video"].gain.value = volume / 100;
dv.audio.volume = volume / 100;
dv.video.volume = volume / 100;
let volume_button = document.querySelector("button.volume");
if(volume > 0 && volume_button.hasAttribute("true")) {
volume_button.removeAttribute("true");
};
},
get: () => {
return dv.volume_management.gain_node["audio"].gain.value * 100;
return dv.audio.volume * 100;
}
},
embed: false,
Expand Down Expand Up @@ -644,7 +622,6 @@ document.addEventListener("DOMContentLoaded", () => {
dv.video.addEventListener("loadedmetadata", dv.controls.time.update_duration);
dv.video.addEventListener("ended", dv.features.next_video);

dv.volume_management.init();
let controls = document.querySelector(".controls");

// Play/Pause Button
Expand Down
4 changes: 2 additions & 2 deletions windows/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<link rel="stylesheet" href="../css/components.css">
</head>
<body>
<video crossorigin="anonymous" preload="auto" autoplay></video>
<video autoplay></video>
<canvas></canvas>
<audio crossorigin="anonymous" preload="auto" autoplay hidden></audio>
<audio autoplay hidden></audio>
<img draggable="false" class="thumbnail" />
<div class="info">
<div class="name"></div>
Expand Down

0 comments on commit faef6bf

Please sign in to comment.