diff --git a/.gitignore b/.gitignore index 4c49bd7..2eea525 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -.env +.env \ No newline at end of file diff --git a/__pycache__/convert.cpython-311.pyc b/__pycache__/convert.cpython-311.pyc index 1064d4d..34e2f25 100644 Binary files a/__pycache__/convert.cpython-311.pyc and b/__pycache__/convert.cpython-311.pyc differ diff --git a/__pycache__/convert_date.cpython-311.pyc b/__pycache__/convert_date.cpython-311.pyc new file mode 100644 index 0000000..290562c Binary files /dev/null and b/__pycache__/convert_date.cpython-311.pyc differ diff --git a/__pycache__/loadenv.cpython-311.pyc b/__pycache__/loadenv.cpython-311.pyc index fe18b98..f79b939 100644 Binary files a/__pycache__/loadenv.cpython-311.pyc and b/__pycache__/loadenv.cpython-311.pyc differ diff --git a/convert.py b/convert.py index 482686d..e9f360f 100644 --- a/convert.py +++ b/convert.py @@ -21,6 +21,4 @@ def get_TMDb_id_from_IMDb_id(imdb_id): print(tmbda['tv_results'][0]['id']) return tmbda['tv_results'][0]['id'], season, episode , ismovie else: - return None - -get_TMDb_id_from_IMDb_id("tt1839578:1:1") \ No newline at end of file + return None \ No newline at end of file diff --git a/US_date.py b/convert_date.py similarity index 50% rename from US_date.py rename to convert_date.py index e2f14c8..2c259b0 100644 --- a/US_date.py +++ b/convert_date.py @@ -17,4 +17,23 @@ def convert_US_date(date): latest_release_date = us_release_dates_type_4[0]['release_date'] date = latest_release_date.split('T')[0] print('Latest US theatrical release date (type 4):', date) + return date +def convert_IT_date(date): + it_data = next((country_data for country_data in date['results'] if country_data["iso_3166_1"] == "IT"), None) + if it_data: + it_release_dates_type_3 = [rd for rd in it_data['release_dates'] if rd['type'] == 3] + # Sort the list of release dates and get the latest + it_release_dates_type_3.sort(key = lambda x: x['release_date'], reverse=True) + if len(it_release_dates_type_3) > 0: + latest_release_date = it_release_dates_type_3[0]['release_date'] + date = latest_release_date.split('T')[0] + print('Latest IT theatrical release date:', date) + return date + else: + it_release_dates_type_4 = [rd for rd in it_data['release_dates'] if rd['type'] == 4] + it_release_dates_type_4.sort(key = lambda x: x['release_date'], reverse=True) + if len(it_release_dates_type_4) > 0: + latest_release_date = it_release_dates_type_4[0]['release_date'] + date = latest_release_date.split('T')[0] + print('Latest IT theatrical release date (type 4):', date) return date \ No newline at end of file diff --git a/filmpertutti.py b/filmpertutti.py index 8a3dc8c..20e3ccd 100644 --- a/filmpertutti.py +++ b/filmpertutti.py @@ -9,7 +9,7 @@ import dateparser from convert import get_TMDb_id_from_IMDb_id from loadenv import load_env from info import get_info -from US_date import convert_US_date +from convert_date import convert_US_date TMDB_KEY, DOMAIN = load_env() headers = { @@ -86,12 +86,13 @@ def get_true_link(real_link): return s def get_stream_link(imbd): - info = get_TMDb_id_from_IMDb_id(imbd) - if len(info)==4 : - tmdba,season,episode,ismovie = info + general = get_TMDb_id_from_IMDb_id(imbd) + if len(general)==4 : + tmdba,season,episode,ismovie = general else: - tmdba,ismovie = info - showname,date = get_info(tmdba,ismovie) + tmdba,ismovie = general + type = "Filmpertutti" + showname,date = get_info(tmdba,ismovie,type) showname = showname.replace(" ", "+").replace("–", "+").replace("—","+") query = f'https://filmpertutti.{DOMAIN}/wp-json/wp/v2/posts?search={showname}&page=1&_fields=link,id' print(query) diff --git a/info.py b/info.py index e1761b5..248c6db 100644 --- a/info.py +++ b/info.py @@ -1,9 +1,9 @@ from loadenv import load_env from tmdbv3api import TMDb, Movie, TV -from US_date import convert_US_date -TMDB_KEY, DOMAIN = load_env() +from convert_date import convert_US_date, convert_IT_date +TMDB_KEY, DOMAIN, FILMPERTUTTI,STREAMINGCOMMUNITY = load_env() -def get_info(tmbda,ismovie): +def get_info(tmbda,ismovie,type): tmdb = TMDb() tmdb.api_key = f'{TMDB_KEY}' tmdb.language = 'it' @@ -11,15 +11,23 @@ def get_info(tmbda,ismovie): tv = TV() show= tv.details(tmbda) showname = show.name - date= show.first_air_date + if type == "Filmpertutti": + date= show.first_air_date + elif type == "StreamingCommunity": + date = show.last_air_date + print("Real date",date) else: movie = Movie() show= movie.details(tmbda) showname= show.title #Get all release dates date = show.release_dates - #GET US RELEASE DATE because filmpertutti somewhy uses US release date - date = convert_US_date(date) + if type == "Filmpertutti": + #GET US RELEASE DATE because filmpertutti somewhy uses US release date + date = convert_US_date(date) + elif type == "StreamingCommunity": + date = convert_IT_date(date) + print (date) if ismovie==0: return showname,date else: diff --git a/loadenv.py b/loadenv.py index c609f84..6fce1d2 100644 --- a/loadenv.py +++ b/loadenv.py @@ -4,4 +4,6 @@ load_dotenv(".env") def load_env(): TMDB_KEY = os.getenv('TMDB_KEY') DOMAIN = os.getenv('DOMAIN') - return TMDB_KEY, DOMAIN \ No newline at end of file + FILMPERTUTTI = os.getenv('FILMPERTUTTI') + STREAMINGCOMMUNITY = os.getenv('STREAMINGCOMMUNITY') + return TMDB_KEY, DOMAIN, FILMPERTUTTI, STREAMINGCOMMUNITY \ No newline at end of file diff --git a/run.py b/run.py index 6cb6298..6991599 100644 --- a/run.py +++ b/run.py @@ -1,5 +1,7 @@ from flask import Flask, jsonify, abort from filmpertutti import get_stream_link +from loadenv import load_env +TMDB_KEY, DOMAIN, FILMPERTUTTI, STREAMINGCOMMUNITY = load_env() app = Flask(__name__) @@ -34,8 +36,10 @@ def root(): def addon_stream(type, id): if type not in MANIFEST['types']: abort(404) - - url = get_stream_link(id) # call the function to dynamically get stream links + if FILMPERTUTTI == 1: + url = get_stream_link(id) # call the function to dynamically get stream links + elif STREAMINGCOMMUNITY == 1: + return "Not implemented yet" streams = {'streams': [{'title': 'Stream URL', 'url': url}]} diff --git a/streamingcommunity.py b/streamingcommunity.py new file mode 100644 index 0000000..aa4c89f --- /dev/null +++ b/streamingcommunity.py @@ -0,0 +1,48 @@ +from tmdbv3api import TMDb, Movie, TV +import requests +from bs4 import BeautifulSoup,SoupStrainer +from datetime import datetime +import dateparser +from convert import get_TMDb_id_from_IMDb_id +from loadenv import load_env +from info import get_info +TMDB_KEY= load_env() +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.10; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', + 'Accept-Language': 'en-US,en;q=0.5' +} +def streaming_community(imbd): + print(load_env) + general = get_TMDb_id_from_IMDb_id(imbd) + if len(general)==4 : + tmdba,season,episode,ismovie = general + else: + tmdba,ismovie = general + type = "StreamingCommunity" + showname,date = get_info(tmdba,ismovie,type) + showname = showname.replace(" ", "+").replace("–", "+").replace("—","+") + query = f'https://streamingcommunity.boston/api/search?q={showname}' + date,tid,slug = search(query,date) + if ismovie == 0: + url = get_film(tid) + return "NOT IMPLEMENTED YET" + + + +def search(query,date): + response = requests.get(query).json() + for json in response: + release_date = json['last_air_date'] + tid = json['id'] + slug = json['slug'] + if date == release_date: + return date,tid,slug +def get_film(tid): + url = f'https://streamingcommunity.boston/watch/{tid}' + response = requests.get(url, headers=headers) + soup = BeautifulSoup(response.text, 'lxml', parse_only=SoupStrainer('iframe')) + vixid = soup['src'] + vixid = vixid.split("/embed/")[1].split("?")[0] + print (vixid) + +streaming_community("tt16426418") \ No newline at end of file