Add macos (#258)

* Add trending film and tv

* Add macos to pyinstaller
This commit is contained in:
Dark1291 2025-02-11 09:48:50 +01:00 committed by GitHub
parent 0de2d32620
commit 10a5f1b88f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 94 additions and 115 deletions

View File

@ -52,7 +52,7 @@ jobs:
if: github.event.inputs.publish_pypi == 'false'
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
@ -67,6 +67,7 @@ jobs:
run: |
$latestTag = git describe --tags --abbrev=0
echo "latest_tag=$latestTag" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Set up Python
uses: actions/setup-python@v4
with:
@ -92,7 +93,7 @@ jobs:
--hidden-import=Cryptodome.Random --hidden-import=Pillow `
--hidden-import=pyTelegramBotAPI --additional-hooks-dir=pyinstaller/hooks `
--add-data "StreamingCommunity;StreamingCommunity" `
--name=StreamingCommunity --icon=".github/media/logo.ico" test_run.py
--name=StreamingCommunity_win --icon=".github/media/logo.ico" test_run.py
- name: Build executable with PyInstaller (Linux)
if: matrix.os == 'ubuntu-latest'
@ -107,28 +108,51 @@ jobs:
--hidden-import=Cryptodome.Random --hidden-import=Pillow \
--hidden-import=pyTelegramBotAPI --additional-hooks-dir=pyinstaller/hooks \
--add-data "StreamingCommunity:StreamingCommunity" \
--name=StreamingCommunity test_run.py
--name=StreamingCommunity_linux test_run.py
- name: Build executable with PyInstaller (macOS)
if: matrix.os == 'macos-latest'
run: |
pyinstaller --onefile --hidden-import=pycryptodomex --hidden-import=ua_generator \
--hidden-import=qbittorrentapi --hidden-import=qbittorrent --hidden-import=googlesearch \
--hidden-import=bs4 --hidden-import=httpx --hidden-import=rich --hidden-import=tqdm \
--hidden-import=m3u8 --hidden-import=psutil --hidden-import=unidecode \
--hidden-import=jsbeautifier --hidden-import=pathvalidate \
--hidden-import=Cryptodome.Cipher --hidden-import=Cryptodome.Cipher.AES \
--hidden-import=Cryptodome.Util --hidden-import=Cryptodome.Util.Padding \
--hidden-import=Cryptodome.Random --hidden-import=Pillow \
--hidden-import=pyTelegramBotAPI --additional-hooks-dir=pyinstaller/hooks \
--add-data "StreamingCommunity:StreamingCommunity" \
--name=StreamingCommunity_mac test_run.py
- name: Upload executable (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: StreamingCommunity-Windows
path: dist/StreamingCommunity.exe
name: StreamingCommunity_win
path: dist/StreamingCommunity_win.exe
- name: Upload executable (Linux)
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: StreamingCommunity-Linux
path: dist/StreamingCommunity
name: StreamingCommunity_linux
path: dist/StreamingCommunity_linux
- name: Upload executable (macOS)
if: matrix.os == 'macos-latest'
uses: actions/upload-artifact@v4
with:
name: StreamingCommunity_mac
path: dist/StreamingCommunity_mac
- name: Create or update release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.latest_tag }}
files: |
dist/StreamingCommunity.exe
dist/StreamingCommunity
dist/StreamingCommunity_win.exe
dist/StreamingCommunity_linux
dist/StreamingCommunity_mac
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -58,11 +58,14 @@
# Installation
<p align="center">
<a href="https://github.com/Arrowar/StreamingCommunity/releases/latest/download/StreamingCommunity.exe">
<img src="https://img.shields.io/badge/-Windows_x64-blue.svg?style=for-the-badge&logo=windows" alt="Windows">
<a href="https://github.com/Arrowar/StreamingCommunity/releases/latest/download/StreamingCommunity_win.exe">
<img src="https://img.shields.io/badge/-Windows-blue.svg?style=for-the-badge&logo=windows" alt="Windows">
</a>
<a href="https://github.com/Arrowar/StreamingCommunity/releases/latest/download/StreamingCommunity.zip">
<img src="https://img.shields.io/badge/-Source_tar-green.svg?style=for-the-badge" alt="Source Tarball">
<a href="https://github.com/Arrowar/StreamingCommunity/releases/latest/download/StreamingCommunity_mac">
<img src="https://img.shields.io/badge/-macOS-black.svg?style=for-the-badge&logo=apple" alt="macOS">
</a>
<a href="https://github.com/Arrowar/StreamingCommunity/releases/latest/download/StreamingCommunity_linux">
<img src="https://img.shields.io/badge/-Linux-orange.svg?style=for-the-badge&logo=linux" alt="Linux">
</a>
<a href="https://github.com/Arrowar/StreamingCommunity/releases">
<img src="https://img.shields.io/badge/-All_Versions-lightgrey.svg?style=for-the-badge" alt="All Versions">

View File

@ -6,17 +6,19 @@ from typing import Dict
# External libraries
import httpx
from rich.console import Console
# Internal utilities
from .obj_tmbd import Json_film
from StreamingCommunity.Util.console import console
from StreamingCommunity.Util._jsonConfig import config_manager
from StreamingCommunity.Util.table import TVShowManager
# Variable
table_show_manager = TVShowManager()
api_key = "a800ed6c93274fb857ea61bd9e7256c5"
MAX_TIMEOUT = config_manager.get_int("REQUESTS", "timeout")
@ -33,7 +35,7 @@ def get_select_title(table_show_manager, generic_obj):
# Check if the generic_obj list is empty
if not generic_obj:
Console.print("\n[red]No media items available.")
console.print("\n[red]No media items available.")
return None
# Example of available colors for columns
@ -76,7 +78,7 @@ def get_select_title(table_show_manager, generic_obj):
# Handle user's quit command
if last_command == "q" or last_command == "quit":
Console.print("\n[red]Quit [white]...")
console.print("\n[red]Quit [white]...")
sys.exit(0)
# Check if the selected index is within range
@ -84,7 +86,7 @@ def get_select_title(table_show_manager, generic_obj):
return generic_obj[int(last_command)]
else:
Console.print("\n[red]Wrong index")
console.print("\n[red]Wrong index")
sys.exit(0)
@ -98,7 +100,6 @@ class TheMovieDB:
"""
self.api_key = api_key
self.base_url = "https://api.themoviedb.org/3"
self.console = Console()
#self.genres = self._fetch_genres()
def _make_request(self, endpoint, params=None):
@ -117,7 +118,7 @@ class TheMovieDB:
params['api_key'] = self.api_key
url = f"{self.base_url}/{endpoint}"
response = httpx.get(url, params=params)
response = httpx.get(url, params=params, timeout=MAX_TIMEOUT)
response.raise_for_status()
return response.json()
@ -132,77 +133,45 @@ class TheMovieDB:
genres = self._make_request("genre/movie/list")
return {genre['id']: genre['name'] for genre in genres.get('genres', [])}
def _process_and_add_tv_shows(self, data, columns):
def _display_top_5(self, category: str, data, name_key='title'):
"""
Process TV show data and add it to the TV show manager.
Display top 5 most popular items in a single line with colors.
Parameters:
- data (list): List of dictionaries containing the data to process.
- columns (list): A list of tuples, where each tuple contains the column name and the key to fetch the data from the dictionary.
- category (str): Category label (e.g., "Trending films", "Trending TV shows")
- data (list): List of media items
- name_key (str): Key to use for the name ('title' for movies, 'name' for TV shows)
"""
# Define column styles with colors
tv_show_manager = TVShowManager()
column_info = {
col[0]: {'color': col[2] if len(col) > 2 else 'white'}
for col in columns
}
tv_show_manager.add_column(column_info)
# Add each item to the TV show manager, including rank
for index, item in enumerate(data):
# Convert genre IDs to genre names
genre_names = [self.genres.get(genre_id, 'Unknown') for genre_id in item.get('genre_ids', [])]
tv_show = {
col[0]: str(item.get(col[1], 'N/A')) if col[1] != 'genre_ids' else ', '.join(genre_names)
for col in columns
}
tv_show_manager.add_tv_show(tv_show)
# Colors for the titles
colors = ['cyan', 'magenta', 'yellow', 'green', 'blue']
# Display the processed TV show data
tv_show_manager.display_data(tv_show_manager.tv_shows[tv_show_manager.slice_start:tv_show_manager.slice_end])
def _display_with_title(self, title: str, data, columns):
"""
Display data with a title.
Parameters:
- title (str): The title to display.
- data (list): List of dictionaries containing the data to process.
- columns (list): A list of tuples, where each tuple contains the column name and the key to fetch the data from the dictionary.
"""
self.console.print(f"\n{title}", style="bold underline")
self._process_and_add_tv_shows(data, columns)
# Sort by popularity and get top 5
sorted_data = sorted(data, key=lambda x: x.get('popularity', 0), reverse=True)[:5]
# Create list of colored titles
colored_items = []
for item, color in zip(sorted_data, colors):
title = item.get(name_key, 'Unknown')
colored_items.append(f"[{color}]{title}[/]")
# Join with colored arrows and print with proper category label
console.print(
f"[bold purple]{category}:[/] {' [red]→[/] '.join(colored_items)}"
)
def display_trending_tv_shows(self):
"""
Fetch and display the trending TV shows of the week.
Fetch and display the top 5 trending TV shows of the week.
"""
data = self._make_request("trending/tv/week").get("results", [])
columns = [
("Title", "name", 'cyan'),
("First Air Date", "first_air_date", 'green'),
("Popularity", "popularity", 'magenta'),
("Genres", "genre_ids", 'blue'),
("Origin Country", "origin_country", 'red'),
("Vote Average", "vote_average", 'yellow')
]
self._display_with_title("Trending TV Shows of the Week", data, columns)
self._display_top_5("Trending TV shows", data, name_key='name')
def display_trending_films(self):
"""
Fetch and display the trending films of the week.
Fetch and display the top 5 trending films of the week.
"""
data = self._make_request("trending/movie/week").get("results", [])
columns = [
("Title", "title", 'cyan'),
("Release Date", "release_date", 'green'),
("Popularity", "popularity", 'magenta'),
("Genres", "genre_ids", 'blue'),
("Vote Average", "vote_average", 'yellow')
]
self._display_with_title("Trending Films of the Week", data, columns)
self._display_top_5("Trending films", data, name_key='title')
def search_movie(self, movie_name: str):
"""
@ -217,10 +186,10 @@ class TheMovieDB:
generic_obj = []
data = self._make_request("search/movie", {"query": movie_name}).get("results", [])
if not data:
self.console.print("No movies found with that name.", style="red")
console.print("No movies found with that name.", style="red")
return None
self.console.print("\nSelect a Movie:")
console.print("\nSelect a Movie:")
for i, movie in enumerate(data, start=1):
generic_obj.append({
'name': movie['title'],
@ -243,7 +212,7 @@ class TheMovieDB:
"""
movie = self._make_request(f"movie/{tmdb_id}")
if not movie:
self.console.print("Movie not found.", style="red")
console.print("Movie not found.", style="red")
return None
return Json_film(movie)
@ -260,12 +229,12 @@ class TheMovieDB:
"""
data = self._make_request("search/tv", {"query": tv_name}).get("results", [])
if not data:
self.console.print("No TV shows found with that name.", style="red")
console.print("No TV shows found with that name.", style="red")
return None
self.console.print("\nSelect a TV Show:")
console.print("\nSelect a TV Show:")
for i, show in enumerate(data, start=1):
self.console.print(f"{i}. {show['name']} (First Air Date: {show.get('first_air_date', 'N/A')})")
console.print(f"{i}. {show['name']} (First Air Date: {show.get('first_air_date', 'N/A')})")
choice = int(input("Enter the number of the show you want: ")) - 1
selected_show = data[choice]
@ -283,12 +252,12 @@ class TheMovieDB:
"""
data = self._make_request(f"tv/{tv_show_id}").get("seasons", [])
if not data:
self.console.print("No seasons found for this TV show.", style="red")
console.print("No seasons found for this TV show.", style="red")
return None
self.console.print("\nSelect a Season:")
console.print("\nSelect a Season:")
for i, season in enumerate(data, start=1):
self.console.print(f"{i}. {season['name']} (Episodes: {season['episode_count']})")
console.print(f"{i}. {season['name']} (Episodes: {season['episode_count']})")
choice = int(input("Enter the number of the season you want: ")) - 1
return data[choice]["season_number"]
@ -306,12 +275,12 @@ class TheMovieDB:
"""
data = self._make_request(f"tv/{tv_show_id}/season/{season_number}").get("episodes", [])
if not data:
self.console.print("No episodes found for this season.", style="red")
console.print("No episodes found for this season.", style="red")
return None
self.console.print("\nSelect an Episode:")
console.print("\nSelect an Episode:")
for i, episode in enumerate(data, start=1):
self.console.print(f"{i}. {episode['name']} (Air Date: {episode.get('air_date', 'N/A')})")
console.print(f"{i}. {episode['name']} (Air Date: {episode.get('air_date', 'N/A')})")
choice = int(input("Enter the number of the episode you want: ")) - 1
return data[choice]
@ -319,28 +288,4 @@ class TheMovieDB:
# Output
tmdb = TheMovieDB(api_key)
"""
Example:
@ movie
movie_name = "Interstellar"
movie_id = tmdb.search_movie(movie_name)
if movie_id:
movie_details = tmdb.get_movie_details(tmdb_id=movie_id)
print(movie_details)
@ series
tv_name = "Game of Thrones"
tv_show_id = tmdb.search_tv_show(tv_name)
if tv_show_id:
season_number = tmdb.get_seasons(tv_show_id=tv_show_id)
if season_number:
episode = tmdb.get_episodes(tv_show_id=tv_show_id, season_number=season_number)
print(episode)
"""
tmdb = TheMovieDB(api_key)

View File

@ -16,9 +16,10 @@ from typing import Callable
from StreamingCommunity.Util.message import start_message
from StreamingCommunity.Util.console import console, msg
from StreamingCommunity.Util._jsonConfig import config_manager
from StreamingCommunity.Upload.update import update as git_update
from StreamingCommunity.Util.os import os_summary
from StreamingCommunity.Util.logger import Logger
from StreamingCommunity.Upload.update import update as git_update
from StreamingCommunity.Lib.TMBD import tmdb
# Telegram util
@ -132,13 +133,18 @@ def initialize():
console.log("[red]Install python version > 3.7.16")
sys.exit(0)
# Trending tmbd
print()
tmdb.display_trending_films()
tmdb.display_trending_tv_shows()
# Attempting GitHub update
try:
git_update()
except:
console.log("[red]Error with loading github.")
def restart_script():
"""Riavvia lo script con gli stessi argomenti della riga di comando."""
print("\n🔄 Riavvio dello script...\n")

View File

@ -15,5 +15,6 @@ if TELEGRAM_BOT:
TelegramSession.set_session(script_id)
main(script_id)
else:
main()