Files
plezy/lib/utils/content_utils.dart
T
edde746 4eaf4423a1 refactor: share focus chrome and simplify the TV picker and browse paths
Focus chrome was implemented twice, once in the focusable wrapper and once
in the focus builders; both now go through FocusChrome. TvColorPicker's
channel row was a copy of TvNumberSpinner and is now that widget in compact
density.

Also trims unused helpers and fields and simplifies the Jellyfin browse
paths.
2026-07-26 06:09:49 +02:00

64 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:material_symbols_icons/symbols.dart';
class ContentTypes {
ContentTypes._();
static const String movie = 'movie';
static const String show = 'show';
static const String season = 'season';
static const String episode = 'episode';
static const String artist = 'artist';
static const String album = 'album';
static const String track = 'track';
static const String collection = 'collection';
static const String playlist = 'playlist';
static const String clip = 'clip';
static const Set<String> musicTypes = {artist, album, track};
static const Set<String> videoTypes = {movie, show, season, episode};
}
class ContentTypeHelper {
ContentTypeHelper._();
static bool isMusicContent(String type) => ContentTypes.musicTypes.contains(type.toLowerCase());
static bool isVideoContent(String type) => ContentTypes.videoTypes.contains(type.toLowerCase());
static IconData getLibraryIcon(String type) {
switch (type.toLowerCase()) {
case ContentTypes.movie:
return Symbols.movie_rounded;
case ContentTypes.show:
return Symbols.tv_rounded;
case ContentTypes.artist:
return Symbols.music_note_rounded;
case 'photo':
return Symbols.photo_rounded;
case 'mixed':
return Symbols.share_rounded;
default:
return Symbols.folder_rounded;
}
}
}
/// Utility function to format content ratings by removing country prefixes
String formatContentRating(String? contentRating) {
if (contentRating == null || contentRating.isEmpty) {
return '';
}
// Remove common country prefixes like "gb/", "us/", "de/", etc.
// The pattern matches: lowercase letters followed by a forward slash
final regex = RegExp(r'^[a-z]{2,3}/(.+)$', caseSensitive: false);
final match = regex.firstMatch(contentRating);
if (match != null && match.groupCount >= 1) {
return match.group(1) ?? contentRating;
}
return contentRating;
}