File size: 7,253 Bytes
2a9b5a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa883eb
 
2a9b5a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
db96a69
 
2a9b5a5
 
 
 
 
 
 
 
733f3a8
 
2a9b5a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

from tmdbv3api import TMDb, Movie, TV
from bs4 import BeautifulSoup,SoupStrainer
import string
import re
import dateparser
from Src.Utilities.convert import get_TMDb_id_from_IMDb_id
from Src.Utilities.info import get_info_tmdb, is_movie, get_info_imdb
from Src.Utilities.convert_date import convert_US_date
import Src.Utilities.config as config
FT_DOMAIN = config.FT_DOMAIN
WOA = 0
#Some basic headers
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'
}
#Map months to check if date = date
month_mapping = {
    'Jan': 'Gennaio', 'Feb': 'Febbraio', 'Mar': 'Marzo', 'Apr': 'Aprile',
    'May': 'Maggio', 'Jun': 'Giugno', 'Jul': 'Luglio', 'Aug': 'Agosto',
    'Sep': 'Settembre', 'Oct': 'Ottobre', 'Nov': 'Novembre', 'Dec': 'Dicembre'
}

async def search(query,date,client,season,ismovie):
    response = await client.get(query)
    response = response.json()
    #Get link tid of every item and then open the link to see if the date = date
    for json in response:
        link = json['link']
        tid = json['id']
        series_response = await client.get(link, headers=headers, allow_redirects=True, timeout = 30)
        series_soup = BeautifulSoup(series_response.text, 'lxml')
        release_span = series_soup.find('span', class_='released')
        if release_span:
            if release_span.text != "Data di uscita: N/A":
                date_string = release_span.text.split(': ')[-1]  # Get the date part
                release_date = date_string[-4:]
            if WOA:
                for eng, ita in month_mapping.items():
                    date_string = re.sub(rf'\b{eng}\b', ita, date_string)

    # Swap to YY-MM-DD formatting using dateparser
                release_date = dateparser.parse(date_string, languages=['it']).strftime("%Y-%m-%d")
        if release_date == date:
            url = link
            tid = tid
            if ismovie == 0:
                Seasons = series_soup.find_all('span', class_="season-name")
                i = 0
                for item in Seasons:
                    season_text = item.text.strip()
                    if season in season_text and "SUB" not in season_text:
                        actual_season = i
                        return url, tid, actual_season
                    else:
                        i = i + 1 
                        continue
            else:        
                actual_season = None
                return url, tid, actual_season 
        else:
            print("")

def get_episode_link(actual_season,episode,tid,url): 
    #Get the link from where we have to obtain mixdrop link
    tlink = f'{url}?show_video=true&post_id={tid}&season_id={actual_season}&episode_id={episode-1}'
    return tlink


def get_film(url):
    #Get the link from where we have to obtain mixdrop link
    tlink = url + "?show_video=true"
    return tlink

async def get_real_link(tlink,client):
    #Some basic code to get the mixdrop link
    page = await client.get(tlink, headers=headers, allow_redirects=True)
    soup = BeautifulSoup(page.content, features="lxml",parse_only=SoupStrainer('iframe'))
    iframe_src = soup.find('iframe')['src']
    iframe_page = await client.get(iframe_src, headers=headers, allow_redirects=True, timeout = 30)
    iframe_soup = BeautifulSoup(iframe_page.content, features="lxml")

    mega_button = iframe_soup.find('div', attrs={'class': 'megaButton', 'rel': 'nofollow'}, string='MIXDROP')
    if mega_button:
        real_link = mega_button.get('meta-link')
        return real_link
    
async def get_true_link(real_link,client):

    response = await client.get(real_link, headers=headers, allow_redirects=True,timeout = 30)
    [s1, s2] = re.search(r"\}\('(.+)',.+,'(.+)'\.split", response.text).group(1, 2)
    schema = s1.split(";")[2][5:-1]
    terms = s2.split("|")
    charset = string.digits + string.ascii_letters
    d = dict()
    for i in range(len(terms)):
        d[charset[i]] = terms[i] or charset[i]
    s = 'https:'
    for c in schema:
        s += d[c] if c in d else c
    return s

async def filmpertutti(imdb,client):
    general = is_movie(imdb)
    ismovie = general[0]
    imdb_id = general[1]
    type = "Filmpertutti"
    if ismovie == 0 : 
        season = general[2]
        episode = int(general[3])
    if "tt" in imdb:
        if ismovie == 0:
        #Get showname and date
            showname,date = await get_info_imdb(imdb_id,ismovie,type,client)
        else:
            #THIS IS needed cause the only way to get all releases dates is by giving a tmdb ID not a IMDB
            showname,date = await get_info_imdb(imdb_id,ismovie,type, client)
            season = None

    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'
    try:
        url,tid,actual_season = await search(query,date,client,season,ismovie)
    except:
        print("No results found")
        return None
    if ismovie == 0:
        episode_link =  get_episode_link(actual_season,episode,tid,url)
        #Let's get mixdrop link 
        real_link = await get_real_link(episode_link,client)
        #let's get delivery link, streaming link
        streaming_link = await get_true_link(real_link,client)
        print(streaming_link)
        response = await client.head(streaming_link,allow_redirects=True)
        print(response)
        return streaming_link
    elif ismovie == 1:
        film_link = get_film(url)
        #Let's get mixdrop link
        real_link = await get_real_link(film_link,client)
        #let's get delivery link, streaming link
        streaming_link = await get_true_link(real_link,client)
        print(streaming_link)
        response = await client.head(streaming_link,allow_redirects=True)
        print(response)
        return streaming_link
    

'''
async def test_animeworld():
    from curl_cffi.requests import AsyncSession
    async with AsyncSession() as client:
        # Replace with actual id, for example 'anime_id:episode' format
        test_id = "tt4655480:1:1"  # This is an example ID format
        results = await filmpertutti(test_id, client)

if __name__ == "__main__":
    import asyncio
    asyncio.run(test_animeworld())
'''








'''
    series_response = await client.get(link, headers=headers, follow_redirects=True)
        series_soup = BeautifulSoup(series_response.text, 'lxml')
        release_span = series_soup.find('span', class_='released')
        if release_span:
            if release_span.text != "Data di uscita: N/A":
                date_string = release_span.text.split(': ')[-1]  # Get the date part
            for eng, ita in month_mapping.items():
                date_string = re.sub(rf'\b{eng}\b', ita, date_string)

    # Swap to YY-MM-DD formatting using dateparser
        release_date = dateparser.parse(date_string, languages=['it']).strftime("%Y-%m-%d")
'''