2021-04-07 11:45:40 +00:00
|
|
|
import { createApp } from "vue";
|
2021-12-28 14:39:20 +00:00
|
|
|
import router from "@/router/router.js";
|
2021-04-07 11:45:40 +00:00
|
|
|
import App from "./App.vue";
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
import TimeAgo from "javascript-time-ago";
|
|
|
|
|
|
|
|
import en from "javascript-time-ago/locale/en";
|
|
|
|
|
|
|
|
TimeAgo.addDefaultLocale(en);
|
|
|
|
|
2021-08-25 16:30:21 +00:00
|
|
|
import { createI18n } from "vue-i18n";
|
|
|
|
import enLocale from "@/locales/en.json";
|
2022-08-17 13:34:57 +00:00
|
|
|
import "@unocss/reset/tailwind.css";
|
|
|
|
import "uno.css";
|
2021-08-25 16:30:21 +00:00
|
|
|
|
2021-07-16 22:56:41 +00:00
|
|
|
const timeAgo = new TimeAgo("en-US");
|
|
|
|
|
2021-05-10 18:14:28 +00:00
|
|
|
import("./registerServiceWorker");
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2020-11-27 06:46:36 +00:00
|
|
|
const mixin = {
|
|
|
|
methods: {
|
2022-01-01 14:42:20 +00:00
|
|
|
timeFormat: function (duration) {
|
|
|
|
var pad = function (num, size) {
|
2020-11-27 06:46:36 +00:00
|
|
|
return ("000" + num).slice(size * -1);
|
|
|
|
};
|
|
|
|
|
|
|
|
var time = parseFloat(duration).toFixed(3),
|
|
|
|
hours = Math.floor(time / 60 / 60),
|
|
|
|
minutes = Math.floor(time / 60) % 60,
|
|
|
|
seconds = Math.floor(time - minutes * 60);
|
|
|
|
|
|
|
|
var str = "";
|
|
|
|
|
2021-01-07 08:03:10 +00:00
|
|
|
if (hours > 0) str += hours + ":";
|
2020-11-27 06:46:36 +00:00
|
|
|
|
|
|
|
str += pad(minutes, 2) + ":" + pad(seconds, 2);
|
|
|
|
|
|
|
|
return str;
|
2021-02-24 09:35:41 +00:00
|
|
|
},
|
2021-05-30 22:06:35 +00:00
|
|
|
numberFormat(num) {
|
2022-11-03 19:54:00 +00:00
|
|
|
var loc = `${this.getPreferenceString("hl")}-${this.getPreferenceString("region")}`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Intl.getCanonicalLocales(loc);
|
|
|
|
} catch {
|
|
|
|
loc = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const formatter = Intl.NumberFormat(loc, {
|
|
|
|
notation: "compact",
|
|
|
|
});
|
2022-10-22 15:54:44 +00:00
|
|
|
return formatter.format(num);
|
2021-05-30 22:06:35 +00:00
|
|
|
},
|
2021-06-02 18:52:58 +00:00
|
|
|
addCommas(num) {
|
2021-07-03 19:33:59 +00:00
|
|
|
num = parseInt(num);
|
|
|
|
return num.toLocaleString("en-US");
|
2021-06-02 18:52:58 +00:00
|
|
|
},
|
2022-01-01 14:42:20 +00:00
|
|
|
fetchJson: function (url, params, options) {
|
2021-06-15 11:37:35 +00:00
|
|
|
if (params) {
|
|
|
|
url = new URL(url);
|
2021-07-03 19:33:59 +00:00
|
|
|
for (var param in params) url.searchParams.set(param, params[param]);
|
2021-06-15 11:37:35 +00:00
|
|
|
}
|
2021-04-07 11:45:40 +00:00
|
|
|
return fetch(url, options).then(response => {
|
|
|
|
return response.json();
|
|
|
|
});
|
|
|
|
},
|
2022-11-16 18:51:56 +00:00
|
|
|
setPreference(key, value, disableAlert = false) {
|
2022-11-07 10:20:13 +00:00
|
|
|
try {
|
|
|
|
localStorage.setItem(key, value);
|
|
|
|
} catch {
|
2022-11-16 18:51:56 +00:00
|
|
|
if (!disableAlert) alert(this.$t("info.local_storage"));
|
2022-11-07 10:20:13 +00:00
|
|
|
}
|
2021-07-03 19:24:09 +00:00
|
|
|
},
|
|
|
|
getPreferenceBoolean(key, defaultVal) {
|
|
|
|
var value;
|
2021-07-03 19:33:59 +00:00
|
|
|
if (
|
2021-08-25 16:30:21 +00:00
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 12:00:17 +00:00
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-03 19:33:59 +00:00
|
|
|
) {
|
2021-08-25 16:30:21 +00:00
|
|
|
switch (String(value).toLowerCase()) {
|
2021-07-03 19:24:09 +00:00
|
|
|
case "true":
|
|
|
|
case "1":
|
|
|
|
case "on":
|
|
|
|
case "yes":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
|
|
|
getPreferenceString(key, defaultVal) {
|
|
|
|
var value;
|
2021-07-03 19:33:59 +00:00
|
|
|
if (
|
2021-08-25 16:30:21 +00:00
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 12:00:17 +00:00
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-03 19:33:59 +00:00
|
|
|
) {
|
2021-07-03 19:24:09 +00:00
|
|
|
return value;
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
2021-07-04 18:26:02 +00:00
|
|
|
getPreferenceNumber(key, defaultVal) {
|
|
|
|
var value;
|
|
|
|
if (
|
2021-08-25 16:30:21 +00:00
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
2021-08-28 12:00:17 +00:00
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
2021-07-04 18:26:02 +00:00
|
|
|
) {
|
2023-03-20 00:44:10 +00:00
|
|
|
const num = Number(value);
|
|
|
|
return isNaN(num) ? defaultVal : num;
|
2021-07-04 18:26:02 +00:00
|
|
|
} else return defaultVal;
|
|
|
|
},
|
2023-02-02 13:25:45 +00:00
|
|
|
getPreferenceJSON(key, defaultVal) {
|
|
|
|
var value;
|
|
|
|
if (
|
|
|
|
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
|
|
|
|
(this.testLocalStorage && (value = localStorage.getItem(key)) !== null)
|
|
|
|
) {
|
|
|
|
return JSON.parse(value);
|
|
|
|
} else return defaultVal;
|
|
|
|
},
|
2021-07-04 18:26:02 +00:00
|
|
|
apiUrl() {
|
2024-03-13 16:49:40 +00:00
|
|
|
return this.getPreferenceString("instance", import.meta.env.VITE_PIPED_API);
|
2021-07-04 18:26:02 +00:00
|
|
|
},
|
2022-07-21 04:04:57 +00:00
|
|
|
authApiUrl() {
|
|
|
|
if (this.getPreferenceBoolean("authInstance", false)) {
|
|
|
|
return this.getPreferenceString("auth_instance_url", this.apiUrl());
|
|
|
|
} else return this.apiUrl();
|
|
|
|
},
|
2021-07-16 22:56:41 +00:00
|
|
|
getAuthToken() {
|
2022-07-21 04:04:57 +00:00
|
|
|
return this.getPreferenceString("authToken" + this.hashCode(this.authApiUrl()));
|
2021-07-16 22:56:41 +00:00
|
|
|
},
|
|
|
|
hashCode(s) {
|
2022-01-01 14:42:20 +00:00
|
|
|
return s.split("").reduce(function (a, b) {
|
2021-07-16 22:56:41 +00:00
|
|
|
a = (a << 5) - a + b.charCodeAt(0);
|
|
|
|
return a & a;
|
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
timeAgo(time) {
|
|
|
|
return timeAgo.format(time);
|
|
|
|
},
|
2021-08-22 10:27:09 +00:00
|
|
|
async updateWatched(videos) {
|
2023-01-13 13:40:12 +00:00
|
|
|
if (window.db && this.getPreferenceBoolean("watchHistory", false)) {
|
2021-08-22 10:27:09 +00:00
|
|
|
var tx = window.db.transaction("watch_history", "readonly");
|
|
|
|
var store = tx.objectStore("watch_history");
|
|
|
|
videos.map(async video => {
|
|
|
|
var request = store.get(video.url.substr(-11));
|
2022-01-01 14:42:20 +00:00
|
|
|
request.onsuccess = function (event) {
|
2021-08-22 10:27:09 +00:00
|
|
|
if (event.target.result) {
|
|
|
|
video.watched = true;
|
2023-02-16 17:26:14 +00:00
|
|
|
video.currentTime = event.target.result.currentTime;
|
2021-08-22 10:27:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-08-01 14:16:06 +00:00
|
|
|
getLocalSubscriptions() {
|
2022-11-07 10:20:13 +00:00
|
|
|
try {
|
|
|
|
return JSON.parse(localStorage.getItem("localSubscriptions"));
|
|
|
|
} catch {
|
|
|
|
return [];
|
|
|
|
}
|
2022-08-01 14:16:06 +00:00
|
|
|
},
|
|
|
|
isSubscribedLocally(channelId) {
|
|
|
|
const localSubscriptions = this.getLocalSubscriptions();
|
|
|
|
if (localSubscriptions == null) return false;
|
|
|
|
return localSubscriptions.includes(channelId);
|
|
|
|
},
|
|
|
|
handleLocalSubscriptions(channelId) {
|
|
|
|
var localSubscriptions = this.getLocalSubscriptions() ?? [];
|
|
|
|
if (localSubscriptions.includes(channelId))
|
2023-01-10 18:30:16 +00:00
|
|
|
localSubscriptions.splice(localSubscriptions.indexOf(channelId), 1);
|
2022-08-01 14:16:06 +00:00
|
|
|
else localSubscriptions.push(channelId);
|
|
|
|
// Sort for better cache hits
|
|
|
|
localSubscriptions.sort();
|
2022-11-07 10:20:13 +00:00
|
|
|
try {
|
|
|
|
localStorage.setItem("localSubscriptions", JSON.stringify(localSubscriptions));
|
|
|
|
return true;
|
|
|
|
} catch {
|
|
|
|
alert(this.$t("info.local_storage"));
|
|
|
|
}
|
|
|
|
return false;
|
2022-08-01 14:16:06 +00:00
|
|
|
},
|
|
|
|
getUnauthenticatedChannels() {
|
2022-08-04 06:08:04 +00:00
|
|
|
const localSubscriptions = this.getLocalSubscriptions() ?? [];
|
2022-08-01 14:16:06 +00:00
|
|
|
return localSubscriptions.join(",");
|
|
|
|
},
|
2024-01-11 19:28:36 +00:00
|
|
|
async fetchSubscriptions() {
|
|
|
|
if (this.authenticated) {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/subscriptions", null, {
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
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(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-04-06 10:05:16 +00:00
|
|
|
async fetchFeed() {
|
|
|
|
if (this.authenticated) {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/feed", {
|
|
|
|
authToken: this.getAuthToken(),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const channels = this.getUnauthenticatedChannels();
|
|
|
|
const split = channels.split(",");
|
|
|
|
if (split.length > 100) {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify(split),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", {
|
|
|
|
channels: channels,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-08-02 08:14:03 +00:00
|
|
|
/* generate a temporary file and ask the user to download it */
|
2023-01-27 16:27:40 +00:00
|
|
|
download(text, filename, mimeType) {
|
|
|
|
var file = new Blob([text], { type: mimeType });
|
2022-08-02 08:14:03 +00:00
|
|
|
|
|
|
|
const elem = document.createElement("a");
|
|
|
|
|
|
|
|
elem.href = URL.createObjectURL(file);
|
|
|
|
elem.download = filename;
|
|
|
|
elem.click();
|
|
|
|
elem.remove();
|
2022-08-02 08:08:26 +00:00
|
|
|
},
|
2023-09-14 15:04:04 +00:00
|
|
|
async getChannelGroups() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let channelGroups = [];
|
|
|
|
var tx = window.db.transaction("channel_groups", "readonly");
|
|
|
|
var store = tx.objectStore("channel_groups");
|
|
|
|
const cursor = store.index("groupName").openCursor();
|
|
|
|
cursor.onsuccess = e => {
|
|
|
|
const cursor = e.target.result;
|
|
|
|
if (cursor) {
|
|
|
|
const group = cursor.value;
|
|
|
|
channelGroups.push({
|
|
|
|
groupName: group.groupName,
|
|
|
|
channels: JSON.parse(group.channels),
|
|
|
|
});
|
|
|
|
cursor.continue();
|
|
|
|
} else {
|
|
|
|
resolve(channelGroups);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2023-05-07 17:56:56 +00:00
|
|
|
},
|
|
|
|
createOrUpdateChannelGroup(group) {
|
|
|
|
var tx = window.db.transaction("channel_groups", "readwrite");
|
|
|
|
var store = tx.objectStore("channel_groups");
|
|
|
|
store.put({
|
|
|
|
groupName: group.groupName,
|
|
|
|
channels: JSON.stringify(group.channels),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteChannelGroup(groupName) {
|
|
|
|
var tx = window.db.transaction("channel_groups", "readwrite");
|
|
|
|
var store = tx.objectStore("channel_groups");
|
|
|
|
store.delete(groupName);
|
|
|
|
},
|
2023-06-15 17:18:47 +00:00
|
|
|
async getLocalPlaylist(playlistId) {
|
2023-06-19 12:28:09 +00:00
|
|
|
return await new Promise(resolve => {
|
|
|
|
var tx = window.db.transaction("playlists", "readonly");
|
|
|
|
var store = tx.objectStore("playlists");
|
|
|
|
const req = store.openCursor(playlistId);
|
|
|
|
let playlist = null;
|
|
|
|
req.onsuccess = e => {
|
|
|
|
playlist = e.target.result.value;
|
|
|
|
playlist.videos = JSON.parse(playlist.videoIds).length;
|
|
|
|
resolve(playlist);
|
|
|
|
};
|
|
|
|
});
|
2023-06-15 17:18:47 +00:00
|
|
|
},
|
|
|
|
createOrUpdateLocalPlaylist(playlist) {
|
|
|
|
var tx = window.db.transaction("playlists", "readwrite");
|
|
|
|
var store = tx.objectStore("playlists");
|
|
|
|
store.put(playlist);
|
|
|
|
},
|
|
|
|
// needs to handle both, streamInfo items and streams items
|
|
|
|
createLocalPlaylistVideo(videoId, videoInfo) {
|
2023-06-15 21:03:57 +00:00
|
|
|
if (videoInfo === undefined || videoId === null || videoInfo?.error) return;
|
2023-06-15 17:18:47 +00:00
|
|
|
|
2023-06-15 21:03:57 +00:00
|
|
|
var tx = window.db.transaction("playlist_videos", "readwrite");
|
|
|
|
var store = tx.objectStore("playlist_videos");
|
2023-06-15 17:18:47 +00:00
|
|
|
const video = {
|
|
|
|
videoId: videoId,
|
|
|
|
title: videoInfo.title,
|
|
|
|
type: "stream",
|
|
|
|
shortDescription: videoInfo.shortDescription ?? videoInfo.description,
|
|
|
|
url: `/watch?v=${videoId}`,
|
2023-06-15 20:41:26 +00:00
|
|
|
thumbnail: videoInfo.thumbnail ?? videoInfo.thumbnailUrl,
|
2023-06-15 17:18:47 +00:00
|
|
|
uploaderVerified: videoInfo.uploaderVerified,
|
|
|
|
duration: videoInfo.duration,
|
|
|
|
uploaderAvatar: videoInfo.uploaderAvatar,
|
|
|
|
uploaderUrl: videoInfo.uploaderUrl,
|
|
|
|
uploaderName: videoInfo.uploaderName ?? videoInfo.uploader,
|
|
|
|
};
|
|
|
|
store.put(video);
|
|
|
|
},
|
|
|
|
async getLocalPlaylistVideo(videoId) {
|
2023-06-19 12:28:09 +00:00
|
|
|
return await new Promise(resolve => {
|
|
|
|
var tx = window.db.transaction("playlist_videos", "readonly");
|
|
|
|
var store = tx.objectStore("playlist_videos");
|
|
|
|
const req = store.openCursor(videoId);
|
|
|
|
req.onsuccess = e => {
|
|
|
|
resolve(e.target.result.value);
|
|
|
|
};
|
|
|
|
});
|
2023-06-15 17:18:47 +00:00
|
|
|
},
|
2023-06-15 15:32:32 +00:00
|
|
|
async getPlaylists() {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
|
|
|
if (!window.db) return [];
|
2023-06-19 12:28:09 +00:00
|
|
|
return await new Promise(resolve => {
|
|
|
|
let playlists = [];
|
|
|
|
var tx = window.db.transaction("playlists", "readonly");
|
|
|
|
var store = tx.objectStore("playlists");
|
|
|
|
const cursorRequest = store.openCursor();
|
|
|
|
cursorRequest.onsuccess = e => {
|
|
|
|
const cursor = e.target.result;
|
|
|
|
if (cursor) {
|
|
|
|
let playlist = cursor.value;
|
|
|
|
playlist.videos = JSON.parse(playlist.videoIds).length;
|
|
|
|
playlists.push(playlist);
|
|
|
|
cursor.continue();
|
|
|
|
} else {
|
|
|
|
resolve(playlists);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2023-06-15 17:18:47 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists", null, {
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async getPlaylist(playlistId) {
|
2024-01-25 10:48:13 +00:00
|
|
|
if (playlistId.startsWith("local")) {
|
2023-06-15 17:18:47 +00:00
|
|
|
const playlist = await this.getLocalPlaylist(playlistId);
|
|
|
|
const videoIds = JSON.parse(playlist.videoIds);
|
|
|
|
const videosFuture = videoIds.map(videoId => this.getLocalPlaylistVideo(videoId));
|
2023-06-15 20:41:26 +00:00
|
|
|
playlist.relatedStreams = await Promise.all(videosFuture);
|
2023-06-15 17:18:47 +00:00
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/playlists/" + playlistId);
|
|
|
|
},
|
|
|
|
async createPlaylist(name) {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
2023-06-15 20:41:26 +00:00
|
|
|
const uuid = crypto.randomUUID();
|
|
|
|
const playlistId = `local-${uuid}`;
|
2023-06-15 17:18:47 +00:00
|
|
|
this.createOrUpdateLocalPlaylist({
|
|
|
|
playlistId: playlistId,
|
|
|
|
// remapping needed for the playlists page
|
|
|
|
id: playlistId,
|
|
|
|
name: name,
|
|
|
|
description: "",
|
2024-03-13 16:49:40 +00:00
|
|
|
thumbnail: import.meta.env.VITE_PIPED_PROXY + "/?host=i.ytimg.com",
|
2023-06-15 17:18:47 +00:00
|
|
|
videoIds: "[]", // empty list
|
|
|
|
});
|
|
|
|
return { playlistId: playlistId };
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists/create", null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: name,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async deletePlaylist(playlistId) {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
2023-06-15 21:03:57 +00:00
|
|
|
const playlist = await this.getLocalPlaylist(playlistId);
|
2023-06-15 17:18:47 +00:00
|
|
|
var tx = window.db.transaction("playlists", "readwrite");
|
|
|
|
var store = tx.objectStore("playlists");
|
|
|
|
store.delete(playlistId);
|
2023-06-15 21:03:57 +00:00
|
|
|
// delete videos that don't need to be store anymore
|
|
|
|
const playlists = await this.getPlaylists();
|
|
|
|
const usedVideoIds = playlists
|
|
|
|
.filter(playlist => playlist.id != playlistId)
|
|
|
|
.map(playlist => JSON.parse(playlist.videoIds))
|
|
|
|
.flat();
|
|
|
|
const potentialDeletableVideos = JSON.parse(playlist.videoIds);
|
|
|
|
var videoTx = window.db.transaction("playlist_videos", "readwrite");
|
|
|
|
var videoStore = videoTx.objectStore("playlist_videos");
|
|
|
|
for (let videoId of potentialDeletableVideos) {
|
|
|
|
if (!usedVideoIds.includes(videoId)) videoStore.delete(videoId);
|
|
|
|
}
|
2023-06-15 17:18:47 +00:00
|
|
|
return { message: "ok" };
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists/delete", null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
playlistId: playlistId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async renamePlaylist(playlistId, newName) {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
|
|
|
const playlist = await this.getLocalPlaylist(playlistId);
|
|
|
|
playlist.name = newName;
|
|
|
|
this.createOrUpdateLocalPlaylist(playlist);
|
|
|
|
return { message: "ok" };
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists/rename", null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
playlistId: playlistId,
|
|
|
|
newName: newName,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async changePlaylistDescription(playlistId, newDescription) {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
|
|
|
const playlist = await this.getLocalPlaylist(playlistId);
|
|
|
|
playlist.description = newDescription;
|
|
|
|
this.createOrUpdateLocalPlaylist(playlist);
|
|
|
|
return { message: "ok" };
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists/description", null, {
|
|
|
|
method: "PATCH",
|
|
|
|
body: JSON.stringify({
|
|
|
|
playlistId: playlistId,
|
|
|
|
description: newDescription,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async addVideosToPlaylist(playlistId, videoIds, videoInfos) {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
|
|
|
const playlist = await this.getLocalPlaylist(playlistId);
|
|
|
|
const currentVideoIds = JSON.parse(playlist.videoIds);
|
2023-06-15 20:41:26 +00:00
|
|
|
currentVideoIds.push(...videoIds);
|
|
|
|
playlist.videoIds = JSON.stringify(currentVideoIds);
|
2023-06-15 21:03:57 +00:00
|
|
|
let streamInfos =
|
|
|
|
videoInfos ??
|
|
|
|
(await Promise.all(videoIds.map(videoId => this.fetchJson(this.apiUrl() + "/streams/" + videoId))));
|
2023-06-20 15:42:11 +00:00
|
|
|
playlist.thumbnail = streamInfos[0].thumbnail || streamInfos[0].thumbnailUrl;
|
|
|
|
this.createOrUpdateLocalPlaylist(playlist);
|
2023-06-15 17:18:47 +00:00
|
|
|
for (let i in videoIds) {
|
2023-06-15 21:03:57 +00:00
|
|
|
this.createLocalPlaylistVideo(videoIds[i], streamInfos[i]);
|
2023-06-15 17:18:47 +00:00
|
|
|
}
|
|
|
|
return { message: "ok" };
|
|
|
|
}
|
|
|
|
|
2023-06-15 15:32:32 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists/add", null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
playlistId: playlistId,
|
|
|
|
videoIds: videoIds,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2023-06-16 06:39:44 +00:00
|
|
|
async removeVideoFromPlaylist(playlistId, index) {
|
2023-06-15 17:18:47 +00:00
|
|
|
if (!this.authenticated) {
|
|
|
|
const playlist = await this.getLocalPlaylist(playlistId);
|
|
|
|
const videoIds = JSON.parse(playlist.videoIds);
|
2023-06-16 06:39:44 +00:00
|
|
|
videoIds.splice(index, 1);
|
2023-06-15 17:18:47 +00:00
|
|
|
playlist.videoIds = JSON.stringify(videoIds);
|
2024-03-13 16:49:40 +00:00
|
|
|
if (videoIds.length == 0) playlist.thumbnail = import.meta.env.VITE_PIPED_PROXY + "/?host=i.ytimg.com";
|
2023-06-15 17:18:47 +00:00
|
|
|
this.createOrUpdateLocalPlaylist(playlist);
|
|
|
|
return { message: "ok" };
|
|
|
|
}
|
|
|
|
|
2023-06-15 20:41:26 +00:00
|
|
|
return await this.fetchJson(this.authApiUrl() + "/user/playlists/remove", null, {
|
2023-06-15 15:32:32 +00:00
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
playlistId: playlistId,
|
2023-06-15 20:41:26 +00:00
|
|
|
index: index,
|
2023-06-15 15:32:32 +00:00
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2023-07-07 16:02:01 +00:00
|
|
|
getHomePage(_this) {
|
2023-07-05 10:59:23 +00:00
|
|
|
switch (_this.getPreferenceString("homepage", "trending")) {
|
|
|
|
case "trending":
|
2023-07-07 16:02:01 +00:00
|
|
|
return "/trending";
|
2023-07-05 10:59:23 +00:00
|
|
|
case "feed":
|
2023-07-07 16:02:01 +00:00
|
|
|
return "/feed";
|
2023-07-05 10:59:23 +00:00
|
|
|
default:
|
2023-07-07 16:02:01 +00:00
|
|
|
return undefined;
|
2023-07-05 10:59:23 +00:00
|
|
|
}
|
|
|
|
},
|
2023-07-21 20:07:53 +00:00
|
|
|
fetchDeArrowContent(content) {
|
|
|
|
if (!this.getPreferenceBoolean("dearrow", false)) return;
|
|
|
|
|
|
|
|
const videoIds = content
|
|
|
|
.filter(item => item.type === "stream")
|
|
|
|
.filter(item => item.dearrow === undefined)
|
|
|
|
.map(item => item.url.substr(-11))
|
|
|
|
.sort();
|
|
|
|
|
|
|
|
if (videoIds.length === 0) return;
|
|
|
|
|
|
|
|
this.fetchJson(this.apiUrl() + "/dearrow", {
|
2023-07-19 01:54:00 +00:00
|
|
|
videoIds: videoIds.join(","),
|
2023-07-21 20:07:53 +00:00
|
|
|
}).then(json => {
|
|
|
|
Object.keys(json).forEach(videoId => {
|
|
|
|
const item = content.find(item => item.url.endsWith(videoId));
|
|
|
|
if (item) item.dearrow = json[videoId];
|
|
|
|
});
|
2023-07-19 01:54:00 +00:00
|
|
|
});
|
|
|
|
},
|
2024-01-19 14:24:12 +00:00
|
|
|
async fetchSubscriptionStatus(channelId) {
|
|
|
|
if (!this.authenticated) {
|
|
|
|
return this.isSubscribedLocally(channelId);
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await this.fetchJson(
|
|
|
|
this.authApiUrl() + "/subscribed",
|
|
|
|
{
|
|
|
|
channelId: channelId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return response?.subscribed;
|
|
|
|
},
|
|
|
|
async toggleSubscriptionState(channelId, subscribed) {
|
|
|
|
if (!this.authenticated) return this.handleLocalSubscriptions(channelId);
|
|
|
|
|
|
|
|
const resp = await this.fetchJson(this.authApiUrl() + (subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: channelId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return !resp.error;
|
|
|
|
},
|
2024-03-15 21:52:20 +00:00
|
|
|
getCustomInstances() {
|
|
|
|
return JSON.parse(window.localStorage.getItem("customInstances")) ?? [];
|
|
|
|
},
|
|
|
|
addCustomInstance(instance) {
|
|
|
|
let customInstances = this.getCustomInstances();
|
|
|
|
customInstances.push(instance);
|
|
|
|
window.localStorage.setItem("customInstances", JSON.stringify(customInstances));
|
|
|
|
},
|
|
|
|
removeCustomInstance(instanceToDelete) {
|
|
|
|
let customInstances = this.getCustomInstances().filter(
|
|
|
|
instance => instance.api_url != instanceToDelete.api_url,
|
|
|
|
);
|
|
|
|
window.localStorage.setItem("customInstances", JSON.stringify(customInstances));
|
|
|
|
},
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2021-06-28 19:45:03 +00:00
|
|
|
computed: {
|
2021-07-16 22:56:41 +00:00
|
|
|
authenticated(_this) {
|
|
|
|
return _this.getAuthToken() !== undefined;
|
|
|
|
},
|
2021-08-28 12:00:17 +00:00
|
|
|
testLocalStorage() {
|
|
|
|
try {
|
|
|
|
if (window.localStorage !== undefined) localStorage;
|
|
|
|
return true;
|
|
|
|
} catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2022-11-03 16:45:28 +00:00
|
|
|
async defaultLanguage() {
|
2021-09-23 22:57:26 +00:00
|
|
|
const languages = window.navigator.languages;
|
|
|
|
for (let i = 0; i < languages.length; i++) {
|
|
|
|
try {
|
2022-10-19 22:16:22 +00:00
|
|
|
await import(`./locales/${languages[i]}.json`);
|
2021-09-23 22:57:26 +00:00
|
|
|
return languages[i];
|
|
|
|
} catch {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "en";
|
|
|
|
},
|
2021-07-03 19:33:59 +00:00
|
|
|
},
|
2021-10-27 00:59:03 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
TimeAgo: TimeAgo,
|
|
|
|
TimeAgoConfig: timeAgo,
|
|
|
|
};
|
|
|
|
},
|
2021-04-07 11:45:40 +00:00
|
|
|
};
|
|
|
|
|
2021-08-25 16:30:21 +00:00
|
|
|
const i18n = createI18n({
|
|
|
|
globalInjection: true,
|
|
|
|
legacy: false,
|
|
|
|
locale: "en",
|
|
|
|
fallbackLocale: "en",
|
|
|
|
messages: {
|
|
|
|
en: enLocale,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
window.i18n = i18n;
|
|
|
|
|
2021-04-07 11:45:40 +00:00
|
|
|
const app = createApp(App);
|
2021-08-25 16:30:21 +00:00
|
|
|
app.use(i18n);
|
2021-04-07 11:45:40 +00:00
|
|
|
app.use(router);
|
|
|
|
app.mixin(mixin);
|
|
|
|
app.mount("#app");
|