Actually works now

This commit is contained in:
Holger Frovin Jensen 2021-12-05 05:56:03 +01:00
parent 8c89236989
commit b83f06cf1f
4 changed files with 58 additions and 9 deletions

View file

@ -31,6 +31,12 @@ export default {
return {}; return {};
}, },
}, },
playlist: {
type: Object,
default: () => {
return {};
},
},
sponsors: { sponsors: {
type: Object, type: Object,
default: () => { default: () => {
@ -40,6 +46,7 @@ export default {
selectedAutoPlay: Boolean, selectedAutoPlay: Boolean,
selectedAutoLoop: Boolean, selectedAutoLoop: Boolean,
isEmbed: Boolean, isEmbed: Boolean,
isPlaylist: Boolean,
}, },
data() { data() {
return { return {
@ -328,13 +335,27 @@ export default {
videoEl.addEventListener("ended", () => { videoEl.addEventListener("ended", () => {
if (!this.selectedAutoLoop && this.selectedAutoPlay && this.video.relatedStreams.length > 0) { if (!this.selectedAutoLoop && this.selectedAutoPlay && this.video.relatedStreams.length > 0) {
const params = this.$route.query; const params = this.$route.query;
let url = this.video.relatedStreams[0].url; let index = Number(params.index).valueOf();
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
let isPlaylist = this.isPlaylist;
let url =
isPlaylist && index > this.playlist.relatedStreams.length
? this.playlist.relatedStreams[index].url
: this.video.relatedStreams[0].url;
let playlistEnded = index == this.playlist.relatedStreams.length;
for (var param in params) for (var param in params)
switch (param) { switch (param) {
case "v": case "v":
case "t": case "t":
break; break;
case "index":
if (playlistEnded) {
searchParams.delete("index");
} else searchParams.set(param, index + 1);
break;
case "list":
if (playlistEnded) searchParams.delete("list");
break;
default: default:
searchParams.set(param, params[param]); searchParams.set(param, params[param]);
break; break;

View file

@ -70,8 +70,8 @@ export default {
this.fetchPlaylist() this.fetchPlaylist()
.then(data => (this.playlist = data)) .then(data => (this.playlist = data))
.then(() => .then(() =>
this.playlist.relatedStreams.forEach(video => { this.playlist.relatedStreams.forEach((video, i) => {
video.url += "&list=" + this.$route.query.list; video.url += "&list=" + this.$route.query.list + "&index=" + (i + 1);
}), }),
) )
.then(() => (document.title = this.playlist.name + " - Piped")); .then(() => (document.title = this.playlist.name + " - Piped"));

View file

@ -1,6 +1,13 @@
<template> <template>
<div class="uk-text-secondary" :style="[{ background: backgroundColor }]"> <div class="uk-text-secondary" :style="[{ background: backgroundColor }]">
<router-link class="uk-text-emphasis" :to="video.url"> <router-link
class="uk-text-emphasis"
:to="
isPlaylist
? video.url + '&list=' + this.$route.query.list + '&index=' + (index.valueOf() + 1)
: video.url
"
>
<img :height="height" :width="width" style="width: 100%" :src="video.thumbnail" alt="" loading="lazy" /> <img :height="height" :width="width" style="width: 100%" :src="video.thumbnail" alt="" loading="lazy" />
<div class="uk-position-relative"> <div class="uk-position-relative">
<span <span
@ -36,7 +43,7 @@
<div class="uk-align-right" style="margin-left: 0; margin-bottom: 0; display: inline-block; width: 10%"> <div class="uk-align-right" style="margin-left: 0; margin-bottom: 0; display: inline-block; width: 10%">
<router-link <router-link
:to="video.url + '&listen=1'" :to="video.url + 'en=1'"
:aria-label="'Listen to ' + video.title" :aria-label="'Listen to ' + video.title"
:title="'Listen to ' + video.title" :title="'Listen to ' + video.title"
> >
@ -96,6 +103,14 @@ export default {
return {}; return {};
}, },
}, },
playlist: {
type: Object,
default: () => {
return {};
},
},
isPlaylist: Boolean,
index: Number,
height: { type: String, default: "118" }, height: { type: String, default: "118" },
width: { type: String, default: "210" }, width: { type: String, default: "210" },
hideChannel: { type: Boolean, default: false }, hideChannel: { type: Boolean, default: false },

View file

@ -17,6 +17,8 @@
<Player <Player
ref="videoPlayer" ref="videoPlayer"
:video="video" :video="video"
:playlist="playlist"
:isPlaylist="isPlaylist"
:sponsors="sponsors" :sponsors="sponsors"
:selected-auto-play="selectedAutoPlay" :selected-auto-play="selectedAutoPlay"
:selected-auto-loop="selectedAutoLoop" :selected-auto-loop="selectedAutoLoop"
@ -131,13 +133,20 @@
{{ showRecs ? $t("actions.minimize_recommendations") : $t("actions.show_recommendations") }} {{ showRecs ? $t("actions.minimize_recommendations") : $t("actions.show_recommendations") }}
</a> </a>
<div <div
v-for="related in isPlaylist ? playlist.relatedStreams : video.relatedStreams" v-for="(related, index) in isPlaylist ? playlist.relatedStreams : video.relatedStreams"
v-show="showRecs || !smallView" v-show="showRecs || !smallView"
:key="related.url" :key="related.url"
class="uk-tile-default uk-width-auto" class="uk-tile-default uk-width-auto"
:style="[{ background: backgroundColor }]" :style="[{ background: backgroundColor }]"
> >
<VideoItem :video="related" height="94" width="168" /> <VideoItem
:video="related"
:playlist="playlist"
:index="index"
height="94"
width="168"
:isPlaylist="isPlaylist"
/>
</div> </div>
<hr class="uk-hidden@s" /> <hr class="uk-hidden@s" />
</div> </div>
@ -168,6 +177,7 @@ export default {
playlist: { playlist: {
title: "Loading...", title: "Loading...",
}, },
index: null,
sponsors: null, sponsors: null,
selectedAutoLoop: false, selectedAutoLoop: false,
selectedAutoPlay: null, selectedAutoPlay: null,
@ -194,7 +204,7 @@ export default {
return String(_this.$route.path).indexOf("/embed/") == 0; return String(_this.$route.path).indexOf("/embed/") == 0;
}, },
isPlaylist(_this) { isPlaylist(_this) {
return _this.$route.query.list; return !!_this.$route.query.list;
}, },
uploadDate(_this) { uploadDate(_this) {
return new Date(_this.video.uploadDate).toLocaleString(undefined, { return new Date(_this.video.uploadDate).toLocaleString(undefined, {
@ -234,7 +244,10 @@ export default {
})(); })();
if (this.active) this.$refs.videoPlayer.loadVideo(); if (this.active) this.$refs.videoPlayer.loadVideo();
}); });
if (this.isPlaylist) {
this.getPlaylistData(); this.getPlaylistData();
this.index = this.$route.query.index;
}
this.getSponsors(); this.getSponsors();
if (!this.isEmbed && this.getPreferenceBoolean("comments", true)) this.getComments(); if (!this.isEmbed && this.getPreferenceBoolean("comments", true)) this.getComments();
window.addEventListener("resize", () => { window.addEventListener("resize", () => {