Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import m3u8
|
| 3 |
+
import requests
|
| 4 |
+
from urllib.parse import urlparse, parse_qs
|
| 5 |
+
|
| 6 |
+
def generate_gallery(user_text):
|
| 7 |
+
data = requests.get('https://net52.cc/pv/search.php', {'s': user_text}).json()['searchResult']
|
| 8 |
+
return [f'https://imgcdn.kim/pv/341/{item["id"]}.jpg' for item in data], data
|
| 9 |
+
|
| 10 |
+
def on_image_click(evt: gr.SelectData, data):
|
| 11 |
+
item = data[evt.index]
|
| 12 |
+
return item['t'], item['y'], item['r'] if item['r'] != "Series" else "", item['id'], item['r'] == "Series"
|
| 13 |
+
|
| 14 |
+
def get_data(id):
|
| 15 |
+
return requests.get('https://net52.cc/pv/post.php', {'id': id}).json() if id else {}
|
| 16 |
+
|
| 17 |
+
def get_video_data(id):
|
| 18 |
+
if not id:
|
| 19 |
+
return gr.Dropdown(choices=[]), {}
|
| 20 |
+
|
| 21 |
+
res = requests.get('https://net52.cc/pv/playlist.php', {'id': id}).json()[0]
|
| 22 |
+
data = {
|
| 23 |
+
"subtitle": [i['label'] for i in res.get('tracks', [])], # Bug fix: .get() use kiya
|
| 24 |
+
"quality": {i.stream_info.resolution[1]: i.uri for i in m3u8.load(f'https://net52.cc/pv/hls/{id}.m3u8?in={parse_qs(urlparse(res['sources'][0]['file']).query)['in'][0]}').playlists}
|
| 25 |
+
}
|
| 26 |
+
q = list(data['quality'].keys())
|
| 27 |
+
print(q)
|
| 28 |
+
return gr.Dropdown(choices=q, value=q[0] if q else None), data
|
| 29 |
+
|
| 30 |
+
def on_quality_change(quality, video_state):
|
| 31 |
+
if not video_state or not quality: # Bug fix: None check
|
| 32 |
+
return ""
|
| 33 |
+
return video_state['quality'].get(quality, "") # Bug fix: .get() use kiya
|
| 34 |
+
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
input_text = gr.Textbox(
|
| 37 |
+
label="Search",
|
| 38 |
+
placeholder="Movie / Series naam likho"
|
| 39 |
+
)
|
| 40 |
+
btn = gr.Button("Search")
|
| 41 |
+
gallery = gr.Gallery(
|
| 42 |
+
label="Results",
|
| 43 |
+
columns=4,
|
| 44 |
+
height=300
|
| 45 |
+
)
|
| 46 |
+
title_box = gr.Textbox(label="Title")
|
| 47 |
+
year_box = gr.Textbox(label="Year")
|
| 48 |
+
duration_box = gr.Textbox(label="Duration")
|
| 49 |
+
is_series_box = gr.Checkbox(label="This is Series")
|
| 50 |
+
get_data_btn = gr.Button("Get Data")
|
| 51 |
+
json_box = gr.JSON(label="JSON")
|
| 52 |
+
html_box = gr.HTML(html_template='<video src="${value}" controls></video>')
|
| 53 |
+
dropdown = gr.Dropdown()
|
| 54 |
+
get_movie = gr.Button("Get Movie")
|
| 55 |
+
data_state = gr.State()
|
| 56 |
+
id_state = gr.State()
|
| 57 |
+
video_state = gr.State()
|
| 58 |
+
|
| 59 |
+
btn.click(generate_gallery, input_text, [gallery, data_state])
|
| 60 |
+
get_data_btn.click(get_data, id_state, json_box)
|
| 61 |
+
get_movie.click(get_video_data, id_state, [dropdown, video_state])
|
| 62 |
+
dropdown.change(on_quality_change, [dropdown, video_state], html_box)
|
| 63 |
+
gallery.select(on_image_click, data_state, [title_box, year_box, duration_box, id_state, is_series_box])
|
| 64 |
+
gallery.preview_close(lambda: ('', '', '', '', False, {}), outputs=[title_box, year_box, duration_box, id_state, is_series_box, json_box])
|
| 65 |
+
|
| 66 |
+
demo.launch()
|