100 lines
3.0 KiB
Python

# 3.12.23
import os
import time
# Internal utilities
from StreamingCommunity.Util.console import console, msg
from StreamingCommunity.Util.os import os_manager
from StreamingCommunity.Util.message import start_message
from StreamingCommunity.Util.call_stack import get_call_stack
from StreamingCommunity.Lib.Downloader import HLS_Downloader
# Logic class
from StreamingCommunity.Api.Template.Util import execute_search
from StreamingCommunity.Api.Template.Class.SearchType import MediaItem
# Player
from StreamingCommunity.Api.Player.vixcloud import VideoSource
# Variable
from .costant import SITE_NAME, MOVIE_FOLDER
# Telegram bot instance
from StreamingCommunity.HelpTg.telegram_bot import get_bot_instance
from StreamingCommunity.HelpTg.session import get_session, updateScriptId, deleteScriptId
from StreamingCommunity.Util._jsonConfig import config_manager
TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot')
def download_film(select_title: MediaItem) -> str:
"""
Downloads a film using the provided film ID, title name, and domain.
Parameters:
- domain (str): The domain of the site
- version (str): Version of site.
Return:
- str: output path
"""
if TELEGRAM_BOT:
bot = get_bot_instance()
# Invio a telegram
bot.send_message(f"Download in corso:\n{select_title.name}", None)
# Viene usato per lo screen
console.print(f"## Download: [red]{select_title.name} ##")
# Get script_id
script_id = get_session()
if script_id != "unknown":
updateScriptId(script_id, select_title.name)
# Start message and display film information
start_message()
console.print(f"[yellow]Download: [red]{select_title.name} \n")
# Init class
video_source = VideoSource(SITE_NAME, False)
video_source.setup(select_title.id)
# Retrieve scws and if available master playlist
video_source.get_iframe(select_title.id)
video_source.get_content()
master_playlist = video_source.get_playlist()
# Define the filename and path for the downloaded film
title_name = os_manager.get_sanitize_file(select_title.name) + ".mp4"
mp4_path = os.path.join(MOVIE_FOLDER, title_name.replace(".mp4", ""))
# Download the film using the m3u8 playlist, and output filename
r_proc = HLS_Downloader(
m3u8_playlist=master_playlist,
output_filename=os.path.join(mp4_path, title_name)
).start()
if TELEGRAM_BOT:
# Delete script_id
script_id = get_session()
if script_id != "unknown":
deleteScriptId(script_id)
"""if r_proc == 404:
time.sleep(2)
# Re call search function
if msg.ask("[green]Do you want to continue [white]([red]y[white])[green] or return at home[white]([red]n[white]) ", choices=['y', 'n'], default='y', show_choices=True) == "n":
frames = get_call_stack()
execute_search(frames[-4])"""
if r_proc != None:
console.print("[green]Result: ")
console.print(r_proc)
return os.path.join(mp4_path, title_name)