-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
198 lines (174 loc) · 7.79 KB
/
main.py
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
188
189
190
191
192
193
194
195
196
197
198
import requests
BASE_URL = "https://api.watchit.com/api"
HEADERS = {
'accept': 'application/json',
'accept-language': 'en',
'applicationversion': '5.21.0',
'authorization': f'Bearer YOUR_ACCESS_TOKEN', # Replace with your actual access token
'content-type': 'application/json',
'deviceid': 'YOUR_DEVICE_ID', # Replace with your actual device ID
'deviceos': 'Web',
'dgst': 'YOUR_DIGEST', # Replace with your actual digest
'lang': 'en',
'origin': 'https://www.watchit.com',
'priority': 'u=1, i',
'referer': 'https://www.watchit.com/',
'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile': '?1',
'sec-ch-ua-platform': '"Android"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'service-code': '1735406595388',
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36',
'x_c_id': '69',
}
def fetch_data(content_type, content_id, season_id=None):
"""
Fetch data for series, shows, movies, or plays.
:param content_type: 'series', 'show', 'movie', or 'plays'
:param content_id: ID of the content
:param season_id: ID of the season (only for episodes)
:return: JSON response data
"""
if season_id:
url = f"{BASE_URL}/{content_type}/seasons/episodes?{content_type}_id={content_id}&season_id={season_id}"
else:
url = f"{BASE_URL}/{content_type}?{content_type}_id={content_id}"
response = requests.get(url, headers=HEADERS)
response.raise_for_status()
return response.json()
def extract_content_info(data, content_type):
"""
Extract information for series, shows, movies, or plays.
:param data: JSON data
:param content_type: Type of content
:return: Extracted content info
"""
content_info = {
'name': data.get('name', 'Unknown'),
'description': data.get('description', 'No description available'),
'start_year': data.get('start_year', 'Unknown'),
'artworks': {
'background_ar_logo': data.get('images', [{}])[0].get('Image', None),
'poster_ar_logo': data.get('images', [{}])[1].get('Image', None),
'background_clean': data.get('content_images', {}).get('BANNER', {}).get('LG', None),
'poster_clean': data.get('content_images', {}).get('BANNER_MOB', {}).get('MD', None)
}
}
if content_type in ['series', 'show']:
content_info['seasons'] = [
{
'season_number': season.get('season_number'),
'id': season.get('id'),
'number_of_episodes': season.get('number_of_episodes')
}
for season in data.get('seasons', [])
]
return content_info
def extract_episode_info(data, detailed=False):
"""
Extract information for episodes in a season.
:param data: JSON data of episodes
:param detailed: Whether to extract detailed information
:return: List of episode details
"""
episodes = data
episode_details = []
for episode in episodes:
try:
duration_seconds = float(episode.get('duration', 0)) / 60000 # Convert milliseconds to minutes
except (ValueError, TypeError):
duration_seconds = 0 # Fallback if conversion fails
episode_detail = {
'episode_id': episode.get('id'),
'episode_number': episode.get('episode_number'),
'thumbnail': episode.get('images', [{}])[0].get('Image', None),
'description': episode.get('description', 'No description available'),
'runtime': round(duration_seconds, 2), # In minutes
}
if detailed:
episode_detail.update({
'name': episode.get('name', 'Unknown'),
'asset_id': episode.get('asset_id', 'Unknown'),
'skip_intro_start': episode.get('skip_time', {}).get('skip_intro_start', None),
'skip_intro_end': episode.get('skip_time', {}).get('skip_intro_end', None),
'end_outro_time': episode.get('skip_time', {}).get('end_outro_time', None),
})
episode_details.append(episode_detail)
return episode_details
def main():
print("Choose the content type:")
print("1. Series")
print("2. Shows")
print("3. Movies")
print("4. Plays")
print("5. Clips")
content_choice = input("Enter your choice (1-5): ").strip()
content_map = {
"1": "series",
"2": "show",
"3": "movie",
"4": "plays",
"5": "clip"
}
content_type = content_map.get(content_choice)
if not content_type:
print("Invalid choice.")
return
content_id = input(f"Enter the {content_type} ID: ").strip()
content_data = fetch_data(content_type, content_id)
content_info = extract_content_info(content_data, content_type)
# Display General Information
print(f"\n{content_type.capitalize()} Name: {content_info['name']}")
print(f"Description: {content_info['description']}")
print(f"Release Year: {content_info['start_year']}")
if content_type in ['series', 'show']:
print("\nSeasons:")
for season in content_info.get('seasons', []):
print(f" - Season {season['season_number']} (ID: {season['id']}), Episodes: {season['number_of_episodes']}")
# User Interaction Menu
while True:
print("\nWhat would you like to do?")
print("1. Get General Artworks (Posters & Backgrounds)")
if content_type in ['series', 'show']:
print("2. Get Episodes Thumbnails for a Season")
print("3. Get Detailed Episodes Information for a Season")
print("4. Exit")
choice = input("Enter your choice (1-4): ").strip()
if choice == "1":
print("\nGeneral Artworks:")
for key, value in content_info['artworks'].items():
print(f" - {key.replace('_', ' ').title()}: {value}")
elif choice == "2" and content_type in ['series', 'show']:
season_id = input("Enter the Season ID: ").strip()
episodes_data = fetch_data(content_type, content_id, season_id)
episodes_info = extract_episode_info(episodes_data)
print("\nEpisodes:")
for episode in episodes_info:
print(f"\nEpisode {episode['episode_number']}:")
print(f" - Thumbnail: {episode['thumbnail']}")
print(f" - Description: {episode['description']}")
print(f" - Runtime: {episode['runtime']} minutes")
elif choice == "3" and content_type in ['series', 'show']:
season_id = input("Enter the Season ID: ").strip()
episodes_data = fetch_data(content_type, content_id, season_id)
episodes_info = extract_episode_info(episodes_data, detailed=True)
print("\nDetailed Episodes Information:")
for episode in episodes_info:
print(f"\nEpisode {episode['episode_number']}:")
print(f" - Name: {episode['name']}")
print(f" - Thumbnail: {episode['thumbnail']}")
print(f" - Description: {episode['description']}")
print(f" - Runtime: {episode['runtime']} minutes")
print(f" - Asset ID: {episode['asset_id']}")
print(f" - Skip Intro Start: {episode['skip_intro_start']} ms")
print(f" - Skip Intro End: {episode['skip_intro_end']} ms")
print(f" - End Outro Time: {episode['end_outro_time']} ms")
elif choice == "4":
print("Exiting...")
break
else:
print("Invalid choice. Please enter a valid option.")
if __name__ == "__main__":
main()