Skip to content

Commit

Permalink
Add type hints for return values of functions in make_json_files method
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-niles committed Jun 4, 2024
1 parent 8ff4342 commit e62b0bb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions scraper/src/youtube2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def video_has_channel(videos_channels, video):
def get_thumbnail_path(video_id):
return f"videos/{video_id}/video.webp"

def get_subtitles(video_id):
def get_subtitles(video_id) -> list[Subtitle]:
video_dir = self.videos_dir.joinpath(video_id)
languages = [
x.stem.split(".")[1]
Expand Down Expand Up @@ -1181,7 +1181,7 @@ def get_videos_list(playlist):
videos = sorted(videos, key=lambda v: v["snippet"]["position"])
return videos

def generate_video_object(video):
def generate_video_object(video) -> Video:
video_id = video["contentDetails"]["videoId"]
author = videos_channels[video_id]
return Video(
Expand All @@ -1202,7 +1202,7 @@ def generate_video_object(video):
duration=0,
)

def generate_video_preview_object(video):
def generate_video_preview_object(video) -> VideoPreview:
video_id = video["contentDetails"]["videoId"]
return VideoPreview(
slug=get_video_slug(video),
Expand All @@ -1212,12 +1212,12 @@ def generate_video_preview_object(video):
duration=0,
)

def get_video_slug(video):
def get_video_slug(video) -> str:
title = video["snippet"]["title"]
video_id = video["contentDetails"]["videoId"]
return f"{get_slug(title)}-{video_id[:4]}"

def generate_playlist_object(playlist):
def generate_playlist_object(playlist) -> Playlist:
videos = get_videos_list(playlist)
return Playlist(
id=playlist.playlist_id,
Expand All @@ -1237,7 +1237,7 @@ def generate_playlist_object(playlist):
),
)

def generate_playlist_preview_object(playlist):
def generate_playlist_preview_object(playlist) -> PlaylistPreview:
videos = get_videos_list(playlist)
return PlaylistPreview(
slug=get_playlist_slug(playlist),
Expand All @@ -1249,7 +1249,7 @@ def generate_playlist_preview_object(playlist):
count=len(videos),
)

def get_playlist_slug(playlist):
def get_playlist_slug(playlist) -> str:
return f"{get_slug(playlist.title)}-{playlist.playlist_id[-4:]}"

videos = load_mandatory_json(self.cache_dir, "videos").values()
Expand Down

0 comments on commit e62b0bb

Please sign in to comment.