1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #6447 from thornbill/refactor-playing-text

Refactor item text lines
This commit is contained in:
Bill Thornton 2025-02-13 16:23:07 -05:00 committed by GitHub
commit 18de10f2ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 167 additions and 103 deletions

View file

@ -1,11 +1,13 @@
import { getImageUrl } from 'apps/stable/features/playback/utils/image';
import { getItemTextLines } from 'apps/stable/features/playback/utils/itemText';
import { appRouter, isLyricsPage } from 'components/router/appRouter';
import datetime from '../../scripts/datetime';
import Events from '../../utils/events.ts';
import browser from '../../scripts/browser';
import imageLoader from '../images/imageLoader';
import layoutManager from '../layoutManager';
import { playbackManager } from '../playback/playbackmanager';
import nowPlayingHelper from '../playback/nowplayinghelper';
import { appHost } from '../apphost';
import dom from '../../scripts/dom';
import globalize from 'lib/globalize';
@ -17,7 +19,6 @@ import appFooter from '../appFooter/appFooter';
import itemShortcuts from '../shortcuts';
import './nowPlayingBar.scss';
import '../../elements/emby-slider/emby-slider';
import { getImageUrl } from 'apps/stable/features/playback/utils/image';
let currentPlayer;
let currentPlayerSupportedCommands = [];
@ -474,24 +475,21 @@ function setLyricButtonActiveStatus() {
function updateNowPlayingInfo(state) {
const nowPlayingItem = state.NowPlayingItem;
const textLines = nowPlayingItem ? nowPlayingHelper.getNowPlayingNames(nowPlayingItem) : [];
const textLines = nowPlayingItem ? getItemTextLines(nowPlayingItem) : undefined;
nowPlayingTextElement.innerHTML = '';
if (textLines) {
const itemText = document.createElement('div');
const secondaryText = document.createElement('div');
secondaryText.classList.add('nowPlayingBarSecondaryText');
if (textLines.length > 1) {
textLines[1].secondary = true;
if (textLines[1].text) {
const text = document.createElement('a');
text.innerText = textLines[1].text;
secondaryText.appendChild(text);
}
if (textLines.length > 1 && textLines[1]) {
const text = document.createElement('a');
text.innerText = textLines[1];
secondaryText.appendChild(text);
}
if (textLines[0].text) {
if (textLines[0]) {
const text = document.createElement('a');
text.innerText = textLines[0].text;
text.innerText = textLines[0];
itemText.appendChild(text);
}
nowPlayingTextElement.appendChild(itemText);

View file

@ -1,78 +0,0 @@
export function getNowPlayingNames(nowPlayingItem, includeNonNameInfo) {
let topItem = nowPlayingItem;
let bottomItem = null;
let topText = nowPlayingItem.Name;
if (nowPlayingItem.AlbumId && nowPlayingItem.MediaType === 'Audio') {
topItem = {
Id: nowPlayingItem.AlbumId,
Name: nowPlayingItem.Album,
Type: 'MusicAlbum',
IsFolder: true
};
}
if (nowPlayingItem.MediaType === 'Video') {
if (nowPlayingItem.IndexNumber != null) {
topText = nowPlayingItem.IndexNumber + ' - ' + topText;
}
if (nowPlayingItem.ParentIndexNumber != null) {
topText = nowPlayingItem.ParentIndexNumber + '.' + topText;
}
}
let bottomText = '';
if (nowPlayingItem.ArtistItems?.length) {
bottomItem = {
Id: nowPlayingItem.ArtistItems[0].Id,
Name: nowPlayingItem.ArtistItems[0].Name,
Type: 'MusicArtist',
IsFolder: true
};
bottomText = nowPlayingItem.ArtistItems.map(function (a) {
return a.Name;
}).join(', ');
} else if (nowPlayingItem.Artists?.length) {
bottomText = nowPlayingItem.Artists.join(', ');
} else if (nowPlayingItem.SeriesName || nowPlayingItem.Album) {
bottomText = topText;
topText = nowPlayingItem.SeriesName || nowPlayingItem.Album;
bottomItem = topItem;
if (nowPlayingItem.SeriesId) {
topItem = {
Id: nowPlayingItem.SeriesId,
Name: nowPlayingItem.SeriesName,
Type: 'Series',
IsFolder: true
};
} else {
topItem = null;
}
} else if (nowPlayingItem.ProductionYear && includeNonNameInfo !== false) {
bottomText = nowPlayingItem.ProductionYear;
}
const list = [];
list.push({
text: topText,
item: topItem
});
if (bottomText) {
list.push({
text: bottomText,
item: bottomItem
});
}
return list;
}
export default {
getNowPlayingNames: getNowPlayingNames
};

View file

@ -1,10 +1,13 @@
import escapeHtml from 'escape-html';
import { getImageUrl } from 'apps/stable/features/playback/utils/image';
import { getItemTextLines } from 'apps/stable/features/playback/utils/itemText';
import datetime from '../../scripts/datetime';
import { clearBackdrop, setBackdrops } from '../backdrop/backdrop';
import listView from '../listview/listview';
import imageLoader from '../images/imageLoader';
import { playbackManager } from '../playback/playbackmanager';
import nowPlayingHelper from '../playback/nowplayinghelper';
import Events from '../../utils/events.ts';
import { appHost } from '../apphost';
import globalize from '../../lib/globalize';
@ -22,7 +25,6 @@ import ServerConnections from '../ServerConnections';
import toast from '../toast/toast';
import { appRouter } from '../router/appRouter';
import { getDefaultBackgroundClass } from '../cardbuilder/cardBuilderUtils';
import { getImageUrl } from 'apps/stable/features/playback/utils/image';
let showMuteButton = true;
let showVolumeSlider = true;
@ -86,15 +88,11 @@ function showSubtitleMenu(context, player, button) {
});
}
function getNowPlayingNameHtml(nowPlayingItem, includeNonNameInfo) {
return nowPlayingHelper.getNowPlayingNames(nowPlayingItem, includeNonNameInfo).map(function (i) {
return escapeHtml(i.text);
}).join('<br/>');
}
function updateNowPlayingInfo(context, state, serverId) {
const item = state.NowPlayingItem;
const displayName = item ? getNowPlayingNameHtml(item).replace('<br/>', ' - ') : '';
const displayName = item ?
getItemTextLines(item).map(escapeHtml).join(' - ') :
'';
if (item) {
const nowPlayingServerId = (item.ServerId || serverId);
if (item.Type == 'AudioBook' || item.Type == 'Audio' || item.MediaStreams[0].Type == 'Audio') {