Skip to content

Commit

Permalink
Update JSON serialization for playlists.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-niles committed Jun 4, 2024
1 parent e62b0bb commit 25b7546
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions scraper/src/youtube2zim/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class PlaylistPreview(CamelModel):
count: int


class Playlists(CamelModel):
"""Class to serialize data about a list of YouTube playlists."""

playlists: list[PlaylistPreview]


class Channel(CamelModel):
"""Class to serialize data about a YouTube channel."""

Expand Down
6 changes: 4 additions & 2 deletions scraper/src/youtube2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from dateutil import parser as dt_parser
from kiwixstorage import KiwixStorage
from pif import get_public_ip
from pydantic.json import pydantic_encoder
from zimscraperlib.download import stream_file
from zimscraperlib.fix_ogvjs_dist import fix_source_dir
from zimscraperlib.i18n import NotFound, get_language_details, setlocale
Expand Down Expand Up @@ -61,6 +60,7 @@
Channel,
Playlist,
PlaylistPreview,
Playlists,
Subtitle,
Video,
VideoPreview,
Expand Down Expand Up @@ -1305,7 +1305,9 @@ def get_playlist_slug(playlist) -> str:
self.zim_file.add_item_for(
path="playlists.json",
title="Playlists",
content=json.dumps(playlist_list, default=pydantic_encoder, indent=2),
content=Playlists(playlists=playlist_list).model_dump_json(
by_alias=True, indent=2
),
mimetype="application/json",
is_front=False,
)
Expand Down

0 comments on commit 25b7546

Please sign in to comment.