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 data = {
media_id: mediaId,
media_slug: mediaSlug,
type_media: mediaType,
download_id: downloadId,
};
return post(url, data);
}
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 downloadAnimeSeries = (mediaId: number, mediaSlug: string, downloadId: number) => downloadMedia(mediaId, mediaSlug, 'TV_ANIME', downloadId);

View File

@ -1,27 +1,17 @@
<script setup lang="ts">
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 { getEpisodesInfo } from "@/api/api";
import {
alertDownload,
handleMovieDownload,
handleOVADownload,
handleTVAnimeDownload,
handleTvAnimeEpisodesDownload,
handleTVDownload
} from "@/api/utils";
import {downloadAnimeFilm, 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[]>([])
onMounted(async () => {
if (['MOVIE', 'OVA', 'SPECIAL'].includes(item.type)) {
@ -41,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) {
@ -61,56 +50,42 @@ onMounted(async () => {
const toggleEpisodeSelection = () => {
selectingEpisodes.value = !selectingEpisodes.value
selectedEpisodes.value = []
}
const toggleEpisodeSelect = (episode: Episode) => {
if (selectedEpisodes.value.includes(episode)) {
selectedEpisodes.value = selectedEpisodes.value.filter(e => e !== episode)
} else {
selectedEpisodes.value.push(episode)
}
}
const downloadSelectedEpisodes = async () => {
const downloadItems = async () => {
try {
let res: DownloadResponse;
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':
await handleMovieDownload(item);
break;
case 'TV_ANIME':
await handleTVAnimeDownload(totalEpisodes.value, item);
res = (await downloadFilm(item.id, item.slug)).data;
break;
case 'OVA':
case 'SPECIAL':
await handleOVADownload(item);
res = (await downloadAnimeFilm(item.id, item.slug)).data;
break;
default:
throw new Error('Tipo di media non supportato');
}
console.log(res)
if (res.error) {
throw new Error(`${res.error} - ${res.message}`);
}
alertDownload();
} catch (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>
@ -127,41 +102,27 @@ const downloadAllItems = async () => {
<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>
</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-->
<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" class="season-item">