Piped/src/components/PlaylistPage.vue

147 lines
5.3 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-21 20:51:41 +00:00
<h1 class="text-center my-4" v-text="playlist.name" />
2022-08-11 10:57:55 +00:00
<div class="flex justify-between items-center">
2021-12-27 14:46:22 +00:00
<div>
<router-link class="link" :to="playlist.uploaderUrl || '/'">
2021-12-28 01:13:55 +00:00
<img :src="playlist.uploaderAvatar" loading="lazy" class="rounded-full" />
<strong v-text="playlist.uploader" />
</router-link>
2021-12-27 14:46:22 +00:00
</div>
<div>
2022-08-11 10:57:55 +00:00
<strong v-text="`${playlist.videos} ${$t('video.videos')}`" />
<br />
<button class="btn mr-1" v-if="authenticated && !isPipedPlaylist" @click="clonePlaylist">
{{ $t("actions.clone_playlist") }}<font-awesome-icon class="ml-3" icon="clone" />
</button>
<button class="btn mr-1" @click="downloadPlaylistAsTxt">
{{ $t("actions.download_as_txt") }}
</button>
<a class="btn" :href="getRssUrl">
<font-awesome-icon icon="rss" />
</a>
2021-12-27 14:46:22 +00:00
</div>
2021-07-04 18:57:57 +00:00
</div>
<hr />
2021-12-27 14:46:22 +00:00
<div class="video-grid">
<VideoItem
2022-04-07 02:33:25 +00:00
v-for="(video, index) in playlist.relatedStreams"
:key="video.url"
2022-11-01 12:12:54 +00:00
:item="video"
2022-04-07 02:33:25 +00:00
:index="index"
:playlist-id="$route.query.list"
:admin="admin"
@remove="removeVideo(index)"
height="94"
width="168"
/>
</div>
</div>
</template>
<script>
2022-04-08 15:46:49 +00:00
import ErrorHandler from "./ErrorHandler.vue";
import VideoItem from "./VideoItem.vue";
export default {
components: {
ErrorHandler,
VideoItem,
},
data() {
return {
playlist: null,
2022-04-07 02:33:25 +00:00
admin: false,
};
},
computed: {
getRssUrl: _this => {
return _this.authApiUrl() + "/rss/playlists/" + _this.$route.query.list;
},
2022-07-22 11:39:49 +00:00
isPipedPlaylist: _this => {
// regex to determine whether it's a Piped plalylist
2022-07-22 13:27:51 +00:00
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-21 20:51:41 +00:00
},
},
mounted() {
this.getPlaylistData();
2022-04-07 02:33:25 +00:00
const playlistId = this.$route.query.list;
if (this.authenticated && playlistId?.length == 36)
this.fetchJson(this.authApiUrl() + "/user/playlists", null, {
2022-04-07 02:33:25 +00:00
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-08 21:29:50 +00:00
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-08 21:29:50 +00:00
.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 09:35:41 +00:00
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 09:35:41 +00:00
});
}
},
2022-04-07 02:33:25 +00:00
removeVideo(index) {
this.playlist.relatedStreams.splice(index, 1);
},
2022-07-21 20:51:41 +00:00
async clonePlaylist() {
this.fetchJson(this.authApiUrl() + "/import/playlist", null, {
method: "POST",
headers: {
Authorization: this.getAuthToken(),
},
body: JSON.stringify({
2022-07-22 11:39:49 +00:00
playlistId: this.$route.query.list,
2022-07-21 20:51:41 +00:00
}),
}).then(resp => {
if (!resp.error) {
alert(this.$t("actions.clone_playlist_success"));
} else alert(resp.error);
});
},
2022-08-02 08:08:26 +00:00
downloadPlaylistAsTxt() {
var data = "";
this.playlist.relatedStreams.forEach(element => {
data += "https://piped.kavin.rocks" + element.url + "\n";
});
2022-08-02 08:16:18 +00:00
this.download(data, this.playlist.name + ".txt", "text/plain");
2022-08-02 08:08:26 +00:00
},
},
};
</script>