1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-17 07:40:27 +05:30
Piped/src/components/PlaylistPage.vue

139 lines
4.9 KiB
Vue
Raw Normal View History

<template>
<ErrorHandler v-if="playlist && playlist.error" :message="playlist.message" :error="playlist.error" />
<div v-if="playlist" v-show="!playlist.error">
2022-07-22 02:21:41 +05:30
<h1 class="text-center my-4" v-text="playlist.name" />
2021-12-27 20:16:22 +05:30
<div class="grid grid-cols-2">
<div>
<router-link class="link" :to="playlist.uploaderUrl || '/'">
2021-12-28 06:43:55 +05:30
<img :src="playlist.uploaderAvatar" loading="lazy" class="rounded-full" />
<strong v-text="playlist.uploader" />
</router-link>
2021-12-27 20:16:22 +05:30
</div>
<div>
<div class="right-2vw absolute">
2021-12-27 21:59:25 +05:30
<strong v-text="`${playlist.videos} ${$t('video.videos')}`" />
2021-12-27 20:16:22 +05:30
<br />
2022-07-22 02:21:41 +05:30
<button class="btn mr-1" v-if="authenticated && !isPipedPlaylist" @click="clonePlaylist">
{{ $t("actions.clone_playlist") }}<font-awesome-icon class="ml-3" icon="clone" />
</button>
<a class="btn" :href="getRssUrl">
2021-12-28 04:03:55 +05:30
<font-awesome-icon icon="rss" />
</a>
2021-12-27 20:16:22 +05:30
</div>
</div>
2021-07-05 00:27:57 +05:30
</div>
<hr />
2021-12-27 20:16:22 +05:30
<div class="video-grid">
<VideoItem
2022-04-07 08:03:25 +05:30
v-for="(video, index) in playlist.relatedStreams"
:key="video.url"
:video="video"
2022-04-07 08:03:25 +05:30
:index="index"
:playlist-id="$route.query.list"
:admin="admin"
@remove="removeVideo(index)"
height="94"
width="168"
/>
</div>
</div>
</template>
<script>
2022-04-08 21:16:49 +05:30
import ErrorHandler from "./ErrorHandler.vue";
import VideoItem from "./VideoItem.vue";
export default {
components: {
ErrorHandler,
VideoItem,
},
data() {
return {
playlist: null,
2022-04-07 08:03:25 +05:30
admin: false,
};
},
computed: {
getRssUrl: _this => {
return _this.authApiUrl() + "/rss/playlists/" + _this.$route.query.list;
},
2022-07-22 17:09:49 +05:30
isPipedPlaylist: _this => {
// regex to determine whether it's a Piped plalylist
2022-07-22 18:57:51 +05:30
return /[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}/.test(
_this.$route.query.list,
);
2022-07-22 02:21:41 +05:30
},
},
mounted() {
this.getPlaylistData();
2022-04-07 08:03:25 +05:30
const playlistId = this.$route.query.list;
if (this.authenticated && playlistId?.length == 36)
this.fetchJson(this.authApiUrl() + "/user/playlists", null, {
2022-04-07 08:03:25 +05:30
headers: {
Authorization: this.getAuthToken(),
},
}).then(json => {
if (json.error) alert(json.error);
else if (json.filter(playlist => playlist.id === playlistId).length > 0) this.admin = true;
});
},
activated() {
window.addEventListener("scroll", this.handleScroll);
2022-04-09 02:59:50 +05:30
if (this.playlist) this.updateTitle();
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchPlaylist() {
return await await this.fetchJson(this.authApiUrl() + "/playlists/" + this.$route.query.list);
},
async getPlaylistData() {
this.fetchPlaylist()
.then(data => (this.playlist = data))
2022-04-09 02:59:50 +05:30
.then(() => this.updateTitle());
},
async updateTitle() {
document.title = this.playlist.name + " - Piped";
},
handleScroll() {
if (this.loading || !this.playlist || !this.playlist.nextpage) return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
this.loading = true;
this.fetchJson(this.authApiUrl() + "/nextpage/playlists/" + this.$route.query.list, {
nextpage: this.playlist.nextpage,
}).then(json => {
2021-02-24 15:05:41 +05:30
this.playlist.relatedStreams.concat(json.relatedStreams);
this.playlist.nextpage = json.nextpage;
this.loading = false;
json.relatedStreams.map(stream => this.playlist.relatedStreams.push(stream));
2021-02-24 15:05:41 +05:30
});
}
},
2022-04-07 08:03:25 +05:30
removeVideo(index) {
this.playlist.relatedStreams.splice(index, 1);
},
2022-07-22 02:21:41 +05:30
async clonePlaylist() {
this.fetchJson(this.authApiUrl() + "/import/playlist", null, {
method: "POST",
headers: {
Authorization: this.getAuthToken(),
},
body: JSON.stringify({
2022-07-22 17:09:49 +05:30
playlistId: this.$route.query.list,
2022-07-22 02:21:41 +05:30
}),
}).then(resp => {
if (!resp.error) {
alert(this.$t("actions.clone_playlist_success"));
} else alert(resp.error);
});
},
},
};
</script>