mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
feat: Integrate Telegram bot support for animeunity and altadefinizione
This commit is contained in:
parent
97f19b78a9
commit
67dda3d504
@ -1,24 +1,24 @@
|
|||||||
# 21.05.24
|
# 16.03.25
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
|
|
||||||
# External library
|
# External library
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.prompt import Prompt
|
from rich.prompt import Prompt
|
||||||
|
|
||||||
|
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from StreamingCommunity.Api.Template import get_select_title
|
from StreamingCommunity.Api.Template import get_select_title
|
||||||
|
|
||||||
|
|
||||||
# Logic class
|
# Logic class
|
||||||
from StreamingCommunity.Api.Template.config_loader import site_constant
|
from StreamingCommunity.Api.Template.config_loader import site_constant
|
||||||
|
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance
|
||||||
from .site import title_search, table_show_manager, media_search_manager
|
from .site import title_search, table_show_manager, media_search_manager
|
||||||
from .film import download_film
|
from .film import download_film
|
||||||
from .series import download_series
|
from .series import download_series
|
||||||
|
|
||||||
|
|
||||||
# Variable
|
# Variable
|
||||||
indice = 2
|
indice = 2
|
||||||
_useFor = "film_serie"
|
_useFor = "film_serie"
|
||||||
@ -34,28 +34,47 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False):
|
|||||||
"""
|
"""
|
||||||
Main function of the application for film and series.
|
Main function of the application for film and series.
|
||||||
"""
|
"""
|
||||||
if string_to_search is None:
|
|
||||||
string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip()
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot = get_bot_instance()
|
||||||
|
|
||||||
|
if string_to_search is None:
|
||||||
|
|
||||||
|
# Chiedi la scelta all'utente con il bot Telegram
|
||||||
|
string_to_search = bot.ask(
|
||||||
|
"key_search",
|
||||||
|
f"Inserisci la parola da cercare\noppure back per tornare alla scelta: ",
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
if string_to_search == 'back':
|
||||||
|
# Riavvia lo script
|
||||||
|
# Chiude il processo attuale e avvia una nuova istanza dello script
|
||||||
|
subprocess.Popen([sys.executable] + sys.argv)
|
||||||
|
sys.exit()
|
||||||
|
else:
|
||||||
|
if string_to_search is None:
|
||||||
|
string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip()
|
||||||
|
|
||||||
len_database = title_search(quote_plus(string_to_search))
|
len_database = title_search(quote_plus(string_to_search))
|
||||||
|
|
||||||
# Return list of elements
|
# Return list of elements
|
||||||
if get_onylDatabase:
|
if get_onylDatabase:
|
||||||
return media_search_manager
|
return media_search_manager
|
||||||
|
|
||||||
if len_database > 0:
|
if len_database > 0:
|
||||||
|
|
||||||
# Select title from list
|
# Select title from list
|
||||||
select_title = get_select_title(table_show_manager, media_search_manager)
|
select_title = get_select_title(table_show_manager, media_search_manager)
|
||||||
|
|
||||||
if select_title.type == 'tv':
|
if select_title.type == 'tv':
|
||||||
download_series(select_title)
|
download_series(select_title)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
download_film(select_title)
|
download_film(select_title)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}")
|
console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}")
|
||||||
|
|
||||||
# Retry
|
# Retry
|
||||||
search()
|
search()
|
||||||
|
@ -8,7 +8,7 @@ import httpx
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
|
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance, TelegramSession
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from StreamingCommunity.Util.os import os_manager
|
from StreamingCommunity.Util.os import os_manager
|
||||||
from StreamingCommunity.Util.message import start_message
|
from StreamingCommunity.Util.message import start_message
|
||||||
@ -41,6 +41,19 @@ def download_film(select_title: MediaItem) -> str:
|
|||||||
Return:
|
Return:
|
||||||
- str: output path if successful, otherwise None
|
- str: output path if successful, otherwise None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot = get_bot_instance()
|
||||||
|
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 = TelegramSession.get_session()
|
||||||
|
if script_id != "unknown":
|
||||||
|
TelegramSession.updateScriptId(script_id, select_title.name)
|
||||||
|
|
||||||
start_message()
|
start_message()
|
||||||
console.print(f"[yellow]Download: [red]{select_title.name} \n")
|
console.print(f"[yellow]Download: [red]{select_title.name} \n")
|
||||||
|
|
||||||
@ -51,6 +64,9 @@ def download_film(select_title: MediaItem) -> str:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"[red]Error fetching the page: {e}")
|
console.print(f"[red]Error fetching the page: {e}")
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"ERRORE\n\nErrore durante il recupero della pagina.\n\n{e}", None)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Create mostraguarda url
|
# Create mostraguarda url
|
||||||
@ -59,6 +75,8 @@ def download_film(select_title: MediaItem) -> str:
|
|||||||
url_mostraGuarda = iframe_tag[0].get('data-src')
|
url_mostraGuarda = iframe_tag[0].get('data-src')
|
||||||
if not url_mostraGuarda:
|
if not url_mostraGuarda:
|
||||||
console.print("Error: data-src attribute not found in iframe.")
|
console.print("Error: data-src attribute not found in iframe.")
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"ERRORE\n\nErrore: attributo data-src non trovato nell'iframe", None)
|
||||||
|
|
||||||
# Extract supervideo URL
|
# Extract supervideo URL
|
||||||
try:
|
try:
|
||||||
@ -67,6 +85,8 @@ def download_film(select_title: MediaItem) -> str:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"[red]Error fetching mostraguarda link: {e}")
|
console.print(f"[red]Error fetching mostraguarda link: {e}")
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"ERRORE\n\nErrore durante il recupero del link mostra/guarda.\n\n{e}", None)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Create supervio URL
|
# Create supervio URL
|
||||||
@ -91,6 +111,13 @@ def download_film(select_title: MediaItem) -> str:
|
|||||||
output_path=os.path.join(mp4_path, title_name)
|
output_path=os.path.join(mp4_path, title_name)
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
|
||||||
|
# Delete script_id
|
||||||
|
script_id = TelegramSession.get_session()
|
||||||
|
if script_id != "unknown":
|
||||||
|
TelegramSession.deleteScriptId(script_id)
|
||||||
|
|
||||||
if r_proc['error'] is not None:
|
if r_proc['error'] is not None:
|
||||||
try: os.remove(r_proc['path'])
|
try: os.remove(r_proc['path'])
|
||||||
except: pass
|
except: pass
|
||||||
|
@ -8,7 +8,7 @@ from typing import Tuple
|
|||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.prompt import Prompt
|
from rich.prompt import Prompt
|
||||||
|
|
||||||
|
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance, TelegramSession
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from StreamingCommunity.Util.message import start_message
|
from StreamingCommunity.Util.message import start_message
|
||||||
from StreamingCommunity.Lib.Downloader import HLS_Downloader
|
from StreamingCommunity.Lib.Downloader import HLS_Downloader
|
||||||
@ -56,9 +56,23 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra
|
|||||||
console.print(f"[yellow]Download: [red]{index_season_selected}:{index_episode_selected} {obj_episode.name}")
|
console.print(f"[yellow]Download: [red]{index_season_selected}:{index_episode_selected} {obj_episode.name}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot = get_bot_instance()
|
||||||
|
|
||||||
|
# Invio a telegram
|
||||||
|
bot.send_message(
|
||||||
|
f"Download in corso\nSerie: {scrape_serie.series_name}\nStagione: {index_season_selected}\nEpisodio: {index_episode_selected}\nTitolo: {obj_episode.name}",
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get script_id and update it
|
||||||
|
script_id = TelegramSession.get_session()
|
||||||
|
if script_id != "unknown":
|
||||||
|
TelegramSession.updateScriptId(script_id, f"{scrape_serie.series_name} - S{index_season_selected} - E{index_episode_selected} - {obj_episode.name}")
|
||||||
|
|
||||||
# Define filename and path for the downloaded video
|
# Define filename and path for the downloaded video
|
||||||
mp4_name = f"{map_episode_title(scrape_serie.serie_name, index_season_selected, index_episode_selected, obj_episode.name)}.mp4"
|
mp4_name = f"{map_episode_title(scrape_serie.series_name, index_season_selected, index_episode_selected, obj_episode.name)}.mp4"
|
||||||
mp4_path = os.path.join(site_constant.SERIES_FOLDER, scrape_serie.serie_name, f"S{index_season_selected}")
|
mp4_path = os.path.join(site_constant.SERIES_FOLDER, scrape_serie.series_name, f"S{index_season_selected}")
|
||||||
|
|
||||||
# Retrieve scws and if available master playlist
|
# Retrieve scws and if available master playlist
|
||||||
video_source = VideoSource(obj_episode.url)
|
video_source = VideoSource(obj_episode.url)
|
||||||
@ -127,6 +141,9 @@ def download_series(select_season: MediaItem) -> None:
|
|||||||
Parameters:
|
Parameters:
|
||||||
- select_season (MediaItem): Selected media item (TV series).
|
- select_season (MediaItem): Selected media item (TV series).
|
||||||
"""
|
"""
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot = get_bot_instance()
|
||||||
|
|
||||||
start_message()
|
start_message()
|
||||||
|
|
||||||
# Init class
|
# Init class
|
||||||
@ -138,10 +155,28 @@ def download_series(select_season: MediaItem) -> None:
|
|||||||
|
|
||||||
# Prompt user for season selection and download episodes
|
# Prompt user for season selection and download episodes
|
||||||
console.print(f"\n[green]Seasons found: [red]{seasons_count}")
|
console.print(f"\n[green]Seasons found: [red]{seasons_count}")
|
||||||
index_season_selected = msg.ask(
|
|
||||||
"\n[cyan]Insert season number [yellow](e.g., 1), [red]* [cyan]to download all seasons, "
|
if site_constant.TELEGRAM_BOT:
|
||||||
"[yellow](e.g., 1-2) [cyan]for a range of seasons, or [yellow](e.g., 3-*) [cyan]to download from a specific season to the end"
|
console.print("\n[cyan]Insert season number [yellow](e.g., 1), [red]* [cyan]to download all seasons, "
|
||||||
)
|
"[yellow](e.g., 1-2) [cyan]for a range of seasons, or [yellow](e.g., 3-*) [cyan]to download from a specific season to the end")
|
||||||
|
|
||||||
|
bot.send_message(f"Stagioni trovate: {seasons_count}", None)
|
||||||
|
|
||||||
|
index_season_selected = bot.ask(
|
||||||
|
"select_title_episode",
|
||||||
|
"Menu di selezione delle stagioni\n\n"
|
||||||
|
"- Inserisci il numero della stagione (ad esempio, 1)\n"
|
||||||
|
"- Inserisci * per scaricare tutte le stagioni\n"
|
||||||
|
"- Inserisci un intervallo di stagioni (ad esempio, 1-2) per scaricare da una stagione all'altra\n"
|
||||||
|
"- Inserisci (ad esempio, 3-*) per scaricare dalla stagione specificata fino alla fine della serie",
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
index_season_selected = msg.ask(
|
||||||
|
"\n[cyan]Insert season number [yellow](e.g., 1), [red]* [cyan]to download all seasons, "
|
||||||
|
"[yellow](e.g., 1-2) [cyan]for a range of seasons, or [yellow](e.g., 3-*) [cyan]to download from a specific season to the end"
|
||||||
|
)
|
||||||
|
|
||||||
# Manage and validate the selection
|
# Manage and validate the selection
|
||||||
list_season_select = manage_selection(index_season_selected, seasons_count)
|
list_season_select = manage_selection(index_season_selected, seasons_count)
|
||||||
@ -161,4 +196,12 @@ def download_series(select_season: MediaItem) -> None:
|
|||||||
else:
|
else:
|
||||||
|
|
||||||
# Otherwise, let the user select specific episodes for the single season
|
# Otherwise, let the user select specific episodes for the single season
|
||||||
download_episode(i_season, scrape_serie, download_all=False)
|
download_episode(i_season, scrape_serie, download_all=False)
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"Finito di scaricare tutte le serie e episodi", None)
|
||||||
|
|
||||||
|
# Get script_id
|
||||||
|
script_id = TelegramSession.get_session()
|
||||||
|
if script_id != "unknown":
|
||||||
|
TelegramSession.deleteScriptId(script_id)
|
@ -6,7 +6,7 @@ import httpx
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
|
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from StreamingCommunity.Util.config_json import config_manager
|
from StreamingCommunity.Util.config_json import config_manager
|
||||||
from StreamingCommunity.Util.headers import get_userAgent
|
from StreamingCommunity.Util.headers import get_userAgent
|
||||||
@ -35,6 +35,9 @@ def title_search(title_search: str) -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: The number of titles found.
|
int: The number of titles found.
|
||||||
"""
|
"""
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot = get_bot_instance()
|
||||||
|
|
||||||
media_search_manager.clear()
|
media_search_manager.clear()
|
||||||
table_show_manager.clear()
|
table_show_manager.clear()
|
||||||
|
|
||||||
@ -47,14 +50,22 @@ def title_search(title_search: str) -> int:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}")
|
console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}")
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"ERRORE\n\nErrore nella richiesta di ricerca:\n\n{e}", None)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# Prepara le scelte per l'utente
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
choices = []
|
||||||
|
|
||||||
# Create soup istance
|
# Create soup istance
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
|
||||||
# Collect data from soup
|
# Collect data from soup
|
||||||
for movie_div in soup.find_all("div", class_="movie"):
|
for movie_div in soup.find_all("div", class_="movie"):
|
||||||
|
|
||||||
title_tag = movie_div.find("h2", class_="movie-title")
|
title_tag = movie_div.find("h2", class_="movie-title")
|
||||||
title = title_tag.find("a").get_text(strip=True)
|
title = title_tag.find("a").get_text(strip=True)
|
||||||
url = title_tag.find("a").get("href")
|
url = title_tag.find("a").get("href")
|
||||||
@ -70,6 +81,16 @@ def title_search(title_search: str) -> int:
|
|||||||
'name': title,
|
'name': title,
|
||||||
'type': tipo
|
'type': tipo
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
choice_text = f"{i} - {title} ({tipo})"
|
||||||
|
choices.append(choice_text)
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
if choices:
|
||||||
|
bot.send_message(f"Lista dei risultati:", choices)
|
||||||
|
|
||||||
# Return the number of titles found
|
# Return the number of titles found
|
||||||
return media_search_manager.get_length()
|
return media_search_manager.get_length()
|
@ -34,7 +34,7 @@ class GetSerieInfo:
|
|||||||
"""
|
"""
|
||||||
response = httpx.get(self.url, headers=self.headers)
|
response = httpx.get(self.url, headers=self.headers)
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
self.serie_name = soup.find("title").get_text(strip=True).split(" - ")[0]
|
self.series_name = soup.find("title").get_text(strip=True).split(" - ")[0]
|
||||||
|
|
||||||
# Process all seasons
|
# Process all seasons
|
||||||
season_items = soup.find_all('div', class_='accordion-item')
|
season_items = soup.find_all('div', class_='accordion-item')
|
||||||
|
@ -123,7 +123,11 @@ def download_series(select_title: MediaItem):
|
|||||||
|
|
||||||
last_command = bot.ask(
|
last_command = bot.ask(
|
||||||
"select_title",
|
"select_title",
|
||||||
f"Inserisci l'indice del media o * per scaricare tutti i media, oppure 1-2 o 3-* per un intervallo di media.",
|
"Menu di selezione degli episodi: \n\n"
|
||||||
|
"- Inserisci il numero dell'episodio (ad esempio, 1)\n"
|
||||||
|
"- Inserisci * per scaricare tutti gli episodi\n"
|
||||||
|
"- Inserisci un intervallo di episodi (ad esempio, 1-2) per scaricare da un episodio all'altro\n"
|
||||||
|
"- Inserisci (ad esempio, 3-*) per scaricare dall'episodio specificato fino alla fine della serie",
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ def title_search(title_search: str) -> int:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}")
|
console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}")
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"ERRORE\n\nErrore nella richiesta di ricerca:\n\n{e}", None)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Prepara le scelte per l'utente
|
# Prepara le scelte per l'utente
|
||||||
@ -82,6 +84,8 @@ def title_search(title_search: str) -> int:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error parsing a film entry: {e}")
|
print(f"Error parsing a film entry: {e}")
|
||||||
|
if site_constant.TELEGRAM_BOT:
|
||||||
|
bot.send_message(f"ERRORE\n\nErrore nell'analisi del film:\n\n{e}", None)
|
||||||
|
|
||||||
if site_constant.TELEGRAM_BOT:
|
if site_constant.TELEGRAM_BOT:
|
||||||
if choices:
|
if choices:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user