Skip to content

Commit

Permalink
Fix extraction of video stats
Browse files Browse the repository at this point in the history
  • Loading branch information
bebatut committed Jun 25, 2024
1 parent 00094d1 commit 44210b4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions bin/extract_gtn_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,20 @@ def get_youtube_stats(tuto: dict) -> None:
tuto["video_versions"] = 0
tuto["video_view"] = 0
ydl_opts = {"ignoreerrors": True, "quiet": True}
if "video_library" in tuto and tuto["video_library"]["tutorial"]:
tuto["video_versions"] = len(tuto["video_library"]["tutorial"]["versions"])
for v in tuto["video_library"]["tutorial"]["versions"]:
url = f"https://www.youtube.com/watch?v={v['link']}"
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
info = ydl.sanitize_info(info)
if info:
tuto["video_view"] += info["view_count"]
recordings = []
print(tuto.keys())
if "recordings" in tuto and tuto["recordings"]:
recordings = tuto["recordings"]
elif "slides_recordings" in tuto and tuto["slides_recordings"]:
recordings = tuto["slides_recordings"]
tuto["video_versions"] = len(recordings)
for v in recordings:
url = f"https://www.youtube.com/watch?v={v['youtube_id']}"
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
info = ydl.sanitize_info(info)
if info:
tuto["video_view"] += info["view_count"]


def format_tutorial(tuto: dict, edam_ontology: dict, tools: dict, feedback: dict, plausible_api: str) -> Dict:
Expand Down

0 comments on commit 44210b4

Please sign in to comment.