navpan2 commited on
Commit
f53459d
·
1 Parent(s): 41c2e01

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -3
main.py CHANGED
@@ -2,13 +2,26 @@ from fastapi import FastAPI
2
 
3
  import yt_dlp
4
  app = FastAPI()
5
-
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  @app.get("/")
8
  async def root():
9
  return {"message": "Hello World"}
10
  @app.get("/dailymo/")
11
- async def read_item(reqUrl: str = 'https://www.dailymotion.com/video/x8pud1k', vidFormat: str='http-720-0'):
12
 
13
  video_url = reqUrl
14
  desired_format = vidFormat
@@ -22,4 +35,9 @@ async def read_item(reqUrl: str = 'https://www.dailymotion.com/video/x8pud1k', v
22
  if format_url:
23
  return {"url":format_url,"reqUrl":reqUrl,"vidFormat":vidFormat}
24
  else:
25
- return {"url":"Not found","reqUrl":reqUrl,"vidFormat":vidFormat}
 
 
 
 
 
 
2
 
3
  import yt_dlp
4
  app = FastAPI()
5
+ def get_video_formats(video_url):
6
+ formats_list = []
7
+
8
+ with yt_dlp.YoutubeDL() as ydl:
9
+ info_dict = ydl.extract_info(video_url, download=False)
10
+ for format in info_dict.get('formats', []):
11
+ format_info = {
12
+ 'format_id': format['format_id'],
13
+ 'ext': format['ext'],
14
+ 'resolution': format.get('resolution', ''),
15
+ }
16
+ formats_list.append(format_info)
17
+
18
+ return formats_list
19
 
20
  @app.get("/")
21
  async def root():
22
  return {"message": "Hello World"}
23
  @app.get("/dailymo/")
24
+ async def read_item(reqUrl: str = 'https://www.dailymotion.com/video/x8pywti', vidFormat: str='http-720-0'):
25
 
26
  video_url = reqUrl
27
  desired_format = vidFormat
 
35
  if format_url:
36
  return {"url":format_url,"reqUrl":reqUrl,"vidFormat":vidFormat}
37
  else:
38
+ return {"url":"Not found","reqUrl":reqUrl,"vidFormat":vidFormat}
39
+ @app.get("/getf/")
40
+ async def read_item(videourl: str = 'https://www.dailymotion.com/video/x8pywti'):
41
+
42
+ available_formats = get_video_formats(videourl)
43
+ return {"video_url": videourl, "formats": available_formats}