Skip to content

Commit

Permalink
Make favourite entries configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
n0y committed Dec 28, 2020
1 parent 1953250 commit 2435317
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 7 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ To use prefetching, you need to:
* decide on how much space you'll assign to prefetched videos. Use the `CACHE_SIZE_GB` configuration. Mediathek-Dlna-Bridge will never use more disk space than that.
* set the 'ENABLE_PREFETCHING' configuration to `true`

## Configure Favourites

Favourite entries appear at the root level of the DLNA directory tree, just befor all other entries.

You can configure what to display there. Currently, this is done by configuration settings (file, env, ... as you like).

Create entries starting with `FAVOURITE_`. All entries will be sorted alphabetically, and rendered in that order.

In the value, you configure what to display. Currently, only show entries are supported. Value is in the form:

`FAVOURITE_1=show:<channel>:<show title>`, i.e. `FAVOURITE_ONE=show:ard:Tagesschau`

All texts will be compared ignoring the case.

[HOME]: https://github.com/n0y/mediatheken-dlna-bridge
[RELEASES]: https://github.com/n0y/mediatheken-dlna-bridge/releases
[LICENSE]: https://github.com/n0y/mediatheken-dlna-bridge/blob/master/LICENSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.Optional.ofNullable;
import static java.util.stream.Stream.concat;

class ConfigurationAccesor {
private Properties classpathProperties = new Properties();
Expand Down Expand Up @@ -98,4 +101,17 @@ public boolean get(String key, boolean defaultValue) {
}
return cached.orElse(defaultValue);
}

public Map<String, String> getStartingWith(String startingWith) {
return concat(
concat(
classpathProperties.keySet().stream().map(Object::toString),
fileSystemProperties.keySet().stream().map(Object::toString)),
concat(
System.getenv().keySet().stream(),
System.getProperties().keySet().stream().map(Object::toString)))
.filter(s -> s.startsWith(startingWith))
.distinct()
.collect(Collectors.toMap(Function.identity(), key -> get(key, "")));
}
}
29 changes: 29 additions & 0 deletions src/main/java/de/corelogics/mediaview/config/Favourite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* MIT License
*
* Copyright (c) 2020 Mediatheken DLNA Bridge Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.corelogics.mediaview.config;

public interface Favourite {
<T> T accept(FavouriteVisitor<T> visitor);
}
48 changes: 48 additions & 0 deletions src/main/java/de/corelogics/mediaview/config/FavouriteShow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* MIT License
*
* Copyright (c) 2020 Mediatheken DLNA Bridge Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.corelogics.mediaview.config;

public class FavouriteShow implements Favourite {
private final String channel;
private final String title;

public FavouriteShow(String channel, String title) {
this.channel = channel;
this.title = title;
}

@Override
public <T> T accept(FavouriteVisitor<T> visitor) {
return visitor.visitShow(this);
}

public String getChannel() {
return channel;
}

public String getTitle() {
return title;
}
}
29 changes: 29 additions & 0 deletions src/main/java/de/corelogics/mediaview/config/FavouriteVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* MIT License
*
* Copyright (c) 2020 Mediatheken DLNA Bridge Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.corelogics.mediaview.config;

public interface FavouriteVisitor<T> {
T visitShow(FavouriteShow favouriteShow);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@

package de.corelogics.mediaview.config;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Optional.ofNullable;

Expand Down Expand Up @@ -91,4 +96,25 @@ public String getBuildVersion() {
}
return version;
}

public List<Favourite> getFavourites() {
return configAccessor
.getStartingWith("FAVOURITE_")
.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.map(Map.Entry::getValue)
.map(this::toFavourite)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
}

private Optional<Favourite> toFavourite(String favConfig) {
var showPattern = Pattern.compile("^show:([^:]+):(.*)$");
var showMatcher = showPattern.matcher(favConfig);
if (showMatcher.matches()) {
return Optional.of(new FavouriteShow(showMatcher.group(1), showMatcher.group(2)));
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private Set<DlnaRequestHandler> buildRequestHandlers() {
var showContent = new ShowContent(clipContent, this.clipRepository);
var sendungAzContent = new SendungAzContent(this.clipRepository, showContent);
var missedShowsContent = new MissedShowsContent(clipContent, this.clipRepository);
var rootContent = new RootContent(sendungAzContent, showContent, missedShowsContent);
var rootContent = new RootContent(mainConfiguration, sendungAzContent, showContent, missedShowsContent);
return Set.of(clipContent, missedShowsContent, sendungAzContent, rootContent, showContent);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package de.corelogics.mediaview.service.dlna.content;

import de.corelogics.mediaview.config.FavouriteShow;
import de.corelogics.mediaview.config.FavouriteVisitor;
import de.corelogics.mediaview.config.MainConfiguration;
import de.corelogics.mediaview.service.dlna.DlnaRequest;
import org.fourthline.cling.support.model.DIDLContent;
import org.fourthline.cling.support.model.container.StorageFolder;

public class RootContent extends BaseDnlaRequestHandler {
private final MainConfiguration mainConfiguration;
private final SendungAzContent sendungAzContent;

private final ShowContent showContent;

private final MissedShowsContent missedShowsContent;

public RootContent(
MainConfiguration mainConfiguration,
SendungAzContent sendungAzContent,
ShowContent showContent,
MissedShowsContent missedShowsContent) {
this.mainConfiguration = mainConfiguration;
this.sendungAzContent = sendungAzContent;
this.showContent = showContent;
this.missedShowsContent = missedShowsContent;
Expand All @@ -25,7 +30,7 @@ public boolean canHandle(DlnaRequest request) {
}

@Override
protected DIDLContent respondWithException(DlnaRequest request) throws Exception {
protected DIDLContent respondWithException(DlnaRequest request) {
var didl = new DIDLContent();
addFavorites(request, didl);
didl.addContainer(sendungAzContent.createLink(request));
Expand All @@ -34,8 +39,11 @@ protected DIDLContent respondWithException(DlnaRequest request) throws Exception
}

private void addFavorites(DlnaRequest request, DIDLContent didl) {
didl.addContainer(showContent.createAsLink(request, "ARD", "Rote Rosen"));
didl.addContainer(showContent.createAsLink(request, "ARD", "Tagesschau"));
didl.addContainer(showContent.createAsLink(request, "ARD", "Die Sendung mit der Maus"));
mainConfiguration.getFavourites().stream().map(s -> s.accept(new FavouriteVisitor<StorageFolder>() {
@Override
public StorageFolder visitShow(FavouriteShow favouriteShow) {
return showContent.createAsLink(request, favouriteShow.getChannel(), favouriteShow.getTitle());
}
})).forEach(didl::addObject);
}
}

0 comments on commit 2435317

Please sign in to comment.