revert base

This commit is contained in:
Francesco Grazioso 2024-05-27 12:54:49 +02:00
parent 28b0338f23
commit bd1c4ddb30
5 changed files with 152 additions and 147 deletions

View File

@ -7,13 +7,15 @@ from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from Src.Api.Animeunity import title_search as anime_search
from Src.Api.Animeunity.Core.Vix_player.player import VideoSource as anime_source
from Src.Api.Animeunity.site import media_search_manager as anime_media_manager
from Src.Api.Streamingcommunity import title_search as sc_search, get_version_and_domain
from Src.Api.Streamingcommunity.Core.Vix_player.player import VideoSource as film_video_source
from Src.Api.Streamingcommunity.site import media_search_manager as film_media_manager
from Src.Api import search, get_version_and_domain, download_film, anime_download_film
from Src.Api.anime import EpisodeDownloader
from Src.Api.Class.Video import VideoSource
from Src.Api.film import ROOT_PATH
from Src.Api.series import SERIES_FOLDER, STREAM_SITE_NAME
from Src.Api.site import media_search_manager, anime_search
from Src.Lib.FFmpeg.my_m3u8 import Downloader
from Src.Util.mapper import map_episode_title
from Src.Util.os import remove_special_characters
class SearchView(viewsets.ViewSet):
@ -22,16 +24,15 @@ class SearchView(viewsets.ViewSet):
self.search_query = request.query_params.get("search_terms")
self.type_search = request.query_params.get("type")
media_manager = anime_media_manager if self.type_search == "anime" else film_media_manager
media_manager.media_list = []
media_search_manager.media_list = []
self.len_database = 0
if self.type_search == "film":
_, self.domain = get_version_and_domain()
self.len_database = sc_search(self.search_query, self.domain)
self.len_database = search(self.search_query, self.domain)
elif self.type_search == "anime":
self.len_database = anime_search(self.search_query)
media_list = media_manager.media_list
media_list = media_search_manager.media_list
if self.len_database != 0:
data_to_return = []
@ -50,23 +51,22 @@ class SearchView(viewsets.ViewSet):
@action(detail=False, methods=["get"])
def get_episodes_info(self, request):
self.media_id = request.query_params.get("media_id")
self.media_slug = request.query_params.get("media_slug")
self.media_slug = request.data.get("media_slug")
self.type_media = request.query_params.get("type_media")
try:
match self.type_media:
case "TV":
def stream_episodes():
self.version, self.domain = get_version_and_domain()
self.site_version, self.domain = get_version_and_domain()
video_source = VideoSource()
video_source.set_url_base_name(STREAM_SITE_NAME)
video_source.set_version(self.site_version)
video_source.set_domain(self.domain)
video_source.set_series_name(self.media_slug)
video_source.set_media_id(self.media_id)
video_source = film_video_source()
video_source.setup(
version=self.version,
domain=self.domain,
media_id=self.media_id,
series_name=self.media_slug
)
video_source.collect_info_seasons()
seasons_count = video_source.obj_title_manager.get_length()
@ -74,42 +74,32 @@ class SearchView(viewsets.ViewSet):
for i_season in range(1, seasons_count + 1):
video_source.obj_episode_manager.clear()
video_source.collect_title_season(i_season)
episodes_count = (
video_source.obj_episode_manager.get_length()
)
episodes_count = video_source.obj_episode_manager.get_length()
episodes[i_season] = {}
for i_episode in range(1, episodes_count + 1):
episode = video_source.obj_episode_manager.episodes[
i_episode - 1
]
episodes[i_season][i_episode] = episode.to_dict()
episodes[i_season][i_episode] = episode.__dict__
yield f'{json.dumps({"episodes": episodes})}\n\n'
response = StreamingHttpResponse(
stream_episodes(), content_type="text/event-stream"
)
response = StreamingHttpResponse(stream_episodes(), content_type='text/event-stream')
return response
case "TV_ANIME":
def stream_episodes():
video_source = anime_source()
video_source.setup(
media_id = self.media_id,
series_name = self.media_slug
)
episoded_count = video_source.get_count_episodes()
episodes_downloader = EpisodeDownloader(self.media_id, self.media_slug)
episoded_count = episodes_downloader.get_count_episodes()
for i in range(0, episoded_count):
episode_info = video_source.get_info_episode(i).to_dict()
for i in range(1, episoded_count + 1):
episode_info = episodes_downloader.get_info_episode(index_ep=i)
episode_info["episode_id"] = i
episode_info["episode_total"] = episoded_count
print(f"Getting episode {i} of {episoded_count} info...")
yield f"{json.dumps(episode_info)}\n\n"
yield f'{json.dumps(episode_info)}\n\n'
response = StreamingHttpResponse(
stream_episodes(), content_type="text/event-stream"
)
response = StreamingHttpResponse(stream_episodes(), content_type='text/event-stream')
return response
except Exception as e:
@ -122,36 +112,7 @@ class SearchView(viewsets.ViewSet):
return Response({"error": "No media found with that search query"})
@action(detail=False, methods=["get"])
def get_preview(self, request):
self.media_id = request.query_params.get("media_id")
self.media_slug = request.query_params.get("media_slug")
self.type_media = request.query_params.get("type_media")
try:
if self.type_media in ["TV", "MOVIE"]:
version, domain = get_version_and_domain()
video_source = film_video_source()
video_source.setup(media_id=self.media_id, version=version, domain=domain, series_name=self.media_slug)
video_source.get_preview()
return Response(video_source.obj_preview.to_dict())
if self.type_media in ["TV_ANIME", "OVA", "SPECIAL"]:
video_source = anime_source()
video_source.setup(media_id=self.media_id, series_name=self.media_slug)
video_source.get_preview()
return Response(video_source.obj_preview.to_dict())
except Exception as e:
return Response(
{
"error": "Error while getting preview info",
"message": str(e),
}
)
return Response({"error": "No media found with that search query"})
'''
class DownloadView(viewsets.ViewSet):
def create(self, request):
@ -159,7 +120,6 @@ class DownloadView(viewsets.ViewSet):
self.media_slug = request.data.get("media_slug")
self.type_media = request.data.get("type_media").upper()
self.download_id = request.data.get("download_id")
self.tv_series_episode_id = request.data.get("tv_series_episode_id")
if self.type_media in ["TV", "MOVIE"]:
self.site_version, self.domain = get_version_and_domain()
@ -238,4 +198,3 @@ class DownloadView(viewsets.ViewSet):
}
return Response(response_dict)
'''

View File

@ -1,44 +1,47 @@
import axios from 'axios'
import type {MediaItemResponse} from '@/api/interfaces'
import axios from 'axios';
import type { AxiosResponse } from 'axios';
import type {DownloadResponse, MediaItemResponse} from '@/api/interfaces';
const BASE_URL = 'http://localhost:8000/api'
const BASE_URL = 'http://localhost:8000/api';
function get(url: string): Promise<any> {
return axios.get(`${BASE_URL}${url}`)
.then(response => response.data)
.catch(error => {
throw error;
});
const api = axios.create({
baseURL: BASE_URL,
});
async function get<T>(url: string): Promise<AxiosResponse<T>> {
return api.get(url);
}
function post(url: string, data: any): Promise<any> {
return axios.post(`${BASE_URL}${url}`, data)
.then(response => response.data)
.catch(error => {
throw error;
});
async function post<T>(url: string, data: any): Promise<AxiosResponse<T>> {
return api.post(url, data);
}
export default function search(query: string, type: string) : Promise<MediaItemResponse> {
return get(`/search?search_terms=${query}&type=${type}`)
export default function search(query: string, type: string): Promise<AxiosResponse<MediaItemResponse>> {
return get(`/search?search_terms=${query}&type=${type}`);
}
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, {
const url = `/search/get_episodes_info?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`;
return fetch(`${BASE_URL}${url}`, {
method: 'GET',
headers: {
'Content-Type': 'text/event-stream'
}
'Content-Type': 'text/event-stream',
},
});
}
export async function downloadFilm(mediaId: number, mediaSlug: string, mediaType: string): Promise<Response> {
async function downloadMedia(mediaId: number, mediaSlug: string, mediaType: string, downloadId?: number): Promise<AxiosResponse<DownloadResponse>> {
const url = `/download/`;
const data = {
media_id: mediaId,
media_slug: mediaSlug,
type_media: mediaType
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

@ -45,7 +45,6 @@ export interface Episode {
season_id: number; // TV Show exclusive
created_by: any; // TV Show exclusive
updated_at: string; // TV Show exclusive
season_index: number; // TV Show exclusive
}
export interface Season {

View File

@ -1,5 +1,5 @@
import {downloadAnimeFilm, downloadAnimeSeries, downloadFilm, downloadTvSeries} from "@/api/api";
import type {DownloadResponse, Episode, MediaItem, Season} from "@/api/interfaces";
import type {DownloadResponse, Episode, MediaItem} from "@/api/interfaces";
export const handleTVDownload = async (tvShowEpisodes: any[], item: MediaItem) => {
alertDownload();
@ -10,15 +10,6 @@ export const handleTVDownload = async (tvShowEpisodes: any[], item: MediaItem) =
}
};
export const handleTVEpisodesDownload = async (episodes: Episode[], item: MediaItem) => {
alertDownload();
for (const episode of episodes) {
const i = episodes.indexOf(episode);
const res = (await downloadTvSeries(item.id, item.slug, episode.season_index + 1, i)).data;
handleDownloadError(res);
}
}
export const handleMovieDownload = async (item: MediaItem) => {
alertDownload();
const res = (await downloadFilm(item.id, item.slug)).data;

View File

@ -1,17 +1,27 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
import type {Episode, MediaItem, Season, SeasonResponse} from "@/api/interfaces";
import type {Episode, MediaItem, SeasonResponse} from "@/api/interfaces";
import { onMounted, ref } from "vue";
import {downloadFilm, getEpisodesInfo} from "@/api/api";
import { getEpisodesInfo } from "@/api/api";
import {
alertDownload,
handleMovieDownload,
handleOVADownload,
handleTVAnimeDownload,
handleTvAnimeEpisodesDownload,
handleTVDownload
} from "@/api/utils";
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)) {
@ -31,6 +41,7 @@ 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) {
@ -50,30 +61,56 @@ onMounted(async () => {
const toggleEpisodeSelection = () => {
selectingEpisodes.value = !selectingEpisodes.value
selectedEpisodes.value = []
}
const downloadItems = async () => {
try {
if (item.type === 'MOVIE') {
const res = await downloadFilm(item.id, item.slug, item.type)
if (res.error) {
throw new Error(res.error + ' - ' + res.message)
const toggleEpisodeSelect = (episode: Episode) => {
if (selectedEpisodes.value.includes(episode)) {
selectedEpisodes.value = selectedEpisodes.value.filter(e => e !== episode)
} else {
selectedEpisodes.value.push(episode)
}
alertDownload()
return
}
const downloadSelectedEpisodes = async () => {
try {
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);
break;
case 'OVA':
case 'SPECIAL':
await handleOVADownload(item);
break;
default:
throw new Error('Tipo di media non supportato');
}
} 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>
@ -87,28 +124,44 @@ const alertDownload = (message?: any) => {
<h1 class="details-title">{{ item.name }}</h1>
<h3> {{ item.score }}</h3>
<div class="details-description">
<p v-if="item.type == 'TV_ANIME'">{{ 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>
</div>
<h3 v-if="animeEpisodes.length > 0 && !loading">Numero episodi: {{ animeEpisodes[0].episode_total }}</h3>
<h3 v-if="animeEpisodes.length > 0 && !loading">Numero episodi: {{ totalEpisodes }}</h3>
<h3 v-if="tvShowEpisodes.length > 0 && !loading">Numero stagioni: {{ tvShowEpisodes.length }}</h3>
<hr style="opacity: 0.2"/>
<hr style="opacity: 0.2; margin-top: 10px"/>
<!--DOWNLOAD SECTION-->
<div class="download-section">
<button :disabled="loading || selectingEpisodes" @click="downloadItems">Scarica {{['TV_ANIME', 'TV'].includes(item.type)? 'tutto' : ''}}</button>
<button :disabled="loading || selectingEpisodes"
@click.prevent="downloadAllItems">
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>Download episodi</button>
<button @click="toggleEpisodeSelection">
{{selectingEpisodes ? 'Disattiva' : 'Attiva'}} selezione episodi
</button>
<button :disabled="selectedEpisodes.length == 0"
@click="downloadSelectedEpisodes">
Download episodi selezionati
</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">
<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 class="episode-title">Episodio {{ episode.number }}</div>
</div>
<div v-else-if="item.type == 'TV'" v-for="(season, index) in tvShowEpisodes" class="season-item">
@ -126,7 +179,7 @@ const alertDownload = (message?: any) => {
<!--MOVIES SECTION-->
<div v-else-if="!loading && ['MOVIE', 'OVA', 'SPECIAL'].includes(item.type)">
<p>Questo è un {{item.type}}</p>
<p>Questo è un {{item.type}} (QUESTO TESTO E' A SCOPO DI TEST)</p>
</div>
<!--LOADING SECTION-->