2021-07-22 20:05:48 +00:00
|
|
|
<template>
|
2023-08-13 17:31:57 +00:00
|
|
|
<h1 v-t="'titles.subscriptions'" class="my-4 text-center font-bold" />
|
2022-11-26 11:04:12 +00:00
|
|
|
<!-- import / export section -->
|
2023-12-02 08:23:30 +00:00
|
|
|
<div class="flex flex-wrap justify-between">
|
|
|
|
<div class="flex gap-1">
|
|
|
|
<!-- import json/csv -->
|
2023-08-23 14:15:43 +00:00
|
|
|
<button class="btn">
|
|
|
|
<router-link v-t="'actions.import_from_json_csv'" to="/import" />
|
2022-07-27 05:52:25 +00:00
|
|
|
</button>
|
2023-12-02 08:23:30 +00:00
|
|
|
<!-- export to json -->
|
2023-07-27 11:46:05 +00:00
|
|
|
<button v-t="'actions.export_to_json'" class="btn" @click="exportHandler" />
|
2023-12-02 08:23:30 +00:00
|
|
|
</div>
|
2023-12-19 15:44:16 +00:00
|
|
|
<div class="m-1 flex flex-wrap gap-1">
|
2023-12-02 08:23:30 +00:00
|
|
|
<!-- import channel groups to json-->
|
|
|
|
<div>
|
|
|
|
<label
|
|
|
|
for="fileSelector"
|
|
|
|
class="btn"
|
|
|
|
v-text="`${$t('actions.import_from_json')} (${$t('titles.channel_groups')})`"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
id="fileSelector"
|
|
|
|
ref="fileSelector"
|
|
|
|
type="file"
|
|
|
|
class="hidden"
|
|
|
|
multiple="multiple"
|
|
|
|
@change="importGroupsHandler"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- export channel groups to json -->
|
2023-08-23 14:15:43 +00:00
|
|
|
<button
|
|
|
|
class="btn"
|
|
|
|
@click="exportGroupsHandler"
|
|
|
|
v-text="`${$t('actions.export_to_json')} (${$t('titles.channel_groups')})`"
|
|
|
|
/>
|
2022-07-27 05:52:25 +00:00
|
|
|
</div>
|
2023-12-19 15:44:16 +00:00
|
|
|
<div class="flex self-center gap-1">
|
2023-12-02 08:23:30 +00:00
|
|
|
<!-- subscriptions count, only shown if there are any -->
|
|
|
|
<i18n-t v-if="subscriptions.length > 0" keypath="subscriptions.subscribed_channels_count">{{
|
|
|
|
subscriptions.length
|
|
|
|
}}</i18n-t>
|
|
|
|
</div>
|
2021-09-04 18:30:13 +00:00
|
|
|
</div>
|
2022-11-26 12:04:57 +00:00
|
|
|
<br />
|
2021-10-08 18:52:51 +00:00
|
|
|
<hr />
|
2023-05-07 17:56:56 +00:00
|
|
|
<div class="w-full flex flex-wrap">
|
|
|
|
<button
|
|
|
|
v-for="group in channelGroups"
|
2023-07-27 11:46:05 +00:00
|
|
|
:key="group.groupName"
|
2023-05-07 17:56:56 +00:00
|
|
|
class="btn mx-1 w-max"
|
|
|
|
:class="{ selected: selectedGroup === group }"
|
2023-07-28 16:49:16 +00:00
|
|
|
@click="selectGroup(group)"
|
2023-05-07 17:56:56 +00:00
|
|
|
>
|
|
|
|
<span v-text="group.groupName !== '' ? group.groupName : $t('video.all')" />
|
|
|
|
<div v-if="group.groupName != '' && selectedGroup == group">
|
|
|
|
<font-awesome-icon class="mx-2" icon="edit" @click="showEditGroupModal = true" />
|
|
|
|
<font-awesome-icon class="mx-2" icon="circle-minus" @click="deleteGroup(group)" />
|
|
|
|
</div>
|
|
|
|
</button>
|
2023-10-27 14:25:40 +00:00
|
|
|
<button class="btn mx-1" @click="showCreateGroupModal = true">
|
|
|
|
<font-awesome-icon icon="circle-plus" />
|
2023-05-07 17:56:56 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<br />
|
|
|
|
<hr />
|
2022-11-26 11:04:12 +00:00
|
|
|
<!-- Subscriptions card list -->
|
2022-11-26 11:23:07 +00:00
|
|
|
<div class="xl:grid xl:grid-cols-5 <md:flex-wrap">
|
2022-11-26 11:04:12 +00:00
|
|
|
<!-- channel info card -->
|
|
|
|
<div
|
2023-05-07 17:56:56 +00:00
|
|
|
v-for="subscription in filteredSubscriptions"
|
2022-11-26 11:04:12 +00:00
|
|
|
:key="subscription.url"
|
2023-08-13 17:31:57 +00:00
|
|
|
class="col m-2 border border-gray-500 rounded-lg p-1"
|
2022-11-26 11:04:12 +00:00
|
|
|
>
|
2023-08-13 17:31:57 +00:00
|
|
|
<router-link :to="subscription.url" class="text-4x4 flex p-2 font-bold">
|
|
|
|
<img :src="subscription.avatar" class="h-[fit-content] rounded-full" width="48" height="48" />
|
|
|
|
<span class="mx-2 self-center" v-text="subscription.name" />
|
2022-11-26 11:04:12 +00:00
|
|
|
</router-link>
|
|
|
|
<!-- subscribe / unsubscribe btn -->
|
|
|
|
<button
|
2023-07-27 11:46:05 +00:00
|
|
|
v-t="`actions.${subscription.subscribed ? 'unsubscribe' : 'subscribe'}`"
|
2023-08-13 17:31:57 +00:00
|
|
|
class="btn mt-2 w-full"
|
2022-11-26 11:04:12 +00:00
|
|
|
@click="handleButton(subscription)"
|
|
|
|
/>
|
2021-07-22 20:05:48 +00:00
|
|
|
</div>
|
2021-10-08 18:52:51 +00:00
|
|
|
</div>
|
2021-09-04 18:30:13 +00:00
|
|
|
<br />
|
2023-05-07 17:56:56 +00:00
|
|
|
|
2023-12-19 15:44:16 +00:00
|
|
|
<CreateGroupModal
|
|
|
|
v-if="showCreateGroupModal"
|
|
|
|
:on-create-group="createGroup"
|
|
|
|
@close="showCreateGroupModal = false"
|
|
|
|
/>
|
2023-05-07 17:56:56 +00:00
|
|
|
|
|
|
|
<ModalComponent v-if="showEditGroupModal" @close="showEditGroupModal = false">
|
2023-08-13 17:31:57 +00:00
|
|
|
<div class="mb-5 mt-3 flex justify-between">
|
2023-07-28 16:49:16 +00:00
|
|
|
<input v-model="editedGroupName" type="text" class="input" />
|
|
|
|
<button v-t="'actions.okay'" class="btn" :placeholder="$t('actions.group_name')" @click="editGroupName()" />
|
|
|
|
</div>
|
2023-10-27 14:20:29 +00:00
|
|
|
<div class="mb-2 mt-3 h-[80vh] flex flex-col overflow-y-scroll pr-2">
|
2023-05-07 17:56:56 +00:00
|
|
|
<div v-for="subscription in subscriptions" :key="subscription.name">
|
2023-09-11 16:51:12 +00:00
|
|
|
<div class="mr-3 flex items-center justify-between">
|
|
|
|
<a :href="subscription.url" target="_blank" class="flex items-center overflow-hidden">
|
|
|
|
<img :src="subscription.avatar" class="h-8 w-8 rounded-full" />
|
|
|
|
<span class="ml-2">{{ subscription.name }}</span>
|
|
|
|
</a>
|
2023-05-08 12:13:32 +00:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
class="checkbox"
|
|
|
|
:checked="selectedGroup.channels.includes(subscription.url.substr(-11))"
|
|
|
|
@change="checkedChange(subscription)"
|
2023-05-07 17:56:56 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ModalComponent>
|
2021-07-22 20:05:48 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-07 17:56:56 +00:00
|
|
|
import ModalComponent from "./ModalComponent.vue";
|
2023-12-19 15:44:16 +00:00
|
|
|
import CreateGroupModal from "./CreateGroupModal.vue";
|
2023-05-07 17:56:56 +00:00
|
|
|
|
2021-07-22 20:05:48 +00:00
|
|
|
export default {
|
2023-12-19 15:44:16 +00:00
|
|
|
components: { ModalComponent, CreateGroupModal },
|
2021-07-22 20:05:48 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
subscriptions: [],
|
2023-05-07 17:56:56 +00:00
|
|
|
selectedGroup: {
|
|
|
|
groupName: "",
|
|
|
|
channels: [],
|
|
|
|
},
|
|
|
|
channelGroups: [],
|
|
|
|
showCreateGroupModal: false,
|
|
|
|
showEditGroupModal: false,
|
2023-07-28 16:49:16 +00:00
|
|
|
editedGroupName: "",
|
2021-07-22 20:05:48 +00:00
|
|
|
};
|
|
|
|
},
|
2023-07-27 11:46:05 +00:00
|
|
|
computed: {
|
|
|
|
filteredSubscriptions(_this) {
|
|
|
|
return _this.selectedGroup.groupName == ""
|
|
|
|
? _this.subscriptions
|
|
|
|
: _this.subscriptions.filter(channel => _this.selectedGroup.channels.includes(channel.url.substr(-11)));
|
|
|
|
},
|
|
|
|
},
|
2021-07-22 20:05:48 +00:00
|
|
|
mounted() {
|
2022-08-01 14:16:06 +00:00
|
|
|
this.fetchSubscriptions().then(json => {
|
|
|
|
this.subscriptions = json;
|
|
|
|
this.subscriptions.forEach(subscription => (subscription.subscribed = true));
|
|
|
|
});
|
2023-05-07 17:56:56 +00:00
|
|
|
|
2023-05-08 12:13:32 +00:00
|
|
|
this.channelGroups.push(this.selectedGroup);
|
2023-05-07 17:56:56 +00:00
|
|
|
|
|
|
|
if (!window.db) return;
|
2023-09-14 15:04:04 +00:00
|
|
|
|
|
|
|
this.loadChannelGroups();
|
2021-07-22 20:05:48 +00:00
|
|
|
},
|
|
|
|
activated() {
|
|
|
|
document.title = "Subscriptions - Piped";
|
|
|
|
},
|
|
|
|
methods: {
|
2022-08-01 14:16:06 +00:00
|
|
|
async fetchSubscriptions() {
|
|
|
|
if (this.authenticated) {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/subscriptions", null, {
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
2024-01-03 20:45:28 +00:00
|
|
|
const channels = this.getUnauthenticatedChannels();
|
|
|
|
const split = channels.split(",");
|
|
|
|
if (split.length > 100) {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/subscriptions/unauthenticated", null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify(split),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/subscriptions/unauthenticated", {
|
|
|
|
channels: this.getUnauthenticatedChannels(),
|
|
|
|
});
|
|
|
|
}
|
2022-08-01 14:16:06 +00:00
|
|
|
}
|
|
|
|
},
|
2023-09-14 15:04:04 +00:00
|
|
|
async loadChannelGroups() {
|
|
|
|
const groups = await this.getChannelGroups();
|
|
|
|
this.channelGroups.push(...groups);
|
|
|
|
},
|
2021-07-22 20:05:48 +00:00
|
|
|
handleButton(subscription) {
|
2022-08-01 16:29:49 +00:00
|
|
|
const channelId = subscription.url.split("/")[2];
|
|
|
|
if (this.authenticated) {
|
|
|
|
this.fetchJson(this.authApiUrl() + (subscription.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: channelId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.handleLocalSubscriptions(channelId);
|
|
|
|
}
|
2021-07-22 20:05:48 +00:00
|
|
|
subscription.subscribed = !subscription.subscribed;
|
|
|
|
},
|
2021-07-31 18:48:38 +00:00
|
|
|
exportHandler() {
|
|
|
|
const subscriptions = [];
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
subscriptions.push({
|
|
|
|
url: "https://www.youtube.com" + subscription.url,
|
|
|
|
name: subscription.name,
|
|
|
|
service_id: 0,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const json = JSON.stringify({
|
|
|
|
app_version: "",
|
|
|
|
app_version_int: 0,
|
|
|
|
subscriptions: subscriptions,
|
|
|
|
});
|
2022-08-02 08:14:03 +00:00
|
|
|
this.download(json, "subscriptions.json", "application/json");
|
2021-07-31 18:48:38 +00:00
|
|
|
},
|
2023-07-28 16:49:16 +00:00
|
|
|
selectGroup(group) {
|
|
|
|
this.selectedGroup = group;
|
|
|
|
this.editedGroupName = group.groupName;
|
|
|
|
},
|
2023-12-19 15:44:16 +00:00
|
|
|
createGroup(newGroupName) {
|
|
|
|
if (!newGroupName || this.channelGroups.some(group => group.groupName == newGroupName)) return;
|
2023-05-07 17:56:56 +00:00
|
|
|
|
|
|
|
const newGroup = {
|
2023-12-19 15:44:16 +00:00
|
|
|
groupName: newGroupName,
|
2023-05-07 17:56:56 +00:00
|
|
|
channels: [],
|
|
|
|
};
|
2023-05-08 12:13:32 +00:00
|
|
|
this.channelGroups.push(newGroup);
|
2023-05-07 17:56:56 +00:00
|
|
|
this.createOrUpdateChannelGroup(newGroup);
|
|
|
|
|
|
|
|
this.showCreateGroupModal = false;
|
|
|
|
},
|
2023-07-28 16:49:16 +00:00
|
|
|
editGroupName() {
|
|
|
|
const oldGroupName = this.selectedGroup.groupName;
|
|
|
|
const newGroupName = this.editedGroupName;
|
|
|
|
|
|
|
|
// the group mustn't yet exist and the name can't be empty
|
|
|
|
if (!newGroupName || newGroupName == oldGroupName) return;
|
|
|
|
if (this.channelGroups.some(group => group.groupName == newGroupName)) return;
|
|
|
|
|
|
|
|
// create a new group with the same info and delete the old one
|
|
|
|
this.selectedGroup.groupName = newGroupName;
|
|
|
|
this.createOrUpdateChannelGroup(this.selectedGroup);
|
|
|
|
this.deleteChannelGroup(oldGroupName);
|
|
|
|
|
|
|
|
this.showEditGroupModal = false;
|
|
|
|
},
|
2023-05-07 17:56:56 +00:00
|
|
|
deleteGroup(group) {
|
|
|
|
this.deleteChannelGroup(group.groupName);
|
|
|
|
this.channelGroups = this.channelGroups.filter(g => g != group);
|
|
|
|
this.selectedGroup = this.channelGroups[0];
|
|
|
|
},
|
|
|
|
checkedChange(subscription) {
|
|
|
|
const channelId = subscription.url.substr(-11);
|
|
|
|
this.selectedGroup.channels = this.selectedGroup.channels.includes(channelId)
|
|
|
|
? this.selectedGroup.channels.filter(channel => channel != channelId)
|
|
|
|
: this.selectedGroup.channels.concat(channelId);
|
|
|
|
this.createOrUpdateChannelGroup(this.selectedGroup);
|
|
|
|
},
|
2023-08-23 14:15:43 +00:00
|
|
|
async importGroupsHandler() {
|
|
|
|
const files = this.$refs.fileSelector.files;
|
|
|
|
for (let file of files) {
|
|
|
|
const groups = JSON.parse(await file.text()).groups;
|
|
|
|
for (let group of groups) {
|
|
|
|
this.createOrUpdateChannelGroup(group);
|
|
|
|
this.channelGroups.push(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
exportGroupsHandler() {
|
|
|
|
const json = {
|
|
|
|
format: "Piped",
|
|
|
|
version: 1,
|
|
|
|
groups: this.channelGroups.slice(1),
|
|
|
|
};
|
|
|
|
this.download(JSON.stringify(json), "channel_groups.json", "application/json");
|
|
|
|
},
|
2021-07-22 20:05:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2023-05-07 17:56:56 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.selected {
|
|
|
|
border: 0.1rem outset red;
|
|
|
|
}
|
|
|
|
</style>
|