From fc7c92466d59b52c13f60d10a8fdf492518e30c7 Mon Sep 17 00:00:00 2001 From: UrloMythus Date: Thu, 11 Jul 2024 17:10:50 +0200 Subject: [PATCH] Fixed the english name and changed back to TMDB API --- filmpertutti.py | 22 +++++++++++++++++----- info.py | 30 +++++++++++++++++++++++++++++- streamingcommunity.py | 11 ++++------- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/filmpertutti.py b/filmpertutti.py index 79f72b5..bdb7015 100644 --- a/filmpertutti.py +++ b/filmpertutti.py @@ -7,7 +7,7 @@ import re from datetime import datetime import dateparser from convert import get_TMDb_id_from_IMDb_id -from info import get_info, is_movie +from info import get_info_tmdb, is_movie, get_info_imdb from convert_date import convert_US_date import logging import config @@ -93,12 +93,23 @@ def filmpertutti(imdb): general = is_movie(imdb) ismovie = general[0] imdb_id = general[1] + type = "Filmpertutti" if ismovie == 0 : season = int(general[2]) episode = int(general[3]) - tmdba = get_TMDb_id_from_IMDb_id(imdb_id) - type = "Filmpertutti" - showname,date = get_info(tmdba,ismovie,type) + if "tt" in imdb: + if ismovie == 0: + #Get showname and date + showname,date = get_info_imdb(imdb_id,ismovie,type) + else: + #THIS IS needed cause the only way to get all releases dates is by giving a tmdb ID not a IMDB + tmdba = get_TMDb_id_from_IMDb_id(imdb_id) + showname,date = get_info_tmdb(tmdba,ismovie,type) + + elif "tmdb" in imdb: + #Get showname and date + tmdba = imdb_id.replace("tmdb:","") + showname,date = get_info_tmdb(tmdba,ismovie,type) showname = showname.replace(" ", "+").replace("–", "+").replace("—","+") #Build the query query = f'https://filmpertutti.{FT_DOMAIN}/wp-json/wp/v2/posts?search={showname}&page=1&_fields=link,id' @@ -122,4 +133,5 @@ def filmpertutti(imdb): #let's get delivery link, streaming link streaming_link = get_true_link(real_link) print(streaming_link) - return streaming_link \ No newline at end of file + return streaming_link +filmpertutti("tt16426418") \ No newline at end of file diff --git a/info.py b/info.py index 6b5deff..4e9fc9b 100644 --- a/info.py +++ b/info.py @@ -1,9 +1,10 @@ from loadenv import load_env from tmdbv3api import TMDb, Movie, TV from convert_date import convert_US_date, convert_IT_date +import requests TMDB_KEY= load_env() -def get_info(tmbda,ismovie,type): +def get_info_tmdb(tmbda,ismovie,type): tmdb = TMDb() tmdb.api_key = f'{TMDB_KEY}' tmdb.language = 'it' @@ -28,6 +29,33 @@ def get_info(tmbda,ismovie,type): return showname,date + + +def get_info_imdb(imdb_id, ismovie, type): + + resp = requests.get(f'https://api.themoviedb.org/3/find/{imdb_id}?api_key={TMDB_KEY}&language=it&external_source=imdb_id') + data = resp.json() + if ismovie == 0: + showname = data['tv_results'][0]['name'] + if type == "Filmpertutti": + date= data['tv_results'][0]['first_air_date'] + print("Real date",date) + return showname, date + elif type == "StreamingCommunity": + return showname + + elif ismovie == 1: + showname= data['movie_results'][0]['title'] + if type == "Filmpertutti": + return + elif type == "StreamingCommunity": + return showname + + + + + + def is_movie(imdb_id): if "tmdb:" in imdb_id: imdb_id = imdb_id.replace("tmdb:","") diff --git a/streamingcommunity.py b/streamingcommunity.py index 7f1c0c3..18242f8 100644 --- a/streamingcommunity.py +++ b/streamingcommunity.py @@ -5,7 +5,7 @@ from bs4 import BeautifulSoup,SoupStrainer from datetime import datetime import dateparser from convert import get_TMDb_id_from_IMDb_id -from info import get_info, is_movie +from info import get_info_tmdb, is_movie, get_info_imdb import config import json #Get domain @@ -99,16 +99,13 @@ def streaming_community(imdb): season = int(general[2]) episode = int(general[3]) if "tt" in imdb: - #If it is a imbd then conver it to tmbd - tmdba = get_TMDb_id_from_IMDb_id(imdb_id) - showname = requests.get(f'https://v3.sg.media-imdb.com/suggestion/a/{imdb_id}.json') - showname = showname.json() - showname = showname['d'][-1]['l'] + #Get showname + showname = get_info_imdb(imdb_id,ismovie,"StreamingCommunity") else: #else just equals them tmdba = imdb_id.replace("tmdb:","") type = "StreamingCommunity" - showname = get_info(tmdba,ismovie,type) + showname = get_info_tmdb(tmdba,ismovie,type) showname = showname.replace(" ", "+").replace("–", "+").replace("—","+") query = f'https://streamingcommunity.{SC_DOMAIN}/api/search?q={showname}' tid,slug = search(query)