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

210 lines
8.2 KiB
Vue
Raw Normal View History

<template>
2022-11-12 02:58:34 +05:30
<ErrorHandler v-if="playlist && playlist.error" :message="playlist.message" :error="playlist.error" />
2023-07-27 17:16:05 +05:30
<LoadingIndicatorPage v-show="!playlist?.error" :show-content="playlist">
<h1 class="mb-1 ml-1 mt-4 text-3xl!" v-text="playlist.name" />
<CollapsableText v-if="playlist?.description" :text="playlist.description" />
2023-05-23 21:54:32 +05:30
<div class="mt-1 flex items-center justify-between">
2022-11-12 02:58:34 +05:30
<div>
2023-05-23 21:54:32 +05:30
<router-link class="link flex items-center gap-3" :to="playlist.uploaderUrl || '/'">
2022-11-12 02:58:34 +05:30
<img :src="playlist.uploaderAvatar" loading="lazy" class="rounded-full" />
<strong v-text="playlist.uploader" />
</router-link>
</div>
<div>
2023-07-27 17:16:05 +05:30
<strong class="mr-2" v-text="`${playlist.videos} ${$t('video.videos')}`" />
<button v-if="!isPipedPlaylist" class="btn mx-1" @click="bookmarkPlaylist">
{{ $t(`actions.${isBookmarked ? "playlist_bookmarked" : "bookmark_playlist"}`)
}}<font-awesome-icon class="ml-3" icon="bookmark" />
2023-01-07 00:00:28 +05:30
</button>
2023-07-27 17:16:05 +05:30
<button v-if="authenticated && !isPipedPlaylist" class="btn mr-1" @click="clonePlaylist">
2022-11-12 02:58:34 +05:30
{{ $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 mr-1" :href="getRssUrl">
<font-awesome-icon icon="rss" />
</a>
2023-07-27 17:16:05 +05:30
<WatchOnButton :link="`https://www.youtube.com/playlist?list=${$route.query.list}`" />
2022-11-12 02:58:34 +05:30
</div>
</div>
2022-11-12 02:58:34 +05:30
<hr />
2022-11-12 02:58:34 +05:30
<div class="video-grid">
<VideoItem
v-for="(video, index) in playlist.relatedStreams"
:key="video.url"
:item="video"
:index="index"
:playlist-id="$route.query.list"
:admin="admin"
height="94"
width="168"
2023-07-27 17:16:05 +05:30
@remove="removeVideo(index)"
2022-11-12 02:58:34 +05:30
/>
</div>
</LoadingIndicatorPage>
</template>
<script>
2022-11-12 02:58:34 +05:30
import ErrorHandler from "./ErrorHandler.vue";
import LoadingIndicatorPage from "./LoadingIndicatorPage.vue";
2023-05-23 21:54:32 +05:30
import CollapsableText from "./CollapsableText.vue";
2022-11-12 02:58:34 +05:30
import VideoItem from "./VideoItem.vue";
import WatchOnButton from "./WatchOnButton.vue";
2022-11-12 02:58:34 +05:30
export default {
components: {
ErrorHandler,
VideoItem,
WatchOnButton,
LoadingIndicatorPage,
2023-05-23 21:54:32 +05:30
CollapsableText,
2022-11-12 02:58:34 +05:30
},
data() {
return {
playlist: null,
admin: false,
isBookmarked: false,
2022-11-12 02:58:34 +05:30
};
},
computed: {
getRssUrl: _this => {
return _this.authApiUrl() + "/rss/playlists/" + _this.$route.query.list;
},
isPipedPlaylist: _this => {
// regex to determine whether it's a Piped plalylist
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,
);
},
},
mounted() {
const playlistId = this.$route.query.list;
if (this.authenticated && playlistId?.length == 36)
2023-06-15 22:48:47 +05:30
this.getPlaylists().then(json => {
2022-11-12 02:58:34 +05:30
if (json.error) alert(json.error);
2023-03-04 13:33:45 +05:30
else if (json.some(playlist => playlist.id === playlistId)) this.admin = true;
2022-11-12 02:58:34 +05:30
});
2023-06-15 22:48:47 +05:30
else if (playlistId.startsWith("local")) this.admin = true;
this.isPlaylistBookmarked();
2022-11-12 02:58:34 +05:30
},
activated() {
2023-05-31 22:01:40 +05:30
this.getPlaylistData();
2022-11-12 02:58:34 +05:30
window.addEventListener("scroll", this.handleScroll);
if (this.playlist) this.updateTitle();
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchPlaylist() {
2023-06-15 22:48:47 +05:30
const playlistId = this.$route.query.list;
if (playlistId.startsWith("local")) {
return this.getPlaylist(playlistId);
}
2022-11-12 02:58:34 +05:30
return await await this.fetchJson(this.authApiUrl() + "/playlists/" + this.$route.query.list);
},
async getPlaylistData() {
this.fetchPlaylist()
.then(data => (this.playlist = data))
.then(() => {
this.updateTitle();
this.updateWatched(this.playlist.relatedStreams);
this.fetchDeArrowContent(this.playlist.relatedStreams);
});
2022-11-12 02:58:34 +05:30
},
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 => {
this.playlist.relatedStreams.concat(json.relatedStreams);
this.playlist.nextpage = json.nextpage;
this.loading = false;
json.relatedStreams.map(stream => this.playlist.relatedStreams.push(stream));
this.fetchDeArrowContent(this.playlist.relatedStreams);
2022-11-12 02:58:34 +05:30
});
}
},
removeVideo(index) {
this.playlist.relatedStreams.splice(index, 1);
},
async clonePlaylist() {
this.fetchJson(this.authApiUrl() + "/import/playlist", null, {
method: "POST",
headers: {
Authorization: this.getAuthToken(),
},
body: JSON.stringify({
playlistId: this.$route.query.list,
}),
}).then(resp => {
if (!resp.error) {
alert(this.$t("actions.clone_playlist_success"));
} else alert(resp.error);
});
},
downloadPlaylistAsTxt() {
var data = "";
this.playlist.relatedStreams.forEach(element => {
data += "https://piped.video" + element.url + "\n";
});
this.download(data, this.playlist.name + ".txt", "text/plain");
},
2023-01-07 00:00:28 +05:30
async bookmarkPlaylist() {
if (!this.playlist) return;
if (this.isBookmarked) {
this.removePlaylistBookmark();
return;
}
2023-01-07 00:00:28 +05:30
if (window.db) {
const playlistId = this.$route.query.list;
var tx = window.db.transaction("playlist_bookmarks", "readwrite");
var store = tx.objectStore("playlist_bookmarks");
store.put({
playlistId: playlistId,
name: this.playlist.name,
uploader: this.playlist.uploader,
uploaderUrl: this.playlist.uploaderUrl,
thumbnail: this.playlist.thumbnailUrl,
uploaderAvatar: this.playlist.uploaderAvatar,
videos: this.playlist.videos,
});
this.isBookmarked = true;
2023-01-07 00:00:28 +05:30
}
},
async removePlaylistBookmark() {
var tx = window.db.transaction("playlist_bookmarks", "readwrite");
var store = tx.objectStore("playlist_bookmarks");
store.delete(this.$route.query.list);
this.isBookmarked = false;
},
async isPlaylistBookmarked() {
// needed in order to change the is bookmarked var later
const App = this;
const playlistId = this.$route.query.list;
var tx = window.db.transaction("playlist_bookmarks", "readwrite");
var store = tx.objectStore("playlist_bookmarks");
var req = store.openCursor(playlistId);
req.onsuccess = function (e) {
var cursor = e.target.result;
App.isBookmarked = cursor ? true : false;
};
},
2022-11-12 02:58:34 +05:30
},
};
</script>