Skip to content

Commit

Permalink
feat: get FlatSong's LikeStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Apr 1, 2024
1 parent 2a3e3fb commit 2165ce2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions parsers/browsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from "../nav.ts";
import { get_option } from "../setup.ts";
import { j, jo } from "../util.ts";
import { get_buttons_like_status } from "./songs.ts";
import {
ArtistRun,
get_library_like_status,
Expand Down Expand Up @@ -520,6 +521,7 @@ export interface FlatSong {
id: string;
} | null;
views: string | null;
likeStatus: LikeStatus | null;
}

export function parse_song_flat(data: any) {
Expand All @@ -537,6 +539,7 @@ export function parse_song_flat(data: any) {
isExplicit: jo(data, BADGE_LABEL) != null,
album: null,
views: null,
likeStatus: get_buttons_like_status(data),
};

if (
Expand Down
12 changes: 5 additions & 7 deletions parsers/playlists.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
BADGE_LABEL,
MENU_ITEMS,
MENU_LIKE_STATUS,
MENU_SERVICE,
MRLIR,
NAVIGATION_VIDEO_TYPE,
Expand All @@ -14,6 +13,7 @@ import { j, jo } from "../util.ts";
import { TrendChange } from "./browsing.ts";
import {
Album,
get_buttons_like_status,
LikeStatus,
MenuTokens,
parse_song_album,
Expand Down Expand Up @@ -66,7 +66,7 @@ export const parse_playlist_items = (

const data = result[MRLIR];

let videoId = null, setVideoId = null, like = null, feedback_tokens = null;
let videoId = null, setVideoId = null, feedback_tokens = null;

// if the item has a menu, find its setVideoId
if ("menu" in data) {
Expand Down Expand Up @@ -95,13 +95,11 @@ export const parse_playlist_items = (
if (play != null) {
if ("playNavigationEndpoint" in play) {
videoId = j(play, "playNavigationEndpoint.watchEndpoint.videoId");

if ("menu" in data) {
like = jo(data, MENU_LIKE_STATUS);
}
}
}

const likeStatus = get_buttons_like_status(data)!;

const title = get_item_text(data, 0);

if (title == "Song deleted") {
Expand Down Expand Up @@ -148,7 +146,7 @@ export const parse_playlist_items = (
title,
artists,
album,
likeStatus: like,
likeStatus,
thumbnails,
isAvailable,
isExplicit,
Expand Down
5 changes: 5 additions & 0 deletions parsers/songs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NAVIGATION_WATCH_PLAYLIST_ID,
TOGGLE_MENU,
} from "../nav.ts";
import { MENU_LIKE_STATUS } from "../nav.ts";
import { j, jo } from "../util.ts";
import { _ } from "./browsing.ts";
import {
Expand Down Expand Up @@ -296,6 +297,10 @@ export function get_menu_like_status(item: any): LikeStatus | null {
return null;
}

export function get_buttons_like_status(item: any): LikeStatus | null {
return jo(item, MENU_LIKE_STATUS);
}

export interface ShuffleAndRadioIds {
shuffleId: string | null;
radioId: string | null;
Expand Down

0 comments on commit 2165ce2

Please sign in to comment.