-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
livestreams from Kodi [DRAFT] #928
Open
codingPF
wants to merge
1
commit into
develop
Choose a base branch
from
feature/livestreamFromKodi
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/de/mediathekview/mserver/crawler/livestream/LivestreamConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package de.mediathekview.mserver.crawler.livestream; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import de.mediathekview.mlib.daten.Sender; | ||
|
||
public final class LivestreamConstants { | ||
|
||
/** Livestreams */ | ||
public static final String URL_LIVESTREAMS = "http://bit.ly/kn-kodi-tv"; | ||
|
||
public static final Map<String,Sender> sender = new HashMap<>(); | ||
|
||
static { | ||
sender.put("3sat", Sender.DREISAT); | ||
sender.put("Das Erste HD", Sender.ARD); | ||
sender.put("one HD", Sender.ARD); | ||
sender.put("ARD-alpha", Sender.ARD); | ||
sender.put("tagesschau24", Sender.ARD); | ||
sender.put("ARTE HD", Sender.ARTE_DE); | ||
sender.put("ARTE HD (FR)", Sender.ARTE_FR); | ||
sender.put("WDR HD", Sender.WDR); | ||
sender.put("SWR Baden-Württemberg HD", Sender.SWR); | ||
sender.put("SWR Rheinland-Pfalz HD", Sender.SWR); | ||
sender.put("NDR Niedersachsen HD", Sender.NDR); | ||
sender.put("NDR Schleswig-Holstein HD", Sender.NDR); | ||
sender.put("NDR Mecklenburg-Vorpommern HD", Sender.NDR); | ||
sender.put("NDR Hamburg HD", Sender.NDR); | ||
sender.put("BR Fernsehen Nord HD", Sender.BR); | ||
sender.put("BR Fernsehen Süd HD", Sender.BR); | ||
sender.put("MDR Sachsen HD", Sender.MDR); | ||
sender.put("MDR Sachsen-Anhalt HD", Sender.MDR); | ||
sender.put("MDR Thüringen HD", Sender.MDR); | ||
sender.put("hr-fernsehen", Sender.HR); | ||
sender.put("rbb Berlin HD", Sender.RBB); | ||
sender.put("rbb Brandenburg HD", Sender.RBB); | ||
sender.put("SR Fernsehen HD", Sender.SR); | ||
sender.put("Deutsche Welle", Sender.DW); | ||
sender.put("Deutsche Welle+", Sender.DW); | ||
sender.put("Deutsche Welle (EN)", Sender.DW); | ||
sender.put("Deutsche Welle (ES)", Sender.DW); | ||
sender.put("phoenix HD", Sender.PHOENIX); | ||
sender.put("Radio Bremen TV", Sender.RBTV); | ||
sender.put("rbb Berlin", Sender.RBB); | ||
sender.put("rbb Brandenburg", Sender.RBB); | ||
sender.put("KiKA", Sender.KIKA); | ||
sender.put("ZDF HD", Sender.ZDF); | ||
sender.put("ZDFneo HD", Sender.ZDF); | ||
sender.put("ZDFinfo HD", Sender.ZDF); | ||
sender.put("ORF eins HD", Sender.ORF); | ||
sender.put("ORF 2 HD", Sender.ORF); | ||
sender.put("ORF III HD", Sender.ORF); | ||
sender.put("ORF SPORT +", Sender.ORF); | ||
}; | ||
|
||
private LivestreamConstants() {} | ||
} |
135 changes: 135 additions & 0 deletions
135
src/main/java/de/mediathekview/mserver/crawler/livestream/LivestreamCrawler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package de.mediathekview.mserver.crawler.livestream; | ||
|
||
import de.mediathekview.mlib.daten.Film; | ||
import de.mediathekview.mlib.daten.FilmUrl; | ||
import de.mediathekview.mlib.daten.Resolution; | ||
import de.mediathekview.mlib.daten.Sender; | ||
import de.mediathekview.mlib.messages.listener.MessageListener; | ||
import de.mediathekview.mserver.base.config.MServerConfigManager; | ||
import de.mediathekview.mserver.base.messages.ServerMessages; | ||
import de.mediathekview.mserver.crawler.basic.AbstractCrawler; | ||
import de.mediathekview.mserver.progress.listeners.SenderProgressListener; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.concurrent.ForkJoinPool; | ||
import java.util.concurrent.RecursiveTask; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class LivestreamCrawler extends AbstractCrawler { | ||
private static final Logger LOG = LogManager.getLogger(LivestreamCrawler.class); | ||
|
||
public LivestreamCrawler( | ||
final ForkJoinPool aForkJoinPool, | ||
final Collection<MessageListener> aMessageListeners, | ||
final Collection<SenderProgressListener> aProgressListeners, | ||
final MServerConfigManager rootConfig) { | ||
super(aForkJoinPool, aMessageListeners, aProgressListeners, rootConfig); | ||
} | ||
|
||
@Override | ||
public Sender getSender() { | ||
return Sender.WDR3; | ||
} | ||
|
||
@Override | ||
protected RecursiveTask<Set<Film>> createCrawlerTask() { | ||
|
||
KodiM3UParser m3uparser = new KodiM3UParser(); | ||
String data = ""; | ||
Set<Film> channels = new HashSet<>(); | ||
try { | ||
data = this.getConnection().requestBodyAsString(LivestreamConstants.URL_LIVESTREAMS); | ||
List<HashMap<String, String>> streamInfo = m3uparser.parse(data); | ||
for (HashMap<String, String> stream : streamInfo) { | ||
if (LivestreamConstants.sender.containsKey(stream.get("tvg-name"))) { | ||
Film f = new Film( | ||
UUID.randomUUID(), | ||
LivestreamConstants.sender.get(stream.get("tvg-name")), | ||
stream.get("name") + " Livestream", | ||
"Livestream", | ||
null, null); | ||
f.addUrl(Resolution.NORMAL, new FilmUrl(new URL(stream.get("url")), 0L)); | ||
channels.add(f); | ||
} | ||
} | ||
//System.out.println("################################"); | ||
//for (HashMap<String, String> stream : streamInfo) { | ||
// System.out.println(stream.get("tvg-name") + "#" + stream.get("name") + "#" + stream.get("url")); | ||
//} | ||
} catch (final IOException e) { | ||
LOG.fatal("Exception in {} crawler.", getSender().getName(), e); | ||
} | ||
printMessage( | ||
ServerMessages.DEBUG_ALL_SENDUNG_FOLGEN_COUNT, getSender().getName(), channels.size()); | ||
getAndSetMaxCount(channels.size()); | ||
return new LivestreamToFilm(channels); | ||
} | ||
|
||
// TODO: move to class when stable | ||
class LivestreamToFilm extends RecursiveTask<Set<Film>> { | ||
private static final long serialVersionUID = 1L; | ||
Set<Film> setOfFilm; | ||
LivestreamToFilm (Set<Film> setOfFilm) { | ||
this.setOfFilm = setOfFilm; | ||
} | ||
|
||
@Override | ||
protected Set<Film> compute() { | ||
return setOfFilm; | ||
} | ||
|
||
} | ||
|
||
// TODO: move to class when stable | ||
class KodiM3UParser { | ||
//#EXTM3U | ||
//#EXTINF:-1 tvg-name="Das Erste HD" tvg-id="DasErste.de" group-title="IPTV-DE" tvg-logo="https://raw.githubusercontent.com/jnk22/kodinerds-iptv/master/logos/tv/daserstehd.png",Das Erste HD | ||
//https://mcdn.daserste.de/daserste/de/master.m3u8 | ||
List<HashMap<String, String>> parse(String aM3U8Data) { | ||
String[] lines = StringUtils.split(aM3U8Data, '\n'); | ||
ArrayList<HashMap<String, String>> data = new ArrayList<>(); | ||
HashMap<String, String> information = new HashMap<>(); | ||
for (String line : lines) { | ||
if (!line.isBlank() && !line.equalsIgnoreCase("#EXTM3U") && !line.equalsIgnoreCase("#")) { | ||
if (line.startsWith("#EXTINF")) { | ||
// remove extint | ||
line = line.substring(8); | ||
// read name (last position after ,) | ||
information.put("name", line.substring(line.lastIndexOf(",")+1)); | ||
// remove name but add space for parsing | ||
line = line.substring(0,line.lastIndexOf(",")) + " "; | ||
// remove length (first position) | ||
information.put("length", line.substring(0,line.indexOf(" "))); | ||
line = line.substring(line.indexOf(" ")+1); | ||
// bag | ||
String[] dictList = line.split("\" "); | ||
for (String valueKeyPair : dictList) { | ||
String key = valueKeyPair.substring(0,valueKeyPair.indexOf("=")); | ||
String value = valueKeyPair.substring(valueKeyPair.indexOf("=")+1); | ||
value = value.replace("\"", ""); | ||
information.put(key.trim(),value.trim()); | ||
} | ||
} else { | ||
information.put("url", line); | ||
data.add(information); | ||
information = new HashMap<>(); | ||
} | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sowas kann das Enum doch 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ja, das ist kommt weg.