Skip to content

Commit

Permalink
feature: include media_content_id when using favoritesToIgnore
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Dec 22, 2024
1 parent cefe948 commit 8eee0c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ customFavoriteThumbnailsIfMissing:
Ed Sheeran Radio: https://i.scdn.co/image/ab6761610000e5eb4d2f80ceffc6c70a432ccd7c
Legendary: https://i.scdn.co/image/ab67706f000000027b2e7ee752dc222ff2fd466f
fallback: https://cdn-icons-png.flaticon.com/512/651/651717.png # will use this if thumbnail is missing and none of the above matches. Defaults to image of music notes.
favoritesToIgnore:
- My Favorite Album
- My Bad Playlist
favoritesToIgnore: # will compare both against title and media_content_id
- My Favorite Album # Hide specific title
- Christmas # Hide any titles matching 'Christmas'
- radio_browser # Hide any radio stations from radio_browser (since their media_content_id contains this string)
topFavorites: # Show these favorites at the top of the list
- Legendary
- Country Rocks
Expand Down
11 changes: 7 additions & 4 deletions src/services/media-browse-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CardConfig, MediaPlayerItem } from '../types';
import HassService from './hass-service';
import { MediaPlayer } from '../model/media-player';
import { indexOfWithoutSpecialChars } from '../utils/media-browser-utils';
import { stringContainsAnyItemInArray } from '../utils/media-browser-utils';

export default class MediaBrowseService {
private hassService: HassService;
Expand All @@ -20,9 +20,12 @@ export default class MediaBrowseService {
favorites = favorites.flatMap((f) => f);
favorites = this.removeDuplicates(favorites);
favorites = favorites.length ? favorites : this.getFavoritesFromStates(player);
return favorites.filter(
(item) => indexOfWithoutSpecialChars(this.config.favoritesToIgnore ?? [], item.title) === -1,
);
const favoritesToIgnore = this.config.favoritesToIgnore ?? [];
return favorites.filter((item) => {
const titleNotIgnored = !stringContainsAnyItemInArray(favoritesToIgnore, item.title);
const contentIdNotIgnored = !stringContainsAnyItemInArray(favoritesToIgnore, item.media_content_id ?? '');
return titleNotIgnored && contentIdNotIgnored;
});
}

private removeDuplicates(items: MediaPlayerItem[]) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/media-browser-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function indexOfWithoutSpecialChars(array: string[], str: string) {
return result;
}

export function stringContainsAnyItemInArray(array: string[], str: string) {
return !!array.find((value) => str.includes(value));
}

export function itemsWithFallbacks(mediaPlayerItems: MediaPlayerItem[], config: CardConfig) {
const itemsWithImage = hasItemsWithImage(mediaPlayerItems);
return mediaPlayerItems.map((item) => {
Expand Down

0 comments on commit 8eee0c1

Please sign in to comment.