Skip to content

Commit

Permalink
Web app: remove hot fix, fix drag and drop links
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Oct 19, 2024
1 parent 5d89d1b commit 048be5c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 150 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing worth mentioning yet.
### Fixed

- Link drag and drop functionality in web app

### Removed

- "Hot fix" from web app

## [0.29.0] - 2024-10-18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,6 @@ namespace Http
return true
end function

@post("/api/ytjs-cache")
function CacheVideoInfo(context as object) as boolean
request = context.request
response = context.response

json = request.Json()
if json = invalid
response.Default(400, "Invalid request body")
return true
end if

instance = m.invidiousService.GetInstance()
videoId = json.videoId

url = `${instance}${Invidious.VIDEOS_ENDPOINT}/${videoId}`

' Place a fake cache so we can read it later
requestObj = HttpClient.Get(url)
requestObj.CacheSeconds(18000)
responseObj = new HttpClient.HttpResponse(requestObj, invalid)
responseObj.OverrideStatusCode(200)
responseObj.OverrideText(request.body)
HttpClientCache.Set(responseObj)

response.Default(204, "OK")
return true
end function

end class

end namespace
99 changes: 2 additions & 97 deletions playlet-web/src/lib/Api/YoutubeJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,53 +186,6 @@ export class YoutubeJs {
throw new Error(`Video not available: ${info.playability_status.reason}`);
}

const formatStreams = info.streaming_data.formats.map(format => {
return {
url: format.decipher(YoutubeJs.innerTube.session.player),
itag: `${format.itag}`,
}
});

const adaptiveFormats = info.streaming_data.adaptive_formats.map(format => {
const formatInfo = FORMATS[format.itag];
const result: any = {
init: format.init_range ? `${format.init_range.start}-${format.init_range.end}` : "",
index: format.index_range ? `${format.index_range.start}-${format.index_range.end}` : "",
bitrate: `${format.bitrate}`,
url: format.decipher(YoutubeJs.innerTube.session.player),
itag: `${format.itag}`,
type: format.mime_type,
clen: `${format.approx_duration_ms}`,
container: formatInfo?.ext,
encoding: formatInfo?.acodec ?? formatInfo?.vcodec,
};
if (format.audio_quality) {
result.audioQuality = format.audio_quality;
}
if (format.audio_sample_rate) {
result.audioSampleRate = format.audio_sample_rate;
}
if (format.audio_channels) {
result.audioChannels = format.audio_channels;
}

if (format.quality_label) {
result.qualityLabel = format.quality_label;
}
if (format.fps) {
result.fps = format.fps;
}
if (format.height && format.width) {
result.size = `${format.width}x${format.height}`;
result.resolution = `${format.height}p`;
} else if (formatInfo?.height && formatInfo?.width) {
result.size = `${formatInfo.width}x${formatInfo.height}`;
result.resolution = `${formatInfo.height}p`;
}

return result;
});

// Populate a video object that is similar to Invidious format.
// Mostly populate only fields we care about, enough to make it work.
return {
Expand Down Expand Up @@ -269,58 +222,10 @@ export class YoutubeJs {
isUpcoming: info.basic_info.is_upcoming,
dashUrl: "",
hlsUrl: info.streaming_data.hls_manifest_url,
adaptiveFormats,
formatStreams,
adaptiveFormats: [],
formatStreams: [],
captions: [],
recommendedVideos: [],
}
}

static async postCacheData(data) {
const maxRetries = 2;
const timeout = 5000;

for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
await YoutubeJs.postJson(`${YoutubeJs.host()}/api/ytjs-cache`, data, timeout);
break;
} catch (error) {
if (attempt === maxRetries) {
throw error;
}
console.warn(`Attempt ${attempt} failed. Retrying...`);
}
}
}

private static postJson(url, payload, timeout) {
return new Promise((resolve, reject) => {
const controller = new AbortController();
const timer = setTimeout(() => {
controller.abort();
reject(new Error('Request timed out'));
}, timeout);

fetch(url, {
headers: {
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify(payload),
signal: controller.signal
})
.then(response => {
clearTimeout(timer);
resolve(response);
})
.catch(err => {
clearTimeout(timer);
if (err.name === 'AbortError') {
reject(new Error('Request was aborted'));
} else {
reject(err);
}
});
});
}
}
3 changes: 2 additions & 1 deletion playlet-web/src/lib/LinkDragDrop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { onDestroy, onMount } from "svelte";
import { playletStateStore, tr } from "lib/Stores";
import { InvidiousApi } from "lib/Api/InvidiousApi";
import { YoutubeJs } from "./Api/YoutubeJs";
import VideoCastDialog from "./VideoFeed/VideoCastDialog.svelte";
import ChannelCastDialog from "./VideoFeed/ChannelCastDialog.svelte";
import PlaylistCastDialog from "./VideoFeed/PlaylistCastDialog.svelte";
Expand Down Expand Up @@ -108,7 +109,7 @@
async function searchForVideoById(videoId, timestamp) {
try {
isLoading = true;
videoMetadata = await invidiousApi.getVideoMetadata(videoId);
videoMetadata = await YoutubeJs.getVideoInfo(videoId);
videoStartAtChecked = timestamp !== undefined;
if (videoStartAtChecked) {
videoStartAtTimestamp = timestamp;
Expand Down
23 changes: 0 additions & 23 deletions playlet-web/src/lib/VideoFeed/VideoCastDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { playletStateStore, tr } from "lib/Stores";
import VideoStartAt from "./VideoStartAt.svelte";
import VideoThumbnail from "./VideoThumbnail.svelte";
import { YoutubeJs } from "lib/Api/YoutubeJs";
export let videoId: string | undefined = undefined;
export let title: string | undefined = undefined;
Expand Down Expand Up @@ -44,22 +43,6 @@
await PlayletApi.playVideo(getVideoInfo());
}
async function playOnTvHotFix() {
// measure length of time it takes to get video info
try {
const start = performance.now();
const videoInfo = await YoutubeJs.getVideoInfo(videoId);
const end = performance.now();
console.log(`Time to get video info: ${end - start}ms`);
await YoutubeJs.postCacheData(videoInfo);
await playOnTv();
} catch (e) {
console.error(e);
alert(e.toString());
}
}
async function queueOnTv() {
await PlayletApi.queueVideo(getVideoInfo());
}
Expand Down Expand Up @@ -131,12 +114,6 @@
<button class="btn join-item hover:btn-accent" on:click={playOnTv}>
{$tr("Play on %1").replace("%1", tvName)}
</button>
<button
class="btn join-item hover:btn-accent"
on:click={playOnTvHotFix}
>
{$tr("Play on %1").replace("%1", tvName)} (HOT FIX)
</button>
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
{$tr("Queue on %1").replace("%1", tvName)}
</button>
Expand Down

0 comments on commit 048be5c

Please sign in to comment.