Skip to content

Commit a3095f9

Browse files
authored
Update playlists.py
1 parent 707c22f commit a3095f9

1 file changed

Lines changed: 25 additions & 34 deletions

File tree

tests/async/playlists.py

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,39 @@
33
import time
44
from youtubesearchpython.__future__ import *
55

6-
def pretty_print(data, fn_name, elapsed):
6+
def print_json(data):
77
print(json.dumps(data, indent=2, ensure_ascii=False))
8-
print(f"\n{fn_name} took {elapsed:.3f} seconds\n{'-'*60}\n")
98

10-
async def timed_call(fn_name, coro):
9+
async def run_get(url):
1110
start = time.perf_counter()
12-
result = await coro
11+
result = await Playlist.get(url)
1312
elapsed = time.perf_counter() - start
14-
return result, fn_name, elapsed
13+
print_json(result)
14+
print(f"\n⏱ Playlist.get took {elapsed:.3f} seconds\n{'-'*60}\n")
15+
16+
async def run_get_info(url):
17+
start = time.perf_counter()
18+
result = await Playlist.getInfo(url)
19+
elapsed = time.perf_counter() - start
20+
print_json(result)
21+
print(f"\n⏱ Playlist.getInfo took {elapsed:.3f} seconds\n{'-'*60}\n")
22+
23+
async def run_get_videos(url):
24+
start = time.perf_counter()
25+
result = await Playlist.getVideos(url)
26+
elapsed = time.perf_counter() - start
27+
print_json(result)
28+
print(f"\n⏱ Playlist.getVideos took {elapsed:.3f} seconds\n{'-'*60}\n")
1529

1630
async def main():
1731
url1 = "https://www.youtube.com/playlist?list=PLRBp0Fe2GpgmsW46rJyudVFlY6IYjFBIK"
1832
url2 = "https://www.youtube.com/watch?v=bplUXwTTgbI&list=PL6edxAMqu2xfxgbf7Q09hSg1qCMfDI7IZ"
1933

20-
playlist, fn, t = await timed_call(
21-
"Playlist.get",
22-
Playlist.get(url1),
23-
)
24-
pretty_print(playlist, fn, t)
25-
26-
playlistInfo, fn, t = await timed_call(
27-
"Playlist.getInfo",
28-
Playlist.getInfo(url1),
29-
)
30-
pretty_print(playlistInfo, fn, t)
31-
32-
playlistVideos, fn, t = await timed_call(
33-
"Playlist.getVideos",
34-
Playlist.getVideos(url1),
35-
)
36-
pretty_print(playlistVideos, fn, t)
37-
38-
playlist, fn, t = await timed_call(
39-
"Playlist.get",
40-
Playlist.get(url1),
41-
)
42-
pretty_print(playlist, fn, t)
43-
44-
playlist, fn, t = await timed_call(
45-
"Playlist.get (video+playlist URL)",
46-
Playlist.get(url2),
47-
)
48-
pretty_print(playlist, fn, t)
34+
await run_get(url1)
35+
await run_get_info(url1)
36+
await run_get_videos(url1)
37+
38+
await run_get(url1)
39+
await run_get(url2)
4940

5041
asyncio.run(main())

0 commit comments

Comments
 (0)