Support drag and drop links for channels

This commit is contained in:
Brahim Hadriche committed 2023-10-24 19:59:24 -04:00
1 parent 549913ef7d
commit 6051d45a80
4 files changed
+67 -12

No files matched your search

+1
View File
@@ -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. - 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 - Search filters in web app
- Channels and Playlists can be opened on TV from 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 ### Fixed
+10
View File
@@ -51,6 +51,16 @@ export class InvidiousApi {
return await response.json(); 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) { public async markFeedSourcePagination(feedSource: any) {
const endpoint = this.endpoints[feedSource.endpoint] const endpoint = this.endpoints[feedSource.endpoint]
if (!endpoint || !endpoint.paginationType) { if (!endpoint || !endpoint.paginationType) {
+53 -12
View File
@@ -14,6 +14,7 @@
let videoStartAtTimestamp; let videoStartAtTimestamp;
let videoMetadata; let videoMetadata;
let channelMetadata;
let tvName = "Roku TV"; let tvName = "Roku TV";
let invidiousInstance; let invidiousInstance;
@@ -44,14 +45,20 @@
for (var i in event.dataTransfer.items) { for (var i in event.dataTransfer.items) {
let item = event.dataTransfer.items[i]; let item = event.dataTransfer.items[i];
if (item.kind === "string" && item.getAsString) { if (item.kind === "string" && item.getAsString) {
let dataString = await new Promise((resolve) => let dataString = (await new Promise((resolve) =>
item.getAsString(resolve) item.getAsString(resolve)
); )) as string;
if (isValidHttpUrl(dataString)) { if (isValidHttpUrl(dataString)) {
const videoInfo = parseYouTubeUrl(dataString); const videoInfo = parseYouTubeUrl(dataString);
if (videoInfo.videoId) { if (videoInfo.videoId) {
searchForVideoById(videoInfo.videoId, videoInfo.timestamp); searchForVideoById(videoInfo.videoId, videoInfo.timestamp);
return; 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) { function onDragOver(event) {
modal.close(); modal.close();
clearTimeout(dragEndTimeout); 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}`; let url = `${invidiousInstance}/watch?v=${videoMetadata?.videoId}`;
if (videoStartAtChecked && videoStartAtTimestamp) { if (videoStartAtChecked && videoStartAtTimestamp) {
url += `&t=${videoStartAtTimestamp}`; url += `&t=${videoStartAtTimestamp}`;
} }
window.open(url); window.open(url);
} }
function openChannelInvidiousInNewTab() {
let url = `${invidiousInstance}/channel/${channelMetadata?.authorId}`;
window.open(url);
}
</script> </script>
<div <div
@@ -185,22 +211,37 @@
<dialog bind:this={modal} id="modal_video_drag_drop" class="modal"> <dialog bind:this={modal} id="modal_video_drag_drop" class="modal">
<form method="dialog" class="modal-box bg-base-100"> <form method="dialog" class="modal-box bg-base-100">
<h3 class="text-lg m-5">{videoMetadata?.title}</h3> {#if videoMetadata}
<h3 class="text-lg m-5">{videoMetadata.title}</h3>
<div class="flex flex-col"> <div class="flex flex-col">
<VideoStartAt <VideoStartAt
bind:checked={videoStartAtChecked} bind:checked={videoStartAtChecked}
bind:timestamp={videoStartAtTimestamp} bind:timestamp={videoStartAtTimestamp}
lengthSeconds={videoMetadata?.lengthSeconds} lengthSeconds={videoMetadata.lengthSeconds}
/> />
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button> <button class="btn m-2" on:click={playVideoOnTv}>
<button class="btn m-2" on:click={queueVideoOnTv} Play on {tvName}
>Queue on {tvName} </button>
<button class="btn m-2" on:click={queueVideoOnTv}>
Queue on {tvName}
</button>
<button class="btn m-2" on:click={openVideoInvidiousInNewTab}>
Open in Invidious
</button> </button>
<button class="btn m-2" on:click={openInvidiousInNewTab}
>Open in Invidious</button
>
<button class="btn m-2">Cancel</button>
</div> </div>
{:else if channelMetadata}
<h3 class="text-lg m-5">{channelMetadata.author}</h3>
<div class="text-sm m-5 line-clamp-3">{channelMetadata.description}</div>
<button class="btn m-2" on:click={openChannelOnTv}>
Open on {tvName}
</button>
<button class="btn m-2" on:click={openChannelInvidiousInNewTab}>
Open in Invidious
</button>
{:else}
<span class="loading loading-spinner loading-md" />
{/if}
<button class="btn m-2">Cancel</button>
</form> </form>
<form method="dialog" class="modal-backdrop"> <form method="dialog" class="modal-backdrop">
<button>close</button> <button>close</button>
@@ -182,6 +182,9 @@
} }
} }
} catch (error) { } catch (error) {
// TODO:P0 handle case of unauthenticated calls
// TODO:P0 handle case of popular feed disabled
// If we're done loading all the feed, but still have no videos, hide the whole component.
console.error(error); console.error(error);
feedSource.state.loadState = FeedLoadState.Error; feedSource.state.loadState = FeedLoadState.Error;
} }