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

166 lines
6.2 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" />
2022-08-11 16:27:55 +05:30
<div class="flex justify-between items-center">
2021-12-27 20:16:22 +05:30
<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>
2022-08-11 16:27:55 +05:30
<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>
2022-11-02 21:40:27 +05:30
<a class="btn mr-1" :href="getRssUrl">
2022-08-11 16:27:55 +05:30
<font-awesome-icon icon="rss" />
</a>
2022-11-02 21:40:27 +05:30
<!-- Watch on YouTube button: For large screens -->
<a
v-if="this.getPreferenceBoolean('showWatchOnYouTube', false)"
:href="`https://www.youtube.com/playlist?list=${this.$route.query.list}`"
class="btn lt-lg:hidden"
>
<i18n-t keypath="player.watch_on" tag="strong">
<font-awesome-icon class="mx-1.5" :icon="['fab', 'youtube']" />
</i18n-t>
</a>
<!-- Watch on YouTube button: For small screens -->
<a
v-if="this.getPreferenceBoolean('showWatchOnYouTube', false)"
:href="`https://www.youtube.com/playlist?list=${this.$route.query.list}`"
class="btn lg:hidden"
>
<font-awesome-icon class="mx-1.5" :icon="['fab', 'youtube']" />
</a>
2021-12-27 20:16:22 +05:30
</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"
2022-11-01 17:42:54 +05:30
:item="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);
});
},
2022-08-02 13:38:26 +05:30
downloadPlaylistAsTxt() {
var data = "";
this.playlist.relatedStreams.forEach(element => {
data += "https://piped.kavin.rocks" + element.url + "\n";
});
2022-08-02 13:46:18 +05:30
this.download(data, this.playlist.name + ".txt", "text/plain");
2022-08-02 13:38:26 +05:30
},
},
};
</script>