Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import json | |
| import re | |
| def process_url(myUrl): | |
| if not myUrl: | |
| return {"error": "URL is required"} | |
| # Extract the ID from the URL using regular expression | |
| shorturl_id = re.search(r"/s/([a-zA-Z0-9\-_]+)", myUrl).group(1) | |
| # First API URL and parameters | |
| terabox_url = "https://www.terabox.com/api/shorturlinfo" | |
| params = { | |
| "app_id": "250528", | |
| "shorturl": shorturl_id, # Use the extracted shorturl_id here | |
| "root": "1" | |
| } | |
| headers = { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.140 Safari/537.36', | |
| 'Accept': 'application/json, text/plain, */*', | |
| 'Accept-Encoding': 'gzip, deflate, br', | |
| 'Connection': 'keep-alive', | |
| 'Host': 'www.terabox.com', | |
| } | |
| # Send GET request to Terabox | |
| response = requests.get(terabox_url, params=params, headers=headers) | |
| # Check if the Terabox request was successful | |
| if response.status_code == 200: | |
| # Parse the JSON content of the Terabox response | |
| data = response.json() | |
| # Transform the response | |
| transformed_response = { | |
| "data": [{ | |
| "metadata": { | |
| "category": data['list'][0]['category'], | |
| "fs_id": data['list'][0]['fs_id'], | |
| "isdir": data['list'][0]['isdir'], | |
| "local_ctime": data['list'][0]['local_ctime'], | |
| "local_mtime": data['list'][0]['local_mtime'], | |
| "md5": data['list'][0]['md5'], | |
| "path": data['list'][0]['path'], | |
| "dlink": "", | |
| "fastdlink": "", | |
| "fdlink": "", | |
| "play_forbid": "0", # Assuming default as 0 since no info is provided | |
| "server_ctime": data['list'][0]['server_ctime'], | |
| "server_filename": data['list'][0]['server_filename'], | |
| "server_mtime": data['list'][0]['server_mtime'], | |
| "size": data['list'][0]['size'], | |
| "thumbs": data['list'][0]['thumbs'], | |
| "emd5": "cd22b0853r56993a0c6d09ffa7a7d509", # Assuming default emd5 as given in the sample | |
| "share_id": data['shareid'], | |
| "uk": data['uk'], | |
| "timestamp": data['timestamp'], | |
| "jsToken": "" | |
| } | |
| }] | |
| } | |
| # Now, call the second URL using the extracted shorturl_id and remove the starting '1' | |
| mdisk_url = f"https://core.mdiskplay.com/box/terabox/{shorturl_id[1:]}?aka=baka" # Slice to remove starting '1' | |
| # Send GET request to mdiskplay.com | |
| mdisk_response = requests.get(mdisk_url) | |
| # Check if the mdiskplay request was successful | |
| if mdisk_response.status_code == 200: | |
| # Parse the mdisk response | |
| mdisk_data = mdisk_response.json() | |
| # Add streamingUrl to the transformed_response | |
| transformed_response["data"][0]["streamingUrl"] = { | |
| "streaming_url": mdisk_data.get("source") | |
| } | |
| # Return the transformed response | |
| return transformed_response | |
| else: | |
| return {"error": f"Failed to retrieve MDisk content. Status code: {mdisk_response.status_code}"} | |
| else: | |
| return {"error": f"Failed to retrieve Terabox content. Status code: {response.status_code}"} | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=process_url, | |
| inputs=gr.Textbox(label="Enter URL"), | |
| outputs=gr.JSON(label="Response"), | |
| title="URL Processor", | |
| description="This tool processes the URL to retrieve information from Terabox and MDisk services." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch(debug=True) | |