diff --git a/CHANGELOG.md b/CHANGELOG.md index 07c78042..b4c7f217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Known issue: thumbnails might appear cropped/misaligned at the end of videos. This will be addressed in a later release. - Search filters in web app - Channels and Playlists can be opened on TV from web app +- Channel links can be drag and dropped into the web app ### Fixed diff --git a/playlet-web/src/lib/Api/InvidiousApi.ts b/playlet-web/src/lib/Api/InvidiousApi.ts index 990d6ee6..65df189d 100644 --- a/playlet-web/src/lib/Api/InvidiousApi.ts +++ b/playlet-web/src/lib/Api/InvidiousApi.ts @@ -51,6 +51,16 @@ export class InvidiousApi { return await response.json(); } + public async getChannelMetadata(ucid: string) { + const response = await fetch(`${this.instance}/api/v1/channels/${ucid}`); + return await response.json(); + } + + public async resolveUrl(url: string) { + const response = await fetch(`${this.instance}/api/v1/resolveurl?url=${encodeURIComponent(url)}`); + return await response.json(); + } + public async markFeedSourcePagination(feedSource: any) { const endpoint = this.endpoints[feedSource.endpoint] if (!endpoint || !endpoint.paginationType) { diff --git a/playlet-web/src/lib/LinkDragDrop.svelte b/playlet-web/src/lib/LinkDragDrop.svelte index 0a172833..66318f34 100644 --- a/playlet-web/src/lib/LinkDragDrop.svelte +++ b/playlet-web/src/lib/LinkDragDrop.svelte @@ -14,6 +14,7 @@ let videoStartAtTimestamp; let videoMetadata; + let channelMetadata; let tvName = "Roku TV"; let invidiousInstance; @@ -44,14 +45,20 @@ for (var i in event.dataTransfer.items) { let item = event.dataTransfer.items[i]; if (item.kind === "string" && item.getAsString) { - let dataString = await new Promise((resolve) => + let dataString = (await new Promise((resolve) => item.getAsString(resolve) - ); + )) as string; if (isValidHttpUrl(dataString)) { const videoInfo = parseYouTubeUrl(dataString); if (videoInfo.videoId) { searchForVideoById(videoInfo.videoId, videoInfo.timestamp); return; + } else { + const urlInfo: any = await invidiousApi.resolveUrl(dataString); + if (urlInfo && urlInfo.pageType === "WEB_PAGE_TYPE_CHANNEL") { + searchForChannelById(urlInfo.ucid); + return; + } } } } @@ -72,6 +79,16 @@ } } + async function searchForChannelById(channelId) { + try { + isLoading = true; + channelMetadata = await invidiousApi.getChannelMetadata(channelId); + modal.showModal(); + } finally { + isLoading = false; + } + } + function onDragOver(event) { modal.close(); clearTimeout(dragEndTimeout); @@ -162,13 +179,22 @@ ); } - function openInvidiousInNewTab() { + async function openChannelOnTv() { + await PlayletApi.openChannel(channelMetadata?.authorId); + } + + function openVideoInvidiousInNewTab() { let url = `${invidiousInstance}/watch?v=${videoMetadata?.videoId}`; if (videoStartAtChecked && videoStartAtTimestamp) { url += `&t=${videoStartAtTimestamp}`; } window.open(url); } + + function openChannelInvidiousInNewTab() { + let url = `${invidiousInstance}/channel/${channelMetadata?.authorId}`; + window.open(url); + }