Skip to content

Commit

Permalink
show rcmd videos in rec_a_collection_of_videos
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Nov 30, 2024
1 parent 73d518f commit d86a9c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 19 additions & 1 deletion fuo_bilibili/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
FavoriteSeasonResourceResponse, HistoryLaterVideoResponse, HomeDynamicVideoResponse, UserInfoResponse, \
UserBestVideoResponse, UserVideoResponse, AudioFavoriteSongsResponse, AudioFavoriteListResponse, AudioPlaylist, \
AudioPlaylistSong, VideoHotCommentsResponse, SearchResultUser, LiveFeedListResponse, SearchResultLiveRoom, \
SearchResultMedia, MediaGetListResponse, VideoWeeklyListResponse, VideoMostPopularResponse
SearchResultMedia, MediaGetListResponse, VideoWeeklyListResponse, VideoMostPopularResponse, \
HomeRecommendVideosResponse
from fuo_bilibili.util import format_timedelta_to_hms

PROVIDER_ID = __identifier__
Expand Down Expand Up @@ -489,6 +490,23 @@ def create_live_model(cls, live: LiveFeedListResponse.LiveFeedListResponseData.L
cover=live.cover,
)

@classmethod
def create_recommend_video_model(cls, result: HomeRecommendVideosResponse.HomeRecommendVideosResponseData.Video):
return VideoModel(
source=PROVIDER_ID,
identifier=result.bvid,
title=get_text_from_html(result.title),
artists=[BriefArtistModel(
source=PROVIDER_ID,
identifier=result.owner.mid,
name=result.owner.name
)],
duration=result.duration.total_seconds(),
cover=wrap_pic(result.pic),
play_count=result.stat.view,
)


@classmethod
def create_popular_video_model(cls, result: VideoMostPopularResponse.VideoMostPopularResponseData.PopularVideo):
return VideoModel(
Expand Down
6 changes: 4 additions & 2 deletions fuo_bilibili/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,10 @@ def g():
return SequentialReader(g(), total)

def rec_a_collection_of_videos(self):
resp = self._api.video_most_popular()
return [BVideoModel.create_popular_video_model(v) for v in resp.data.list]
if self.has_current_user():
resp = self._api.home_recommend_videos(HomeRecommendVideosRequest(ps=12))
return [BVideoModel.create_recommend_video_model(v) for v in resp.data.item]
return []

@property
def identifier(self):
Expand Down

0 comments on commit d86a9c7

Please sign in to comment.