Spaces:
Paused
Paused
Delete filmpertutti.py
Browse files- filmpertutti.py +0 -179
filmpertutti.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
from tmdbv3api import TMDb, Movie, TV
|
| 3 |
-
import requests
|
| 4 |
-
from bs4 import BeautifulSoup
|
| 5 |
-
import string
|
| 6 |
-
import re
|
| 7 |
-
from datetime import datetime
|
| 8 |
-
import dateparser
|
| 9 |
-
import os
|
| 10 |
-
import logging
|
| 11 |
-
TMDB_KEY = os.getenv('TMDB_KEY')
|
| 12 |
-
DOMAIN = os.getenv('DOMAIN')
|
| 13 |
-
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
|
| 14 |
-
|
| 15 |
-
headers = {
|
| 16 |
-
'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',
|
| 17 |
-
'Accept-Language': 'en-US,en;q=0.5'
|
| 18 |
-
}
|
| 19 |
-
cookies = {
|
| 20 |
-
'PHPSESSID': 'uu8g29ahp247ocjdf70k28diuc',
|
| 21 |
-
}
|
| 22 |
-
month_mapping = {
|
| 23 |
-
'Jan': 'Gennaio', 'Feb': 'Febbraio', 'Mar': 'Marzo', 'Apr': 'Aprile',
|
| 24 |
-
'May': 'Maggio', 'Jun': 'Giugno', 'Jul': 'Luglio', 'Aug': 'Agosto',
|
| 25 |
-
'Sep': 'Settembre', 'Oct': 'Ottobre', 'Nov': 'Novembre', 'Dec': 'Dicembre'
|
| 26 |
-
}
|
| 27 |
-
def convert_US_date(date):
|
| 28 |
-
us_data = next((country_data for country_data in date['results'] if country_data["iso_3166_1"] == "US"), None)
|
| 29 |
-
if us_data:
|
| 30 |
-
us_release_dates_type_3 = [rd for rd in us_data['release_dates'] if rd['type'] == 3]
|
| 31 |
-
# Sort the list of release dates and get the latest
|
| 32 |
-
us_release_dates_type_3.sort(key = lambda x: x['release_date'], reverse=True)
|
| 33 |
-
if len(us_release_dates_type_3) > 0:
|
| 34 |
-
latest_release_date = us_release_dates_type_3[0]['release_date']
|
| 35 |
-
date = latest_release_date.split('T')[0]
|
| 36 |
-
print('Latest US theatrical release date:', date)
|
| 37 |
-
return date
|
| 38 |
-
else:
|
| 39 |
-
us_release_dates_type_4 = [rd for rd in us_data['release_dates'] if rd['type'] == 4]
|
| 40 |
-
us_release_dates_type_4.sort(key = lambda x: x['release_date'], reverse=True)
|
| 41 |
-
if len(us_release_dates_type_4) > 0:
|
| 42 |
-
latest_release_date = us_release_dates_type_4[0]['release_date']
|
| 43 |
-
date = latest_release_date.split('T')[0]
|
| 44 |
-
print('Latest US theatrical release date (type 4):', date)
|
| 45 |
-
return date
|
| 46 |
-
def get_TMDb_id_from_IMDb_id(imdb_id):
|
| 47 |
-
if ":" in imdb_id:
|
| 48 |
-
season = imdb_id.split(":")[1]
|
| 49 |
-
episode = imdb_id[-1]
|
| 50 |
-
ismovie = 0
|
| 51 |
-
imdb_id = imdb_id.split(":")[0]
|
| 52 |
-
else:
|
| 53 |
-
ismovie = 1
|
| 54 |
-
response = requests.get(f'https://api.themoviedb.org/3/find/{imdb_id}',
|
| 55 |
-
params={'external_source': 'imdb_id', 'api_key': f'{TMDB_KEY}'})
|
| 56 |
-
tmbda = response.json()
|
| 57 |
-
if tmbda['movie_results']:
|
| 58 |
-
print(tmbda)
|
| 59 |
-
return tmbda['movie_results'][0]['id'], ismovie
|
| 60 |
-
elif tmbda['tv_results']:
|
| 61 |
-
print(tmbda['tv_results'][0]['id'])
|
| 62 |
-
return tmbda['tv_results'][0]['id'], season, episode , ismovie
|
| 63 |
-
else:
|
| 64 |
-
return None
|
| 65 |
-
|
| 66 |
-
def get_mamma(tmbda,ismovie):
|
| 67 |
-
tmdb = TMDb()
|
| 68 |
-
tmdb.api_key = f'{TMDB_KEY}'
|
| 69 |
-
tmdb.language = 'it'
|
| 70 |
-
if ismovie == 0:
|
| 71 |
-
tv = TV()
|
| 72 |
-
show= tv.details(tmbda)
|
| 73 |
-
showname = show.name
|
| 74 |
-
date= show.first_air_date
|
| 75 |
-
else:
|
| 76 |
-
movie = Movie()
|
| 77 |
-
show= movie.details(tmbda)
|
| 78 |
-
showname= show.title
|
| 79 |
-
#Get all release dates
|
| 80 |
-
date = show.release_dates
|
| 81 |
-
#GET US RELEASE DATE because filmpertutti somewhy uses US release date
|
| 82 |
-
date = convert_US_date(date)
|
| 83 |
-
if ismovie==0:
|
| 84 |
-
return showname,date
|
| 85 |
-
else:
|
| 86 |
-
return showname,date
|
| 87 |
-
|
| 88 |
-
def search(query,date):
|
| 89 |
-
response = requests.get(query).json()
|
| 90 |
-
for json in response:
|
| 91 |
-
link = json['link']
|
| 92 |
-
tid = json['id']
|
| 93 |
-
series_response = requests.get(link, headers=headers)
|
| 94 |
-
series_soup = BeautifulSoup(series_response.text, 'lxml')
|
| 95 |
-
release_span = series_soup.find('span', class_='released')
|
| 96 |
-
if release_span:
|
| 97 |
-
if release_span.text != "Data di uscita: N/A":
|
| 98 |
-
date_string = release_span.text.split(': ')[-1] # Get the date part
|
| 99 |
-
for eng, ita in month_mapping.items():
|
| 100 |
-
date_string = re.sub(rf'\b{eng}\b', ita, date_string)
|
| 101 |
-
|
| 102 |
-
# Swap to YY-MM-DD formatting using dateparser
|
| 103 |
-
release_date = dateparser.parse(date_string, languages=['it']).strftime("%Y-%m-%d")
|
| 104 |
-
print(release_date)
|
| 105 |
-
if release_date == date:
|
| 106 |
-
url = link
|
| 107 |
-
tid = tid
|
| 108 |
-
break
|
| 109 |
-
return url, tid
|
| 110 |
-
|
| 111 |
-
def get_episode_link(season,episode,tid,url):
|
| 112 |
-
episode = int(episode)
|
| 113 |
-
season = int(season)
|
| 114 |
-
tlink = f'{url}?show_video=true&post_id={tid}&season_id={season-1}&episode_id={episode-1}'
|
| 115 |
-
return tlink
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
def get_film(url):
|
| 119 |
-
tlink = url + "?show_video=true"
|
| 120 |
-
return tlink
|
| 121 |
-
|
| 122 |
-
def get_real_link(tlink):
|
| 123 |
-
page = requests.get(tlink, headers=headers)
|
| 124 |
-
soup = BeautifulSoup(page.content, features="lxml")
|
| 125 |
-
iframe_src = soup.find('iframe')['src']
|
| 126 |
-
|
| 127 |
-
iframe_page = requests.get(iframe_src, headers=headers)
|
| 128 |
-
iframe_soup = BeautifulSoup(iframe_page.content, features="lxml")
|
| 129 |
-
|
| 130 |
-
mega_button = iframe_soup.find('div', attrs={'class': 'megaButton', 'rel': 'nofollow'}, string='MIXDROP')
|
| 131 |
-
if mega_button:
|
| 132 |
-
real_link = mega_button.get('meta-link')
|
| 133 |
-
logging.info(f'Real link: {real_link}')
|
| 134 |
-
return real_link
|
| 135 |
-
|
| 136 |
-
def get_true_link(real_link):
|
| 137 |
-
response = requests.get(real_link, headers=headers, cookies=cookies)
|
| 138 |
-
[s1, s2] = re.search(r"\}\('(.+)',.+,'(.+)'\.split", response.text).group(1, 2)
|
| 139 |
-
schema = s1.split(";")[2][5:-1]
|
| 140 |
-
terms = s2.split("|")
|
| 141 |
-
charset = string.digits + string.ascii_letters
|
| 142 |
-
d = dict()
|
| 143 |
-
for i in range(len(terms)):
|
| 144 |
-
d[charset[i]] = terms[i] or charset[i]
|
| 145 |
-
s = 'https:'
|
| 146 |
-
for c in schema:
|
| 147 |
-
s += d[c] if c in d else c
|
| 148 |
-
logging.info(s)
|
| 149 |
-
return s
|
| 150 |
-
|
| 151 |
-
def get_stream_link(imbd):
|
| 152 |
-
info = get_TMDb_id_from_IMDb_id(imbd)
|
| 153 |
-
if len(info)==4 :
|
| 154 |
-
tmdba,season,episode,ismovie = info
|
| 155 |
-
else:
|
| 156 |
-
tmdba,ismovie = info
|
| 157 |
-
showname,date = get_mamma(tmdba,ismovie)
|
| 158 |
-
showname = showname.replace(" ", "+").replace("–", "+").replace("—","+")
|
| 159 |
-
query = f'https://filmpertutti.{DOMAIN}/wp-json/wp/v2/posts?search={showname}&page=1&_fields=link,id'
|
| 160 |
-
print(query)
|
| 161 |
-
url,tid = search(query,date)
|
| 162 |
-
print(ismovie)
|
| 163 |
-
print(url)
|
| 164 |
-
if ismovie == 0:
|
| 165 |
-
episode_link = get_episode_link(season,episode,tid,url)
|
| 166 |
-
print(episode_link)
|
| 167 |
-
#Let's get mixdrop link
|
| 168 |
-
real_link = get_real_link(episode_link)
|
| 169 |
-
#let's get delivery link, streaming link
|
| 170 |
-
streaming_link = get_true_link(real_link)
|
| 171 |
-
return streaming_link
|
| 172 |
-
elif ismovie == 1:
|
| 173 |
-
film_link = get_film(url)
|
| 174 |
-
print(film_link)
|
| 175 |
-
#Let's get mixdrop link
|
| 176 |
-
real_link = get_real_link(film_link)
|
| 177 |
-
#let's get delivery link, streaming link
|
| 178 |
-
streaming_link = get_true_link(real_link)
|
| 179 |
-
return streaming_link
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|