Skip to content

Commit

Permalink
zdf: 720p als normale Url analog ARD
Browse files Browse the repository at this point in the history
  • Loading branch information
pidoubleyou committed Feb 24, 2025
1 parent 564a1de commit 8392a36
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public class ZdfVideoUrlOptimizer {
private static final String NORMAL_2360_35_15 = "2360k_p35v15.mp4";
private static final String NORMAL_2360_35_17 = "2360k_p35v17.mp4";

private static final String HD_3256 = "3256k_p15v12.mp4";
private static final String HD_3296_15_13 = "3296k_p15v13.mp4";
private static final String HD_3296_15_14 = "3296k_p15v14.mp4";
private static final String HD_3328_15_15 = "3328k_p15v15.mp4";
private static final String HD_3328_15_17 = "3328k_p15v17.mp4";
private static final String HD_3328_12 = "3328k_p36v12.mp4";
private static final String HD_3328_13 = "3328k_p36v13.mp4";
private static final String HD_3328_14 = "3328k_p36v14.mp4";
private static final String HD_3328_35_14 = "3328k_p35v14.mp4";
private static final String HD_3328_36_13 = "3328k_p36v13.mp4";
private static final String HD_3328_36_14 = "3328k_p36v14.mp4";
private static final String HD_3360_36_15 = "3360k_p36v15.mp4";
private static final String HD_3360_36_17 = "3360k_p36v17.mp4";
private static final String NORMAL_3256 = "3256k_p15v12.mp4";
private static final String NORMAL_3296_15_13 = "3296k_p15v13.mp4";
private static final String NORMAL_3296_15_14 = "3296k_p15v14.mp4";
private static final String NORMAL_3328_15_15 = "3328k_p15v15.mp4";
private static final String NORMAL_3328_15_17 = "3328k_p15v17.mp4";
private static final String NORMAL_3328_12 = "3328k_p36v12.mp4";
private static final String NORMAL_3328_13 = "3328k_p36v13.mp4";
private static final String NORMAL_3328_14 = "3328k_p36v14.mp4";
private static final String NORMAL_3328_35_14 = "3328k_p35v14.mp4";
private static final String NORMAL_3328_36_13 = "3328k_p36v13.mp4";
private static final String NORMAL_3328_36_14 = "3328k_p36v14.mp4";
private static final String NORMAL_3360_36_15 = "3360k_p36v15.mp4";
private static final String NORMAL_3360_36_17 = "3360k_p36v17.mp4";
private static final String HD_6628_61_17 = "6628k_p61v17.mp4";
private static final String HD_6660_37_17 = "6660k_p37v17.mp4";

Expand All @@ -52,38 +52,33 @@ public class ZdfVideoUrlOptimizer {
private static final Map<String, String[]> HD_OPTIMIZE = new HashMap<>();

static {
NORMAL_OPTIMIZE.put(NORMAL_1628_13_17, new String[] {NORMAL_2360_35_17});
NORMAL_OPTIMIZE.put(NORMAL_1628_13_17, new String[] {NORMAL_3360_36_17, NORMAL_2360_35_17});
NORMAL_OPTIMIZE.put(NORMAL_2256_14_11, new String[] {NORMAL_2328_35_11});
NORMAL_OPTIMIZE.put(NORMAL_2256_14_12, new String[] {NORMAL_2328_35_12});
NORMAL_OPTIMIZE.put(NORMAL_2256_14_12, new String[] {NORMAL_3328_12, NORMAL_3256, NORMAL_2328_35_12});
NORMAL_OPTIMIZE.put(NORMAL_2296_14_13, new String[] {NORMAL_2328_35_13});
NORMAL_OPTIMIZE.put(NORMAL_2296_14_14, new String[] {NORMAL_2328_35_14});
NORMAL_OPTIMIZE.put(NORMAL_2296_14_14, new String[] {NORMAL_3328_14, NORMAL_3328_35_14, NORMAL_3328_13, NORMAL_3296_15_14, NORMAL_3296_15_13, NORMAL_2328_35_14});
NORMAL_OPTIMIZE.put(NORMAL_1456_13_11, new String[] {NORMAL_2328_35_11, NORMAL_2256_14_11});
NORMAL_OPTIMIZE.put(NORMAL_1456_13_12, new String[] {NORMAL_2328_35_12, NORMAL_2256_14_12});
NORMAL_OPTIMIZE.put(NORMAL_1496_13_13, new String[] {NORMAL_2328_35_13, NORMAL_2296_14_13});
NORMAL_OPTIMIZE.put(NORMAL_1496_13_14, new String[] {NORMAL_2328_35_14, NORMAL_2296_14_14});
NORMAL_OPTIMIZE.put(NORMAL_1628_13_15, new String[] {NORMAL_2360_35_15});

NORMAL_TO_HD.put(NORMAL_2360_35_17, new String[] {HD_6660_37_17, HD_6628_61_17, HD_3360_36_17});
NORMAL_TO_HD.put(NORMAL_1628_13_17, new String[] {HD_6660_37_17, HD_6628_61_17, HD_3360_36_17});
NORMAL_TO_HD.put(NORMAL_1456_13_12, new String[] {HD_3328_12, HD_3256});
NORMAL_TO_HD.put(NORMAL_2256_14_12, new String[] {HD_3328_12, HD_3256});
NORMAL_TO_HD.put(NORMAL_2328_35_12, new String[] {HD_3328_12, HD_3256});
NORMAL_TO_HD.put(NORMAL_1496_13_13, new String[] {HD_3328_13, HD_3296_15_14, HD_3296_15_13});
NORMAL_TO_HD.put(NORMAL_2296_14_13, new String[] {HD_3328_13, HD_3296_15_14, HD_3296_15_13});
NORMAL_TO_HD.put(NORMAL_2328_35_13, new String[] {HD_3328_13, HD_3296_15_14, HD_3296_15_13});
NORMAL_TO_HD.put(NORMAL_1496_13_14, new String[] {HD_3328_14, HD_3328_35_14});
NORMAL_TO_HD.put(NORMAL_2296_14_14, new String[] {HD_3328_14, HD_3328_35_14});
NORMAL_TO_HD.put(NORMAL_2328_35_14, new String[] {HD_3328_14, HD_3328_35_14});
NORMAL_TO_HD.put(NORMAL_1628_13_15, new String[] {HD_3360_36_15});
NORMAL_TO_HD.put(NORMAL_2360_35_15, new String[] {HD_3360_36_15});

HD_OPTIMIZE.put(HD_3360_36_17, new String[] {HD_6660_37_17, HD_6628_61_17});
NORMAL_OPTIMIZE.put(NORMAL_1456_13_12, new String[] {NORMAL_3328_12, NORMAL_3256, NORMAL_2328_35_12, NORMAL_2256_14_12});
NORMAL_OPTIMIZE.put(NORMAL_1496_13_13, new String[] {NORMAL_3328_13, NORMAL_3296_15_14, NORMAL_3296_15_13, NORMAL_2328_35_13, NORMAL_2296_14_13});
NORMAL_OPTIMIZE.put(NORMAL_1496_13_14, new String[] {NORMAL_3328_14, NORMAL_3328_35_14, NORMAL_2328_35_14, NORMAL_2296_14_14});
NORMAL_OPTIMIZE.put(NORMAL_1628_13_15, new String[] {NORMAL_3360_36_15, NORMAL_2360_35_15});
NORMAL_OPTIMIZE.put(NORMAL_3328_15_15, new String[] {NORMAL_3360_36_15});
NORMAL_OPTIMIZE.put(NORMAL_3256, new String[] {NORMAL_3328_12});
NORMAL_OPTIMIZE.put(NORMAL_3296_15_14, new String[] {NORMAL_3328_36_14});
NORMAL_OPTIMIZE.put(NORMAL_3296_15_13, new String[] {NORMAL_3328_36_13});
NORMAL_OPTIMIZE.put(NORMAL_3328_15_17, new String[] {NORMAL_3360_36_17});
NORMAL_OPTIMIZE.put(NORMAL_2328_35_12, new String[] {NORMAL_3328_12, NORMAL_3256});
NORMAL_OPTIMIZE.put(NORMAL_2328_35_13, new String[] {NORMAL_3328_13, NORMAL_3296_15_14, NORMAL_3296_15_13});
NORMAL_OPTIMIZE.put(NORMAL_2328_35_14, new String[] {NORMAL_3328_14, NORMAL_3328_35_14});
NORMAL_OPTIMIZE.put(NORMAL_2360_35_15, new String[] {NORMAL_3360_36_15});
NORMAL_OPTIMIZE.put(NORMAL_2360_35_17, new String[] {NORMAL_3360_36_17});

NORMAL_TO_HD.put(NORMAL_2360_35_17, new String[] {HD_6660_37_17, HD_6628_61_17});
NORMAL_TO_HD.put(NORMAL_1628_13_17, new String[] {HD_6660_37_17, HD_6628_61_17});
NORMAL_TO_HD.put(NORMAL_3360_36_17, new String[] {HD_6660_37_17, HD_6628_61_17});
NORMAL_TO_HD.put(NORMAL_3328_15_17, new String[] {HD_6660_37_17, HD_6628_61_17});

HD_OPTIMIZE.put(HD_6628_61_17, new String[] {HD_6660_37_17});
HD_OPTIMIZE.put(HD_3328_15_17, new String[] {HD_6660_37_17, HD_6628_61_17, HD_3360_36_17});
HD_OPTIMIZE.put(HD_3328_15_15, new String[] {HD_3360_36_15});
HD_OPTIMIZE.put(HD_3256, new String[] {HD_3328_12});
HD_OPTIMIZE.put(HD_3296_15_14, new String[] {HD_3328_36_14});
HD_OPTIMIZE.put(HD_3296_15_13, new String[] {HD_3328_36_13});
}

protected AbstractCrawler crawler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ private void parseDuration(final DownloadDto dto, final JsonObject rootNode) {
}
}

private void parseFormitaet(final DownloadDto dto, final JsonElement formitaet) {
private void parseFormitaet(final List<DownloadInfo> downloads, final JsonElement formitaet) {
// only mp4-videos are relevant
final JsonElement mimeType = formitaet.getAsJsonObject().get(JSON_ELEMENT_MIMETYPE);
if (mimeType != null && mimeType.getAsString().equalsIgnoreCase(RELEVANT_MIME_TYPE)) {

List<DownloadInfo> downloads = new ArrayList<>();

// array Resolution
final JsonArray qualityList =
Expand Down Expand Up @@ -135,9 +134,6 @@ private void parseFormitaet(final DownloadDto dto, final JsonElement formitaet)
}
}
}

downloads.sort(Comparator.comparingInt(DownloadInfo::verticalResolution));
downloads.forEach(info -> dto.addUrl(info.language(), info.resolution(), info.uri()));
}
}

Expand All @@ -159,14 +155,13 @@ private void parseGeoLocation(final DownloadDto dto, final JsonObject rootNode)
}
}

private void parsePriority(final DownloadDto dto, final JsonElement priority) {
private void parsePriority(final List<DownloadInfo> downloads, final JsonElement priority) {
if (priority != null) {

// array formitaeten
final JsonArray formitaetList =
priority.getAsJsonObject().getAsJsonArray(JSON_ELEMENT_FORMITAET);
for (final JsonElement formitaet : formitaetList) {
parseFormitaet(dto, formitaet);
parseFormitaet(downloads, formitaet);
}
}
}
Expand Down Expand Up @@ -203,9 +198,9 @@ private Resolution parseVideoQuality(final JsonObject quality) {
qualityValue = Resolution.SMALL;
break;
case ZDF_QUALITY_VERYHIGH:
case ZDF_QUALITY_HD:
qualityValue = Resolution.NORMAL;
break;
case ZDF_QUALITY_HD:
case ZDF_QUALITY_FHD:
qualityValue = Resolution.HD;
break;
Expand All @@ -220,12 +215,17 @@ private Resolution parseVideoQuality(final JsonObject quality) {
}

private void parseVideoUrls(final DownloadDto dto, final JsonObject rootNode) {
List<DownloadInfo> downloads = new ArrayList<>();

// array priorityList
final JsonArray priorityList = rootNode.getAsJsonArray(JSON_ELEMENT_PRIORITYLIST);
for (final JsonElement priority : priorityList) {

parsePriority(dto, priority);
parsePriority(downloads, priority);
}

downloads.sort(Comparator.comparingInt(DownloadInfo::verticalResolution));
downloads.forEach(info -> dto.addUrl(info.language(), info.resolution(), info.uri()));
}

private record DownloadInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,13 @@ public void getOptimizedUrlHdTestAlreadyBestQuality() {

@Test
public void getOptimizedUrlHdTestBetterUrlExists() {
final String url = getWireMockBaseUrlSafe() + "/video_3360k_p36v17.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_6628k_p61v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6660k_p37v17.mp4";

setupHeadResponse("/video_6660k_p37v17.mp4", 200);
assertGetOptimizedUrlHd(expectedUrl, url);
}

@Test
public void getOptimizedUrlHdTestBetterUrlExists2() {
final String url = getWireMockBaseUrlSafe() + "/video_3360k_p36v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6628k_p61v17.mp4";

setupHeadResponse("/video_6628k_p61v17.mp4", 200);
assertGetOptimizedUrlHd(expectedUrl, url);
}

@Test
public void getOptimizedUrlHdTestBetterUrlNotExists() {
final String url = getWireMockBaseUrlSafe() + "/video_3360k_p36v17.mp4";
Expand All @@ -92,57 +83,57 @@ public void getOptimizedUrlHdTestBetterUrlNotExists() {

@Test
public void determineUrlHdTestFirstUrlExists() {
final String url = getWireMockBaseUrlSafe() + "/video_1456k_p13v12.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_3328k_p36v12.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_1628k_p13v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6660k_p37v17.mp4";

setupHeadResponse("/video_3328k_p36v12.mp4", 200);
setupHeadResponse("/video_6660k_p37v17.mp4", 200);
assertDetermineUrlHd(Optional.of(expectedUrl), url);
}

@Test
public void determineUrlHdTestFirstUrlExists2() {
final String url = getWireMockBaseUrlSafe() + "/video_2360k_p35v15.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_3360k_p36v15.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_2360k_p35v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6660k_p37v17.mp4";

setupHeadResponse("/video_3360k_p36v15.mp4", 200);
setupHeadResponse("/video_6660k_p37v17.mp4", 200);
assertDetermineUrlHd(Optional.of(expectedUrl), url);
}

@Test
public void determineUrlHdTestFirstUrlExists3() {
final String url = getWireMockBaseUrlSafe() + "/video_1628k_p13v15.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_3360k_p36v15.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_3328k_p15v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6660k_p37v17.mp4";

setupHeadResponse("/video_3360k_p36v15.mp4", 200);
setupHeadResponse("/video_6660k_p37v17.mp4", 200);
assertDetermineUrlHd(Optional.of(expectedUrl), url);
}

@Test
public void determineUrlHdTestSecondUrlExists() {
final String url = getWireMockBaseUrlSafe() + "/video_1456k_p13v12.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_3256k_p15v12.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_1628k_p13v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6628k_p61v17.mp4";

setupHeadResponse("/video_3328k_p36v12.mp4", 404);
setupHeadResponse("/video_3256k_p15v12.mp4", 200);
setupHeadResponse("/video_6660k_p37v17.mp4", 404);
setupHeadResponse("/video_6628k_p61v17.mp4", 200);
assertDetermineUrlHd(Optional.of(expectedUrl), url);
}

@Test
public void determineUrlHdTestNoUrlExists() {
final String url = getWireMockBaseUrlSafe() + "/video_1456k_p13v12.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_1628k_p13v17.mp4";

setupHeadResponse("/video_3328k_p36v12.mp4", 404);
setupHeadResponse("/video_3256k_p15v12.mp4", 404);
setupHeadResponse("/video_6660k_p37v17.mp4", 404);
setupHeadResponse("/video_6628k_p61v17.mp4", 404);
assertDetermineUrlHd(Optional.empty(), url);
}

@Test
public void determineUrlHdTestBothUrlExists() {
final String url = getWireMockBaseUrlSafe() + "/video_1496k_p13v13.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_3328k_p36v13.mp4";
final String url = getWireMockBaseUrlSafe() + "/video_1628k_p13v17.mp4";
final String expectedUrl = getWireMockBaseUrlSafe() + "/video_6660k_p37v17.mp4";

setupHeadResponse("/video_3328k_p36v13.mp4", 200);
setupHeadResponse("/video_3296k_p15v13.mp4", 200);
setupHeadResponse("/video_6660k_p37v17.mp4", 200);
setupHeadResponse("/video_6628k_p61v17.mp4", 200);
assertDetermineUrlHd(Optional.of(expectedUrl), url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public static Collection<Object[]> data() {
{
"/zdf/zdf_video_details1.json",
"http://localhost:8589/none/zdf/16/06/160605_echte_kerle_das_duo_neo/6/160605_echte_kerle_das_duo_neo_436k_p9v12.mp4",
"http://localhost:8589/none/zdf/16/06/160605_echte_kerle_das_duo_neo/6/160605_echte_kerle_das_duo_neo_1456k_p13v12.mp4",
"http://localhost:8589/none/zdf/16/06/160605_echte_kerle_das_duo_neo/6/160605_echte_kerle_das_duo_neo_3328k_p36v12.mp4",
"",
"",
Expand All @@ -91,6 +90,7 @@ public static Collection<Object[]> data() {
"",
"",
"",
"",
Optional.empty(),
Optional.empty(),
Optional.of(GeoLocations.GEO_NONE)
Expand Down Expand Up @@ -190,16 +190,16 @@ public static Collection<Object[]> data() {
{
"/zdf/zdf_video_details_uhd.json",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a1a2_808k_p11v15.mp4",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a1a2_1628k_p13v15.mp4",
// "http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a1a2_1628k_p13v15.mp4",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a1a2_3328k_p15v15.mp4",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a1a2_4692k_p72v16.mp4",
"", "http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a1a2_4692k_p72v16.mp4",
"",
"",
"",
"",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a3a4_808k_p11v15.mp4",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a3a4_1628k_p13v15.mp4",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a3a4_3328k_p15v15.mp4",
"",
"http://localhost:8589/none/zdf/23/01/230101_2015_sendung_trs/3/230101_2015_sendung_trs_a3a4_4692k_p72v16.mp4",
Optional.of(
"https://utstreaming.zdf.de/mtt/zdf/23/01/230101_2015_sendung_trs/6/F1037067_hoh_deu_Das_Traumschiff_Bahamas_Karibik_final_010123.xml"),
Expand All @@ -209,7 +209,7 @@ public static Collection<Object[]> data() {
{
"/zdf/zdf_video_details_fhd.json",
"http://localhost:8589/dach/zdf/20/12/201222_schwarm_meerestroemung_tex/3/201222_schwarm_meerestroemung_tex_808k_p11v17.mp4",
"http://localhost:8589/dach/zdf/20/12/201222_schwarm_meerestroemung_tex/3/201222_schwarm_meerestroemung_tex_1628k_p13v17.mp4",
"http://localhost:8589/dach/zdf/20/12/201222_schwarm_meerestroemung_tex/3/201222_schwarm_meerestroemung_tex_3328k_p15v17.mp4",
"http://localhost:8589/dach/zdf/20/12/201222_schwarm_meerestroemung_tex/3/201222_schwarm_meerestroemung_tex_6628k_p61v17.mp4",
"",
"",
Expand All @@ -227,15 +227,15 @@ public static Collection<Object[]> data() {
{
"/zdf/zdf_video_details_eng_ut.json",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a1a2_808k_p11v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a1a2_1628k_p13v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a1a2_3328k_p15v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a1a2_6628k_p61v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a1a2_4692k_p72v16.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a3a4_808k_p11v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a3a4_1628k_p13v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a3a4_3328k_p15v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a3a4_6628k_p61v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a3a4_4692k_p72v16.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a5a6_808k_p11v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a5a6_1628k_p13v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a5a6_3328k_p15v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a5a6_6628k_p61v17.mp4",
"http://localhost:8589/de/zdf/23/02/230222_1001_sendung_swm/7/230222_1001_sendung_swm_a5a6_4692k_p72v16.mp4",
Optional.of(
Expand Down
Loading

0 comments on commit 8392a36

Please sign in to comment.