Mythus commited on
Commit
2058a45
·
verified ·
1 Parent(s): e4f56db

Upload 4 files

Browse files
Files changed (4) hide show
  1. .env +2 -0
  2. filmpertutti.py +191 -0
  3. requirements.txt +7 -0
  4. run.py +40 -0
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ TMDB_KEY= "713f5bb9e1903628cc8a41c487d833c4"
2
+ DOMAIN = "casino"
filmpertutti.py ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from dotenv import load_dotenv
11
+
12
+ load_dotenv(".env")
13
+
14
+ TMDB_KEY = os.getenv('TMDB_KEY')
15
+ DOMAIN = os.getenv('DOMAIN')
16
+
17
+ headers = {
18
+ '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',
19
+ 'Accept-Language': 'en-US,en;q=0.5'
20
+ }
21
+ month_mapping = {
22
+ 'Jan': 'Gennaio', 'Feb': 'Febbraio', 'Mar': 'Marzo', 'Apr': 'Aprile',
23
+ 'May': 'Maggio', 'Jun': 'Giugno', 'Jul': 'Luglio', 'Aug': 'Agosto',
24
+ 'Sep': 'Settembre', 'Oct': 'Ottobre', 'Nov': 'Novembre', 'Dec': 'Dicembre'
25
+ }
26
+ def convert_US_date(date):
27
+ us_data = next((country_data for country_data in date['results'] if country_data["iso_3166_1"] == "US"), None)
28
+ if us_data:
29
+ us_release_dates_type_3 = [rd for rd in us_data['release_dates'] if rd['type'] == 3]
30
+ # Sort the list of release dates and get the latest
31
+ us_release_dates_type_3.sort(key = lambda x: x['release_date'], reverse=True)
32
+ if len(us_release_dates_type_3) > 0:
33
+ latest_release_date = us_release_dates_type_3[0]['release_date']
34
+ date = latest_release_date.split('T')[0]
35
+ print('Latest US theatrical release date:', date)
36
+ return date
37
+ def get_TMDb_id_from_IMDb_id(imdb_id):
38
+ if ":" in imdb_id:
39
+ season = imdb_id.split(":")[1]
40
+ episode = imdb_id[-1]
41
+ ismovie = 0
42
+ imdb_id = imdb_id.split(":")[0]
43
+ else:
44
+ ismovie = 1
45
+ response = requests.get(f'https://api.themoviedb.org/3/find/{imdb_id}',
46
+ params={'external_source': 'imdb_id', 'api_key': f'{TMDB_KEY}'})
47
+ tmbda = response.json()
48
+ if tmbda['movie_results']:
49
+ print(tmbda)
50
+ return tmbda['movie_results'][0]['id'], ismovie
51
+ elif tmbda['tv_results']:
52
+ print(tmbda['tv_results'][0]['id'])
53
+ return tmbda['tv_results'][0]['id'], season, episode , ismovie
54
+ else:
55
+ return None
56
+
57
+ def get_mamma(tmbda,ismovie):
58
+ tmdb = TMDb()
59
+ tmdb.api_key = f'{TMDB_KEY}'
60
+ tmdb.language = 'it'
61
+ if ismovie == 0:
62
+ tv = TV()
63
+ show= tv.details(tmbda)
64
+ showname = show.name
65
+ date= show.first_air_date
66
+ else:
67
+ movie = Movie()
68
+ show= movie.details(tmbda)
69
+ showname= show.title
70
+ #Get all release dates
71
+ date = show.release_dates
72
+ #GET US RELEASE DATE because filmpertutti somewhy uses US release date
73
+ date = convert_US_date(date)
74
+ if ismovie==0:
75
+ return showname,date
76
+ else:
77
+ return showname,date
78
+
79
+ def search(query,date):
80
+ response = requests.get(query)
81
+ soup = BeautifulSoup(response.text, 'html.parser')
82
+ test= soup.find('div', class_='elementor-posts-container elementor-posts elementor-posts--skin-classic elementor-grid')
83
+ # Find all articles
84
+ articles = test.select('article', class_='elementor-post elementor-grid-item post-629565')
85
+
86
+ # Loop through each article
87
+ for article in articles:
88
+ # Find the link inside the article
89
+ link = article.find('a', class_='elementor-post__thumbnail__link')
90
+
91
+ # Extract the href attribute from the link
92
+ href = link['href']
93
+ #replace base url for easier scraping
94
+ href = href.replace('definizionealta.com', f'filmpertutti.{DOMAIN}')
95
+ href = href.replace('definizionealta.com', 'filmpertutti.casino')
96
+ #Get the correct serie by checking if the date is equals
97
+ series_response = requests.get(href, headers=headers)
98
+ series_soup = BeautifulSoup(series_response.text, 'html.parser')
99
+ release_span = series_soup.find('span', class_='released')
100
+ if release_span:
101
+ if release_span.text != "Data di uscita: N/A":
102
+ date_string = release_span.text.split(': ')[-1] # Get the date part
103
+ for eng, ita in month_mapping.items():
104
+ date_string = re.sub(rf'\b{eng}\b', ita, date_string)
105
+
106
+ # Swap to YY-MM-DD formatting using dateparser
107
+ release_date = dateparser.parse(date_string, languages=['it']).strftime("%Y-%m-%d")
108
+ print(release_date)
109
+ if release_date == date:
110
+ url = href
111
+ break
112
+ return url
113
+
114
+ def get_episode_link(season,episode,url):
115
+ response = requests.get(url)
116
+ # Extract the 'link' field from the headers
117
+ link_field = response.headers.get('Link')
118
+ links = link_field.split(',')
119
+ links = [link.split(';')[0].strip('<>') for link in links]
120
+ second_link = links[2]
121
+ #Get the ID of the serie (not tmbd or imbd)
122
+ tid = second_link.split("=")[1]
123
+ episode = int(episode)
124
+ season = int(season)
125
+ tlink = f'{url}?show_video=true&post_id={tid}&season_id={season-1}&episode_id={episode-1}'
126
+ return tlink
127
+
128
+
129
+ def get_film(url):
130
+ tlink = url + "?show_video=true"
131
+ return tlink
132
+
133
+ def get_real_link(tlink):
134
+ page = requests.get(tlink, headers=headers)
135
+ soup = BeautifulSoup(page.content, features="lxml")
136
+ iframe_src = soup.find('iframe')['src']
137
+
138
+ iframe_page = requests.get(iframe_src, headers=headers)
139
+ iframe_soup = BeautifulSoup(iframe_page.content, features="lxml")
140
+
141
+ mega_button = iframe_soup.find('div', attrs={'class': 'megaButton', 'rel': 'nofollow'}, string='MIXDROP')
142
+ if mega_button:
143
+ real_link = mega_button.get('meta-link')
144
+ print(f'Real link: {real_link}')
145
+ return real_link
146
+
147
+ def get_true_link(real_link):
148
+ response = requests.get(real_link, headers=headers)
149
+ [s1, s2] = re.search(r"\}\('(.+)',.+,'(.+)'\.split", response.text).group(1, 2)
150
+ schema = s1.split(";")[2][5:-1]
151
+ terms = s2.split("|")
152
+ charset = string.digits + string.ascii_letters
153
+ d = dict()
154
+ for i in range(len(terms)):
155
+ d[charset[i]] = terms[i] or charset[i]
156
+ s = 'https:'
157
+ for c in schema:
158
+ s += d[c] if c in d else c
159
+ print(s)
160
+ return s
161
+
162
+ def get_stream_link(imbd):
163
+ info = get_TMDb_id_from_IMDb_id(imbd)
164
+ if len(info)==4 :
165
+ tmdba,season,episode,ismovie = info
166
+ else:
167
+ tmdba,ismovie = info
168
+ showname,date = get_mamma(tmdba,ismovie)
169
+
170
+ query = "https://definizionealta.com/?s=" + f"{showname}"
171
+ query = query.replace(" ", "+").replace("–", "+").replace("—","+")
172
+ print(query)
173
+ url = search(query,date)
174
+ print(ismovie)
175
+ print(url)
176
+ if ismovie == 0:
177
+ episode_link = get_episode_link(season,episode,url)
178
+ print(episode_link)
179
+ #Let's get mixdrop link
180
+ real_link = get_real_link(episode_link)
181
+ #let's get delivery link, streaming link
182
+ streaming_link = get_true_link(real_link)
183
+ return streaming_link
184
+ elif ismovie == 1:
185
+ film_link = get_film(url)
186
+ print(film_link)
187
+ #Let's get mixdrop link
188
+ real_link = get_real_link(film_link)
189
+ #let's get delivery link, streaming link
190
+ streaming_link = get_true_link(real_link)
191
+ return streaming_link
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ bs4
2
+ tmdbv3api
3
+ string
4
+ datetime
5
+ dateparser
6
+ dotenv
7
+ flask
run.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, jsonify, abort
2
+ from filmpertutti import get_stream_link
3
+
4
+ app = Flask(__name__)
5
+
6
+ MANIFEST = {
7
+ "id": "org.stremio.mammamia",
8
+ "version": "1.0.0",
9
+ "catalogs": [],
10
+ "resources": ["stream"],
11
+ "types": ["movie", "series"],
12
+ "name": "Mamma Mia",
13
+ "description": "Addon providing HTTPS Stream for Italian Movies/Series",
14
+ "logo":"https://creazilla-store.fra1.digitaloceanspaces.com/emojis/49647/pizza-emoji-clipart-md.png"
15
+ }
16
+
17
+ def respond_with(data):
18
+ resp = jsonify(data)
19
+ resp.headers['Access-Control-Allow-Origin'] = '*'
20
+ resp.headers['Access-Control-Allow-Headers'] = '*'
21
+ return resp
22
+
23
+ @app.route('/manifest.json')
24
+ def addon_manifest():
25
+ return respond_with(MANIFEST)
26
+
27
+ @app.route('/stream/<type>/<id>.json')
28
+ def addon_stream(type, id):
29
+ if type not in MANIFEST['types']:
30
+ abort(404)
31
+
32
+ url = get_stream_link(id) # call the function to dynamically get stream links
33
+
34
+
35
+ streams = {'streams': [{'title': 'Stream URL', 'url': url}]}
36
+
37
+ return respond_with(streams)
38
+
39
+ if __name__ == '__main__':
40
+ app.run(port=5000)