Skip to content

Commit

Permalink
Append season names to season folders
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfaceS committed Jul 16, 2024
1 parent 782df88 commit e470944
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/pms/store/container/MediaLibraryFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,15 @@ public void doRefreshChildren() {
}
}
boolean isExpectedTVSeries = expectedOutput == TVSERIES || expectedOutput == TVSERIES_NOSORT || expectedOutput == TVSERIES_WITH_FILTERS;
boolean isExpectedTVSeason = expectedOutput == EPISODES;
boolean isExpectedMovieFolder = expectedOutput == MOVIE_FOLDERS;
if (isExpectedTVSeries) {
Long tvSeriesId = getMediaLibraryTvSeriesId(virtualFolderName);
if (tvSeriesId != null) {
newVirtualFoldersResources.add(new MediaLibraryTvSeries(renderer, tvSeriesId, sqls2, expectedOutputs2));
}
} else if (isExpectedTVSeason) {
newVirtualFoldersResources.add(new MediaLibraryTvSeason(renderer, i18nName, virtualFolderName, sqls2, expectedOutputs2));
} else if (isExpectedMovieFolder) {
String filename = getMediaLibraryMovieFilename(virtualFolderName);
if (filename != null) {
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/net/pms/store/container/MediaLibraryTvSeason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* This file is part of Universal Media Server, based on PS3 Media Server.
*
* This program is a free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License only.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.store.container;

import net.pms.media.video.metadata.ApiSeason;
import net.pms.media.video.metadata.TvSeriesMetadata;
import net.pms.renderers.Renderer;
import org.apache.commons.lang3.StringUtils;

/**
* @author SurfaceS
*/
public class MediaLibraryTvSeason extends MediaLibraryFolder {

private final Integer tvSeasonId;
private TvSeriesMetadata tvSeriesMetadata;
private String seasonName = "";

public MediaLibraryTvSeason(Renderer renderer, String i18nName, String tvSeason, String[] sql, int[] expectedOutput) {
super(renderer, i18nName, sql, expectedOutput, tvSeason);
this.tvSeasonId = getInteger(tvSeason);
this.isSortable = false;
}

@Override
public String getName() {
return super.getName().concat(getSeasonName());
}

/**
* Returns the localized display name.
*
* @return The localized display name.
*/
@Override
public String getLocalizedDisplayName(String lang) {
return super.getLocalizedDisplayName(lang).concat(getSeasonName());
}

private TvSeriesMetadata getTvSeriesMetadata() {
if (tvSeriesMetadata == null && tvSeasonId != null && getParent() instanceof MediaLibraryTvSeries mediaLibraryTvSeries) {
tvSeriesMetadata = mediaLibraryTvSeries.getTvSeriesMetadata();
}
return tvSeriesMetadata;
}

/**
* Get the season name.
*
* Will be possible to localize it when/if we store localized data.
*
* @return the season name or empty string.
*/
private synchronized String getSeasonName() {
if (seasonName.isEmpty() && getTvSeriesMetadata() != null && tvSeriesMetadata.getSeasons() != null && tvSeasonId != null) {
for (ApiSeason season : tvSeriesMetadata.getSeasons()) {
if (season.getSeasonNumber() == tvSeasonId) {
if (!StringUtils.isBlank(season.getName()) &&
!season.getName().equalsIgnoreCase("Season " + season.getSeasonNumber())) {
seasonName = ": " + season.getName();
}
break;
}
}
}
return seasonName;
}

private static Integer getInteger(String value) {
try {
return Integer.valueOf(value);
} catch (NumberFormatException e) {
return null;
}
}

}

0 comments on commit e470944

Please sign in to comment.