Skip to content

Commit

Permalink
optimize orf urls if only one stream is found
Browse files Browse the repository at this point in the history
  • Loading branch information
pidoubleyou committed Mar 23, 2024
1 parent 5dee698 commit f614070
Show file tree
Hide file tree
Showing 3 changed files with 21,510 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,27 @@ public OrfOnVideoInfoDTO deserialize(
parseWebsite(JsonUtils.getElementValueAsString(jsonElement, TAG_SHARE_BODY)),
parseGeoLocations(JsonUtils.getElementValueAsString(jsonElement, TAG_RIGHT)),
parseSubtitleSource(JsonUtils.getElementValueAsString(jsonElement, TAG_SUBTITLE)),
parseUrl(jsonElement),
optimizeUrls(parseUrl(jsonElement)),
buildOrResolveSubs(jsonElement)

);
return aFilm;
}


private Optional<Map<Resolution, FilmUrl>> optimizeUrls(Optional<Map<Resolution, FilmUrl>> urls) {
if (urls.isPresent() && urls.get().size() == 1) {
final Map<Resolution, FilmUrl> urlMap = urls.get();
final FilmUrl url = urlMap.get(Resolution.NORMAL);
final String urlToOptimize = url.getUrl().toString();
try {
urlMap.put(Resolution.SMALL, new FilmUrl(urlToOptimize.replace("QXA", "Q4A"), 0L));
urlMap.put(Resolution.NORMAL, new FilmUrl(urlToOptimize.replace("QXA", "Q6A"), 0L));
urlMap.put(Resolution.HD, new FilmUrl(urlToOptimize.replace("QXA", "Q8C"), 0L));
} catch (MalformedURLException e) {}
}
return urls;
}

private Optional<Set<URL>> buildOrResolveSubs(JsonElement jsonElement) {
Optional<String> subtitleSource = JsonUtils.getElementValueAsString(jsonElement, TAG_SUBTITLE);
Optional<JsonElement> embeddedSubtitleSection = JsonUtils.getElement(jsonElement, TAG_SUBTITLE_SECTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;


import de.mediathekview.mlib.daten.*;
import de.mediathekview.mlib.messages.listener.MessageListener;
import de.mediathekview.mserver.base.config.MServerConfigManager;
import de.mediathekview.mserver.crawler.orfon.task.OrfOnEpisodeTask;
import de.mediathekview.mserver.progress.listeners.SenderProgressListener;
import de.mediathekview.mserver.testhelper.AssertFilm;
import java.net.URL;
import java.time.Duration;
import java.time.LocalDateTime;
Expand All @@ -16,21 +21,17 @@
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ForkJoinPool;

import org.junit.Test;

import de.mediathekview.mlib.daten.Film;
import de.mediathekview.mlib.daten.FilmUrl;
import de.mediathekview.mlib.daten.GeoLocations;
import de.mediathekview.mlib.daten.Resolution;
import de.mediathekview.mlib.messages.listener.MessageListener;
import de.mediathekview.mserver.base.config.MServerConfigManager;
import de.mediathekview.mserver.crawler.orfon.task.OrfOnEpisodeTask;
import de.mediathekview.mserver.progress.listeners.SenderProgressListener;


public class OrfOnEpisodeTaskTest extends OrfOnEpisodesTaskTest {

protected static OrfOnCrawler createCrawler() {
final ForkJoinPool forkJoinPool = new ForkJoinPool();
final Collection<MessageListener> nachrichten = new ArrayList<>();
final Collection<SenderProgressListener> fortschritte = new ArrayList<>();
return new OrfOnCrawler(forkJoinPool, nachrichten, fortschritte, new MServerConfigManager("MServer-JUnit-Config.yaml"));
}

@Test
public void testNormal_1() {
setupSuccessfulJsonResponse("/episode1", "/orfOn/episode_1.json");
Expand Down Expand Up @@ -63,7 +64,7 @@ Resolution.VERY_SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwid
assertTrue(false);
}
}

@Test
public void testNormal_2() {
setupSuccessfulJsonResponse("/episode2", "/orfOn/episode_2.json");
Expand Down Expand Up @@ -97,6 +98,29 @@ Resolution.VERY_SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/
}
}

@Test
public void testZib() {
setupSuccessfulJsonResponse("/zib", "/orfOn/episode_zib.json");
Set<Film> result = executeTask("/zib");
assertTrue(result.size() == 1);
Film actual = result.toArray(new Film[1])[0];

AssertFilm.assertEquals(
actual,
Sender.ORF,
"ZIB 13:00",
"ZIB 13:00 vom 20.03.2024",
LocalDateTime.of(2024, 3, 20, 13, 0, 0),
Duration.ofSeconds(1177),
"Wohnbaupaket passiert Nationalrat | ORF-Analyse: Details zum Wohnbaupaket | Neue Lehrerausbildung kommt ein Jahr später | Agrarprodukte aus Ukraine werden wieder verzollt | ORF-Analyse: Zölle auf Landwirtschaftsgüter aus Ukraine | London: Zweiter Anlauf für \"Ruanda-Plan\" | Vorschau: GB stimmt über \"Ruanda-Plan\" ab | 2023: Über 1.300 Vorfälle von Rassismus in Österreich | Rekordhoch bei Insolvenze\n.....",
"https://tvthek.orf.at/profile/ZIB-1300/71280/ZIB-1300-vom-20-03-2024/14218665",
new GeoLocations[] { GeoLocations.GEO_NONE},
"https://apasfiis.sf.apa.at/ipad/cms-worldwide_episodes/14218665_0017_Q4A.mp4/playlist.m3u8",
"https://apasfiis.sf.apa.at/ipad/cms-worldwide_episodes/14218665_0017_Q6A.mp4/playlist.m3u8",
"https://apasfiis.sf.apa.at/ipad/cms-worldwide_episodes/14218665_0017_Q8C.mp4/playlist.m3u8",
"https://api-tvthek.orf.at/assets/subtitles/0171/59/69a0deabec546a7fb5fabc7ebb44e55a031987ac.ttml");
}

@Test
public void testAD() {
setupSuccessfulJsonResponse("/episodeAD", "/orfOn/episode_ad.json");
Expand Down Expand Up @@ -173,13 +197,6 @@ private Set<Film> executeTask(String... requestUrl) {
return new OrfOnEpisodeTask(OrfOnEpisodeTaskTest.createCrawler(), input).invoke();
}

protected static OrfOnCrawler createCrawler() {
final ForkJoinPool forkJoinPool = new ForkJoinPool();
final Collection<MessageListener> nachrichten = new ArrayList<>();
final Collection<SenderProgressListener> fortschritte = new ArrayList<>();
return new OrfOnCrawler(forkJoinPool, nachrichten, fortschritte, new MServerConfigManager("MServer-JUnit-Config.yaml"));
}



}
Loading

0 comments on commit f614070

Please sign in to comment.