Skip to content

Commit 46ac95e

Browse files
authored
Update playlists.py
1 parent d4f0289 commit 46ac95e

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

tests/async/playlists.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@
55

66
def print_json(data):
77
print(json.dumps(data, indent=2, ensure_ascii=False))
8+
print("-" * 60)
89

910
def print_timing(fn_name, elapsed):
1011
print(f"⏱ {fn_name}: {elapsed:.3f}s")
11-
print("-" * 60)
12+
print("=" * 60)
1213

1314
async def timed(fn_name, coro):
1415
start = time.perf_counter()
1516
result = await coro
1617
elapsed = time.perf_counter() - start
17-
print_timing(fn_name, elapsed)
18-
return result
18+
return fn_name, elapsed, result
1919

2020
async def main():
2121
url1 = "https://www.youtube.com/playlist?list=PLRBp0Fe2GpgmsW46rJyudVFlY6IYjFBIK"
2222
url2 = "https://www.youtube.com/watch?v=bplUXwTTgbI&list=PL6edxAMqu2xfxgbf7Q09hSg1qCMfDI7IZ"
2323

24-
print_json(await timed("Playlist.get", Playlist.get(url1)))
25-
print_json(await timed("Playlist.getInfo", Playlist.getInfo(url1)))
26-
print_json(await timed("Playlist.getVideos", Playlist.getVideos(url1)))
27-
print_json(await timed("Playlist.get (cached)", Playlist.get(url1)))
28-
print_json(await timed("Playlist.get (video+playlist URL)", Playlist.get(url2)))
24+
for fn, coro in [
25+
("Playlist.get", Playlist.get(url1)),
26+
("Playlist.getInfo", Playlist.getInfo(url1)),
27+
("Playlist.getVideos", Playlist.getVideos(url1)),
28+
("Playlist.get (cached)", Playlist.get(url1)),
29+
("Playlist.get (video+playlist URL)", Playlist.get(url2)),
30+
]:
31+
name, elapsed, result = await timed(fn, coro)
32+
print_timing(name, elapsed)
33+
print_json(result)
2934

3035
asyncio.run(main())

0 commit comments

Comments
 (0)