revert base

This commit is contained in:
Francesco Grazioso 2024-05-27 12:51:59 +02:00
parent ad132b7c53
commit 28b0338f23
3 changed files with 310 additions and 420 deletions

View File

@ -1,81 +1,44 @@
import axios from "axios";
import type { AxiosResponse } from "axios";
import type { DownloadResponse, MediaItemResponse } from "@/api/interfaces";
import axios from 'axios'
import type {MediaItemResponse} from '@/api/interfaces'
const BASE_URL = "http://localhost:8000/api";
const BASE_URL = 'http://localhost:8000/api'
const api = axios.create({
baseURL: BASE_URL,
function get(url: string): Promise<any> {
return axios.get(`${BASE_URL}${url}`)
.then(response => response.data)
.catch(error => {
throw error;
});
async function get<T>(url: string): Promise<AxiosResponse<T>> {
return api.get(url);
}
async function post<T>(url: string, data: any): Promise<AxiosResponse<T>> {
return api.post(url, data);
function post(url: string, data: any): Promise<any> {
return axios.post(`${BASE_URL}${url}`, data)
.then(response => response.data)
.catch(error => {
throw error;
});
}
export default function search(
query: string,
type: string
): Promise<AxiosResponse<MediaItemResponse>> {
return get(`/search?search_terms=${query}&type=${type}`);
export default function search(query: string, type: string) : Promise<MediaItemResponse> {
return get(`/search?search_terms=${query}&type=${type}`)
}
export async function getEpisodesInfo(
mediaId: number,
mediaSlug: string,
mediaType: string
): Promise<Response> {
const url = `/search/get_episodes_info?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`;
return fetch(`${BASE_URL}${url}`, {
method: "GET",
export async function getEpisodesInfo(mediaId: number, mediaSlug: string, mediaType: string): Promise<Response> {
const url = `${BASE_URL}/search/get_episodes_info?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`;
return await fetch(url, {
method: 'GET',
headers: {
"Content-Type": "text/event-stream",
},
'Content-Type': 'text/event-stream'
}
});
}
export async function getPreview(
mediaId: number,
mediaSlug: string,
mediaType: string
): Promise<AxiosResponse<any>> {
const url = `/search/get_preview?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`;
return get(url);
}
async function downloadMedia(
mediaId: number,
mediaSlug: string,
mediaType: string,
downloadId?: number,
tvSeriesEpisodeId?: number
): Promise<AxiosResponse<DownloadResponse>> {
export async function downloadFilm(mediaId: number, mediaSlug: string, mediaType: string): Promise<Response> {
const url = `/download/`;
const data = {
media_id: mediaId,
media_slug: mediaSlug,
type_media: mediaType,
download_id: downloadId,
tv_series_episode_id: tvSeriesEpisodeId,
type_media: mediaType
};
return post(url, data);
}
export const downloadFilm = (mediaId: number, mediaSlug: string) =>
downloadMedia(mediaId, mediaSlug, "MOVIE");
export const downloadTvSeries = (
mediaId: number,
mediaSlug: string,
downloadId: number,
tvSeriesEpisodeId?: number
) => downloadMedia(mediaId, mediaSlug, "TV", downloadId, tvSeriesEpisodeId);
export const downloadAnimeFilm = (mediaId: number, mediaSlug: string) =>
downloadMedia(mediaId, mediaSlug, "OVA");
export const downloadAnimeSeries = (
mediaId: number,
mediaSlug: string,
downloadId: number
) => downloadMedia(mediaId, mediaSlug, "TV_ANIME", downloadId);

View File

@ -57,8 +57,3 @@ export interface Season {
export interface SeasonResponse {
episodes: Season;
}
export interface DownloadResponse {
error: string;
message: string;
}

View File

@ -1,42 +1,23 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
import type {Episode, MediaItem, SeasonResponse} from "@/api/interfaces";
import { onBeforeMount, onMounted, ref } from "vue";
import { getEpisodesInfo, getPreview } from "@/api/api";
import {
alertDownload,
handleMovieDownload,
handleOVADownload,
handleTVAnimeDownload,
handleTvAnimeEpisodesDownload,
handleTVDownload, handleTVEpisodesDownload
} from "@/api/utils";
import type {Episode, MediaItem, Season, SeasonResponse} from "@/api/interfaces";
import { onMounted, ref } from "vue";
import {downloadFilm, getEpisodesInfo} from "@/api/api";
const route = useRoute()
const item: MediaItem = JSON.parse(<string>route.params.item)
const imageUrl: string = <string>route.params.imageUrl
const animeEpisodes = ref<Episode[]>([])
const totalEpisodes = ref<number>(0)
const tvShowEpisodes = ref<any[]>([])
const loading = ref(false)
const selectingEpisodes = ref(false)
const selectedEpisodes = ref<Episode[]>([])
const previewItem = ref<MediaItem>(item)
onBeforeMount(async () => {
const res = await getPreview(item.id, item.slug, item.type)
if (res && res.data) {
previewItem.plot = res.data.plot
}
})
onMounted(async () => {
loading.value = true;
if (['MOVIE', 'OVA', 'SPECIAL'].includes(item.type)) {
loading.value = false;
return
} else {
loading.value = true;
const response = await getEpisodesInfo(item.id, item.slug, item.type)
if (response && response.body) {
loading.value = false;
@ -50,7 +31,6 @@ onMounted(async () => {
if (item.type === 'TV_ANIME') {
const episodesData:Episode = JSON.parse(value.trim());
animeEpisodes.value.push(episodesData);
totalEpisodes.value = episodesData.episode_total;
} else {
const episodesData:SeasonResponse = JSON.parse(value.trim());
for (const seasonKey in episodesData.episodes) {
@ -70,59 +50,30 @@ onMounted(async () => {
const toggleEpisodeSelection = () => {
selectingEpisodes.value = !selectingEpisodes.value
selectedEpisodes.value = []
}
const toggleEpisodeSelect = (episode: Episode, seasonNumber?: number) => {
if (selectedEpisodes.value.includes(episode)) {
selectedEpisodes.value = selectedEpisodes.value.filter(e => e !== episode)
} else {
if (seasonNumber) {
episode.season_index = seasonNumber
}
selectedEpisodes.value.push(episode)
}
}
const downloadSelectedEpisodes = async () => {
const downloadItems = async () => {
try {
switch (item.type) {
case 'TV':
await handleTVEpisodesDownload(selectedEpisodes.value, item);
case 'TV_ANIME':
await handleTvAnimeEpisodesDownload(selectedEpisodes.value, item);
break;
default:
throw new Error('Tipo di media non supportato');
if (item.type === 'MOVIE') {
const res = await downloadFilm(item.id, item.slug, item.type)
if (res.error) {
throw new Error(res.error + ' - ' + res.message)
}
toggleEpisodeSelection();
} catch (error) {
alertDownload(error);
}
};
const downloadAllItems = async () => {
try {
switch (item.type) {
case 'TV':
await handleTVDownload(tvShowEpisodes.value, item);
case 'MOVIE':
await handleMovieDownload(item);
break;
case 'TV_ANIME':
await handleTVAnimeDownload(totalEpisodes.value, item);
break;
case 'OVA':
case 'SPECIAL':
await handleOVADownload(item);
break;
default:
throw new Error('Tipo di media non supportato');
alertDownload()
return
}
} catch (error) {
alertDownload(error);
alertDownload(error)
}
}
const alertDownload = (message?: any) => {
if (message) {
alert(message)
return;
}
alert('Il downlaod è iniziato, il file sarà disponibile tra qualche minuto nella cartella \'Video\' del progetto...')
}
};
</script>
<template>
@ -136,52 +87,34 @@ const downloadAllItems = async () => {
<h1 class="details-title">{{ item.name }}</h1>
<h3> {{ item.score }}</h3>
<div class="details-description">
<p>{{ item.plot }}</p>
<p v-if="item.type == 'TV_ANIME'">{{ item.plot }}</p>
<p v-else-if="tvShowEpisodes.length > 0">{{ tvShowEpisodes[0][0].plot }}</p>
</div>
<h3 v-if="animeEpisodes.length > 0 && !loading">Numero episodi: {{ totalEpisodes }}</h3>
<h3 v-if="animeEpisodes.length > 0 && !loading">Numero episodi: {{ animeEpisodes[0].episode_total }}</h3>
<h3 v-if="tvShowEpisodes.length > 0 && !loading">Numero stagioni: {{ tvShowEpisodes.length }}</h3>
<hr style="opacity: 0.2; margin-top: 10px"/>
<!--DOWNLOAD SECTION-->
<hr style="opacity: 0.2"/>
<div class="download-section">
<button :disabled="loading || selectingEpisodes"
@click.prevent="downloadAllItems">
Scarica {{['TV_ANIME', 'TV'].includes(item.type)? 'tutto' : ''}}
</button>
<button :disabled="loading || selectingEpisodes" @click="downloadItems">Scarica {{['TV_ANIME', 'TV'].includes(item.type)? 'tutto' : ''}}</button>
<template v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)">
<button @click="toggleEpisodeSelection">
{{selectingEpisodes ? 'Disattiva' : 'Attiva'}} selezione episodi
</button>
<button :disabled="selectedEpisodes.length == 0"
@click="downloadSelectedEpisodes">
Download episodi selezionati
</button>
<button @click="toggleEpisodeSelection">{{selectingEpisodes ? 'Disattiva' : 'Attiva'}} selezione episodi</button>
<button>Download episodi</button>
</template>
</div>
</div>
</div>
<!--SERIES SECTION-->
<div v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)"
:class="item.type == 'TV_ANIME' ? 'episodes-container' : 'season-container'">
<div v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)" :class="item.type == 'TV_ANIME' ? 'episodes-container' : 'season-container'">
<div v-if="animeEpisodes.length == 0 && tvShowEpisodes.length == 0">
<p>Non ci sono episodi...</p>
</div>
<div v-else-if="item.type == 'TV_ANIME'"
v-for="episode in animeEpisodes"
:key="episode.id"
class="episode-item"
:style="{ backgroundColor: selectedEpisodes.includes(episode) ? '#42b883' : '#333' }"
@click="selectingEpisodes ? toggleEpisodeSelect(episode) : null">
<div v-else-if="item.type == 'TV_ANIME'" v-for="episode in animeEpisodes" :key="episode.id" class="episode-item">
<div class="episode-title">Episodio {{ episode.number }}</div>
</div>
<div v-else-if="item.type == 'TV'" v-for="(season, index) in tvShowEpisodes" v-bind:key="season.number" class="season-item">
<div v-else-if="item.type == 'TV'" v-for="(season, index) in tvShowEpisodes" class="season-item">
<div class="season-title">Stagione {{ index + 1 }}</div>
<div class="episode-container">
<div v-for="episode in season" :key="episode.id">
<div class="episode-item"
:style="{ backgroundColor: selectedEpisodes.includes(episode) ? '#42b883' : '#333' }"
@click="selectingEpisodes ? toggleEpisodeSelect(episode, index) : null">
<div v-for="episode in season" :key="episode.id" class="episode-item">
<div class="episode-title">
Episodio {{ episode.number }} -
{{episode.name.slice(0, 40) + (episode.name.length > 39 ? '...' : '')}}
@ -190,11 +123,10 @@ const downloadAllItems = async () => {
</div>
</div>
</div>
</div>
<!--MOVIES SECTION-->
<div v-else-if="!loading && ['MOVIE', 'OVA', 'SPECIAL'].includes(item.type)">
<p>Questo è un {{item.type}} (QUESTO TESTO E' A SCOPO DI TEST)</p>
<p>Questo è un {{item.type}}</p>
</div>
<!--LOADING SECTION-->