Francesco Grazioso 1c5f960b16
Feat/app api and frontend (#140)
* minor fixes

* created basic django app

* add django dependency

* created basic search endpoint

* created retrieve method for search

* remove retrieve

* start implementing download endpoint (only movie for now)

* start implementing episode info for series

* finished get_episodes_info

* minor fixes

* add download anime episode

* start implementing download for tv series

* refactor methods

* finished download endpoint (will implement possibility to download single episodes of season in tv series)

* new domain and black on project

* start

* add cors

* add start gui command

* add gui for search

* edited .gitignore

* create component for media details

* better UX/UI

* edited anime episode to stream response (better experience)

* implemented UI for media details (TODO add download capabilities)

* fix poster fetching

* minor fixes

* fix cors error

* start implementing download

* fix typing on anime movies

* refactor

* refactor + add download OVA

* add plot for all anime types

* add download for all anime episodes

* add download all tv series episodes

* fix crach if localStorage is undefined

* moved download logic in separeted file

* fix wrong index passed while downloading tv series

* fix style searchbar

* add loader to search button and add enter listener while searching

* remove dependency from loading episodes to download all in anime series

* add function to download selected episodes for anime

* add sh command to kill gui

* fix messages in kill_gui.sh

* start implementing download select episodes for tv series (to be tested) + run black and eslint

* start  refactoring  to version 2.0

* start implementing preview endpoint

* finish reimplement version 2.0
2024-06-01 13:13:09 +02:00

123 lines
3.2 KiB
Python

# 11.03.24
import os
import logging
# Internal utilities
from Src.Util.console import console, msg
from Src.Util._jsonConfig import config_manager
from Src.Lib.Hls.downloader import Downloader
from Src.Util.message import start_message
# Logic class
from .Core.Vix_player.player import VideoSource
from .Core.Util import manage_selection
# Config
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
from .costant import ANIME_FOLDER, SERIES_FOLDER, MOVIE_FOLDER
# Variable
video_source = VideoSource()
def download_episode(index_select: int, custom_video_source: VideoSource = None):
"""
Downloads the selected episode.
Args:
- index_select (int): Index of the episode to download.
"""
active_video_source = custom_video_source if custom_video_source is not None else video_source
# Get information about the selected episode
obj_episode = active_video_source.get_info_episode(index_select)
start_message()
console.print(f"[yellow]Download: [red]EP_{obj_episode.number} \n")
# Get the embed URL for the episode
embed_url = active_video_source.get_embed(obj_episode.id)
# Parse parameter in embed text
active_video_source.parse_script(embed_url)
# Create output path
mp4_path = None
mp4_name = f"{index_select + 1}.mp4"
if active_video_source.is_series:
mp4_path = os.path.join(ROOT_PATH, ANIME_FOLDER, SERIES_FOLDER, active_video_source.series_name)
else:
mp4_path = os.path.join(ROOT_PATH, ANIME_FOLDER, MOVIE_FOLDER, active_video_source.series_name)
# Crete downloader
obj_download = Downloader(
m3u8_playlist = active_video_source.get_playlist(),
output_filename = os.path.join(mp4_path, mp4_name)
)
# Start downloading
obj_download.start()
def donwload_series(tv_id: int, tv_name: str):
"""
Function to download episodes of a TV series.
Args:
- tv_id (int): The ID of the TV series.
- tv_name (str): The name of the TV series.
"""
# Set up video source
video_source.setup(
media_id = tv_id,
series_name = tv_name
)
# Get the count of episodes for the TV series
episoded_count = video_source.get_count_episodes()
console.log(f"[cyan]Episodes find: [red]{episoded_count}")
# Prompt user to select an episode index
last_command = msg.ask("\n[cyan]Insert media [red]index [yellow]or [red](*) [cyan]to download all media [yellow]or [red][1-2] [cyan]for a range of media")
# Manage user selection
list_episode_select = manage_selection(last_command, episoded_count)
# Download selected episodes
if len(list_episode_select) == 1 and last_command != "*":
download_episode(list_episode_select[0]-1)
# Download all other episodes selecter
else:
for i_episode in list_episode_select:
download_episode(i_episode-1)
def donwload_film(id_film: int, title_name: str):
"""
Function to download a film.
Args:
- id_film (int): The ID of the film.
- title_name (str): The title of the film.
"""
# Set up video source
video_source.setup(
media_id = id_film,
series_name = title_name
)
video_source.is_series = False
# Start download
download_episode(0)