revert base

This commit is contained in:
Francesco Grazioso 2024-05-27 12:55:56 +02:00
parent bd1c4ddb30
commit d02e225da9
2 changed files with 32 additions and 74 deletions

View File

@ -30,18 +30,15 @@ export async function getEpisodesInfo(mediaId: number, mediaSlug: string, mediaT
}); });
} }
async function downloadMedia(mediaId: number, mediaSlug: string, mediaType: string, downloadId?: number): Promise<AxiosResponse<DownloadResponse>> { async function downloadMedia(mediaId: number, mediaSlug: string, mediaType: string): Promise<AxiosResponse<DownloadResponse>> {
const url = `/download/`; const url = `/download/`;
const data = { const data = {
media_id: mediaId, media_id: mediaId,
media_slug: mediaSlug, media_slug: mediaSlug,
type_media: mediaType, type_media: mediaType,
download_id: downloadId,
}; };
return post(url, data); return post(url, data);
} }
export const downloadFilm = (mediaId: number, mediaSlug: string) => downloadMedia(mediaId, mediaSlug, 'MOVIE'); export const downloadFilm = (mediaId: number, mediaSlug: string) => downloadMedia(mediaId, mediaSlug, 'MOVIE');
export const downloadTvSeries = (mediaId: number, mediaSlug: string, downloadId: number) => downloadMedia(mediaId, mediaSlug, 'TV', downloadId); export const downloadAnimeFilm = (mediaId: number, mediaSlug: string) => downloadMedia(mediaId, mediaSlug, 'OVA');
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

@ -1,27 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import type {Episode, MediaItem, SeasonResponse} from "@/api/interfaces"; import type {DownloadResponse, Episode, MediaItem, Season, SeasonResponse} from "@/api/interfaces";
import { onMounted, ref } from "vue"; import { onMounted, ref } from "vue";
import { getEpisodesInfo } from "@/api/api"; import {downloadAnimeFilm, downloadFilm, getEpisodesInfo} from "@/api/api";
import {
alertDownload,
handleMovieDownload,
handleOVADownload,
handleTVAnimeDownload,
handleTvAnimeEpisodesDownload,
handleTVDownload
} from "@/api/utils";
const route = useRoute() const route = useRoute()
const item: MediaItem = JSON.parse(<string>route.params.item) const item: MediaItem = JSON.parse(<string>route.params.item)
const imageUrl: string = <string>route.params.imageUrl const imageUrl: string = <string>route.params.imageUrl
const animeEpisodes = ref<Episode[]>([]) const animeEpisodes = ref<Episode[]>([])
const totalEpisodes = ref<number>(0)
const tvShowEpisodes = ref<any[]>([]) const tvShowEpisodes = ref<any[]>([])
const loading = ref(false) const loading = ref(false)
const selectingEpisodes = ref(false) const selectingEpisodes = ref(false)
const selectedEpisodes = ref<Episode[]>([])
onMounted(async () => { onMounted(async () => {
if (['MOVIE', 'OVA', 'SPECIAL'].includes(item.type)) { if (['MOVIE', 'OVA', 'SPECIAL'].includes(item.type)) {
@ -41,7 +31,6 @@ onMounted(async () => {
if (item.type === 'TV_ANIME') { if (item.type === 'TV_ANIME') {
const episodesData:Episode = JSON.parse(value.trim()); const episodesData:Episode = JSON.parse(value.trim());
animeEpisodes.value.push(episodesData); animeEpisodes.value.push(episodesData);
totalEpisodes.value = episodesData.episode_total;
} else { } else {
const episodesData:SeasonResponse = JSON.parse(value.trim()); const episodesData:SeasonResponse = JSON.parse(value.trim());
for (const seasonKey in episodesData.episodes) { for (const seasonKey in episodesData.episodes) {
@ -61,56 +50,42 @@ onMounted(async () => {
const toggleEpisodeSelection = () => { const toggleEpisodeSelection = () => {
selectingEpisodes.value = !selectingEpisodes.value selectingEpisodes.value = !selectingEpisodes.value
selectedEpisodes.value = []
} }
const toggleEpisodeSelect = (episode: Episode) => { const downloadItems = async () => {
if (selectedEpisodes.value.includes(episode)) {
selectedEpisodes.value = selectedEpisodes.value.filter(e => e !== episode)
} else {
selectedEpisodes.value.push(episode)
}
}
const downloadSelectedEpisodes = async () => {
try { try {
let res: DownloadResponse;
switch (item.type) { switch (item.type) {
case 'TV':
// await handleTVDownload(selectedEpisodes.value, item);
case 'TV_ANIME':
await handleTvAnimeEpisodesDownload(selectedEpisodes.value, item);
break;
default:
throw new Error('Tipo di media non supportato');
}
toggleEpisodeSelection();
} catch (error) {
alertDownload(error);
}
};
const downloadAllItems = async () => {
try {
switch (item.type) {
case 'TV':
await handleTVDownload(tvShowEpisodes.value, item);
case 'MOVIE': case 'MOVIE':
await handleMovieDownload(item); res = (await downloadFilm(item.id, item.slug)).data;
break;
case 'TV_ANIME':
await handleTVAnimeDownload(totalEpisodes.value, item);
break; break;
case 'OVA': case 'OVA':
case 'SPECIAL': case 'SPECIAL':
await handleOVADownload(item); res = (await downloadAnimeFilm(item.id, item.slug)).data;
break; break;
default: default:
throw new Error('Tipo di media non supportato'); throw new Error('Tipo di media non supportato');
} }
console.log(res)
if (res.error) {
throw new Error(`${res.error} - ${res.message}`);
}
alertDownload();
} catch (error) { } 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> </script>
<template> <template>
@ -127,43 +102,29 @@ const downloadAllItems = async () => {
<p v-if="['TV_ANIME', 'OVA', 'SPECIAL'].includes(item.type)">{{ item.plot }}</p> <p v-if="['TV_ANIME', 'OVA', 'SPECIAL'].includes(item.type)">{{ item.plot }}</p>
<p v-else-if="tvShowEpisodes.length > 0">{{ tvShowEpisodes[0][0].plot }}</p> <p v-else-if="tvShowEpisodes.length > 0">{{ tvShowEpisodes[0][0].plot }}</p>
</div> </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> <h3 v-if="tvShowEpisodes.length > 0 && !loading">Numero stagioni: {{ tvShowEpisodes.length }}</h3>
<hr style="opacity: 0.2; margin-top: 10px"/> <hr style="opacity: 0.2; margin-top: 10px"/>
<!--DOWNLOAD SECTION--> <!--DOWNLOAD SECTION-->
<div class="download-section"> <div class="download-section">
<button :disabled="loading || selectingEpisodes" <button :disabled="loading || selectingEpisodes" @click="downloadItems">Scarica {{['TV_ANIME', 'TV'].includes(item.type)? 'tutto' : ''}}</button>
@click.prevent="downloadAllItems">
Scarica {{['TV_ANIME', 'TV'].includes(item.type)? 'tutto' : ''}}
</button>
<template v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)"> <template v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)">
<button @click="toggleEpisodeSelection"> <button @click="toggleEpisodeSelection">{{selectingEpisodes ? 'Disattiva' : 'Attiva'}} selezione episodi</button>
{{selectingEpisodes ? 'Disattiva' : 'Attiva'}} selezione episodi <button>Download episodi</button>
</button>
<button :disabled="selectedEpisodes.length == 0"
@click="downloadSelectedEpisodes">
Download episodi selezionati
</button>
</template> </template>
</div> </div>
</div> </div>
</div> </div>
<!--SERIES SECTION--> <!--SERIES SECTION-->
<div v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)" <div v-if="!loading && ['TV_ANIME', 'TV'].includes(item.type)" :class="item.type == 'TV_ANIME' ? 'episodes-container' : 'season-container'">
:class="item.type == 'TV_ANIME' ? 'episodes-container' : 'season-container'">
<div v-if="animeEpisodes.length == 0 && tvShowEpisodes.length == 0"> <div v-if="animeEpisodes.length == 0 && tvShowEpisodes.length == 0">
<p>Non ci sono episodi...</p> <p>Non ci sono episodi...</p>
</div> </div>
<div v-else-if="item.type == 'TV_ANIME'" <div v-else-if="item.type == 'TV_ANIME'" v-for="episode in animeEpisodes" :key="episode.id" class="episode-item">
v-for="episode in animeEpisodes" <div class="episode-title">Episodio {{ episode.number }}</div>
:key="episode.id" </div>
class="episode-item"
:style="{ backgroundColor: selectedEpisodes.includes(episode) ? '#42b883' : '#333' }"
@click="selectingEpisodes ? toggleEpisodeSelect(episode) : null">
<div class="episode-title">Episodio {{ episode.number }}</div>
</div>
<div v-else-if="item.type == 'TV'" v-for="(season, index) in tvShowEpisodes" 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="season-title">Stagione {{ index + 1 }}</div>
<div class="episode-container"> <div class="episode-container">