Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
def process_url(myUrl):
|
| 7 |
+
if not myUrl:
|
| 8 |
+
return {"error": "URL is required"}
|
| 9 |
+
|
| 10 |
+
# Extract the ID from the URL using regular expression
|
| 11 |
+
shorturl_id = re.search(r"/s/([a-zA-Z0-9\-_]+)", myUrl).group(1)
|
| 12 |
+
|
| 13 |
+
# First API URL and parameters
|
| 14 |
+
terabox_url = "https://www.terabox.com/api/shorturlinfo"
|
| 15 |
+
params = {
|
| 16 |
+
"app_id": "250528",
|
| 17 |
+
"shorturl": shorturl_id, # Use the extracted shorturl_id here
|
| 18 |
+
"root": "1"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
headers = {
|
| 22 |
+
'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',
|
| 23 |
+
'Accept': 'application/json, text/plain, */*',
|
| 24 |
+
'Accept-Encoding': 'gzip, deflate, br',
|
| 25 |
+
'Connection': 'keep-alive',
|
| 26 |
+
'Host': 'www.terabox.com',
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Send GET request to Terabox
|
| 30 |
+
response = requests.get(terabox_url, params=params, headers=headers)
|
| 31 |
+
|
| 32 |
+
# Check if the Terabox request was successful
|
| 33 |
+
if response.status_code == 200:
|
| 34 |
+
# Parse the JSON content of the Terabox response
|
| 35 |
+
data = response.json()
|
| 36 |
+
|
| 37 |
+
# Transform the response
|
| 38 |
+
transformed_response = {
|
| 39 |
+
"data": [{
|
| 40 |
+
"metadata": {
|
| 41 |
+
"category": data['list'][0]['category'],
|
| 42 |
+
"fs_id": data['list'][0]['fs_id'],
|
| 43 |
+
"isdir": data['list'][0]['isdir'],
|
| 44 |
+
"local_ctime": data['list'][0]['local_ctime'],
|
| 45 |
+
"local_mtime": data['list'][0]['local_mtime'],
|
| 46 |
+
"md5": data['list'][0]['md5'],
|
| 47 |
+
"path": data['list'][0]['path'],
|
| 48 |
+
"dlink": "",
|
| 49 |
+
"fastdlink": "",
|
| 50 |
+
"fdlink": "",
|
| 51 |
+
"play_forbid": "0", # Assuming default as 0 since no info is provided
|
| 52 |
+
"server_ctime": data['list'][0]['server_ctime'],
|
| 53 |
+
"server_filename": data['list'][0]['server_filename'],
|
| 54 |
+
"server_mtime": data['list'][0]['server_mtime'],
|
| 55 |
+
"size": data['list'][0]['size'],
|
| 56 |
+
"thumbs": data['list'][0]['thumbs'],
|
| 57 |
+
"emd5": "cd22b0853r56993a0c6d09ffa7a7d509", # Assuming default emd5 as given in the sample
|
| 58 |
+
"share_id": data['shareid'],
|
| 59 |
+
"uk": data['uk'],
|
| 60 |
+
"timestamp": data['timestamp'],
|
| 61 |
+
"jsToken": ""
|
| 62 |
+
}
|
| 63 |
+
}]
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# Now, call the second URL using the extracted shorturl_id and remove the starting '1'
|
| 67 |
+
mdisk_url = f"https://core.mdiskplay.com/box/terabox/{shorturl_id[1:]}?aka=baka" # Slice to remove starting '1'
|
| 68 |
+
|
| 69 |
+
# Send GET request to mdiskplay.com
|
| 70 |
+
mdisk_response = requests.get(mdisk_url)
|
| 71 |
+
|
| 72 |
+
# Check if the mdiskplay request was successful
|
| 73 |
+
if mdisk_response.status_code == 200:
|
| 74 |
+
# Parse the mdisk response
|
| 75 |
+
mdisk_data = mdisk_response.json()
|
| 76 |
+
|
| 77 |
+
# Add streamingUrl to the transformed_response
|
| 78 |
+
transformed_response["data"][0]["streamingUrl"] = {
|
| 79 |
+
"streaming_url": mdisk_data.get("source")
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# Return the transformed response
|
| 83 |
+
return transformed_response
|
| 84 |
+
else:
|
| 85 |
+
return {"error": f"Failed to retrieve MDisk content. Status code: {mdisk_response.status_code}"}
|
| 86 |
+
else:
|
| 87 |
+
return {"error": f"Failed to retrieve Terabox content. Status code: {response.status_code}"}
|
| 88 |
+
|
| 89 |
+
# Create a Gradio interface
|
| 90 |
+
iface = gr.Interface(
|
| 91 |
+
fn=process_url,
|
| 92 |
+
inputs=gr.Textbox(label="Enter URL"),
|
| 93 |
+
outputs=gr.JSON(label="Response"),
|
| 94 |
+
title="URL Processor",
|
| 95 |
+
description="This tool processes the URL to retrieve information from Terabox and MDisk services."
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
iface.launch(debug=True)
|