Spaces:
Sleeping
Sleeping
import requests | |
import json | |
class AutoEmbed: | |
def __init__(self): | |
self.base_url = "https://tom.autoembed.cc/api/getVideoSource" | |
self.headers = { | |
'Referer': 'https://tom.autoembed.cc', | |
'Origin': 'https://tom.autoembed.cc', | |
} | |
self.videoDataList = [] | |
def build_url(self, imdb_id, media_type, season = None, episode = None): | |
final_url = f"{self.base_url}?type={media_type}&id={imdb_id}" | |
if season and episode and media_type == 'tv': | |
final_url += f"/{season}/{episode}" | |
return final_url | |
def get_stream(self, tmdb_id, imdb_id, media_type, title, year, season = None, episode = None): | |
final_url = self.build_url(media_type=media_type, imdb_id=imdb_id, season=season, episode=episode) | |
response = requests.get(final_url, headers=self.headers) | |
if response.status_code == 200: | |
data = response.json() | |
if 'videoSource' in data: | |
self.videoDataList.append( | |
{ | |
"videoSource" : f"AUTOEMBED1_{len(self.videoDataList)+1}", | |
"videoUrl" : data['videoSource'], | |
"videoHeaders": {} | |
} | |
) | |
else: | |
raise Exception("Failed to get encoded data") | |
return self.videoDataList | |
if __name__ == "__main__": | |
auto_embed = AutoEmbed() | |
media_type = "movie" | |
tmdb_id = "822119" | |
imdb_id = "tt14513804" | |
title = "Captain America: Brave New World" | |
year = "2025" | |
season = None | |
episode = None | |
try: | |
encoded_data = auto_embed.get_stream(tmdb_id=tmdb_id, imdb_id=imdb_id, media_type=media_type, title=title, year=year, season=season, episode=episode) | |
print(json.dumps(encoded_data, indent=4)) | |
except Exception as e: | |
print(f"Error: {e}") |