Skip to content

Commit

Permalink
move Resolution from BR to KIKA
Browse files Browse the repository at this point in the history
  • Loading branch information
pidoubleyou committed Apr 25, 2023
1 parent bebf0ca commit 503db1e
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import java.util.Optional;
import java.util.Set;

import mServer.crawler.sender.br.Resolution;



public class KikaApiVideoInfoDto {
//
private Optional<String> errorMesssage = Optional.empty();
Expand Down
155 changes: 155 additions & 0 deletions src/main/java/mServer/crawler/sender/kika/Resolution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package mServer.crawler.sender.kika;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

public enum Resolution {
HD(3, "HD"), NORMAL(2, "Normal"), SMALL(1, "Klein"), VERY_SMALL(0, "Sehr klein");

private enum CountingDirection {
HIGHER(+1), LOWER(-1);

int direction;

private CountingDirection(final int direction) {
this.direction = direction;
}

public int getDirectionValue() {
return direction;
}
}

/**
* The bigger the index the better the quality.
*/
private final int resolutionSize;

private final String description;

private Resolution(final int resolutionSize, final String description) {
this.resolutionSize = resolutionSize;
this.description = description;
}

public static List<Resolution> getFromBestToLowest() {
return Arrays.asList(Resolution.values()).stream()
.sorted(Comparator.comparing(Resolution::getResolutionSize).reversed())
.collect(Collectors.toList());
}

public static Resolution getHighestResolution() {
return Resolution.HD;
}

public static Resolution getLowestResolution() {
return Resolution.VERY_SMALL;
}

public static Resolution getNextHigherResolution(final Resolution startingResolution) {
return getNextResolutionByDirection(startingResolution, CountingDirection.HIGHER);
}

public static Resolution getNextLowerResolution(final Resolution startingResolution) {
return getNextResolutionByDirection(startingResolution, CountingDirection.LOWER);
}

/**
* Derzeit sind folgende ARD AudioVideo Ordinals bekannt:<br>
* <ul>
* <li>HD = 1280 width x 720 height</li>
* <li>Premium = 969 width x 540 height</li>
* <li>Large = 640 width x 360 height</li>
* <li>Standard = 512 width x 288 height</li>
* <li>Mobile = 480 width x 270 height</li>
* <li>Mobile_S = 320 width x 180 height</li>
* </ul>
*
* @param profileName
* @return
*/
public static Resolution getResolutionFromArdAudioVideoOrdinalsByProfileName(
final String profileName) {
if (profileName.endsWith("HD")) {
return Resolution.HD;
}
if (profileName.endsWith("Premium")) {
return Resolution.NORMAL;
}
if (profileName.endsWith("Large")) {
return Resolution.SMALL;
}
if (profileName.endsWith("Standard")) {
return Resolution.VERY_SMALL;
}
if (profileName.endsWith("Mobile")) {
return Resolution.VERY_SMALL;
}
if (profileName.endsWith("Mobile_S")) {
return Resolution.VERY_SMALL;
}

return Resolution.VERY_SMALL;

}

/**
* The following width size limits are relevant:<br>
* <ul>
* <li>HD = >= 1280 width</li>
* <li>Normal = >= 969 width</li>
* <li>Small = >= 640 width</li>
* <li>Very Small = < 640 width</li>
* </ul>
*
* @param profileName
* @return
*/
public static Resolution getResolutionFromWidth(final int width) {
if (width >= 1280) {
return Resolution.HD;
}
if (width >= 969) {
return Resolution.NORMAL;
}
if (width >= 640) {
return Resolution.SMALL;
}
return Resolution.VERY_SMALL;
}

static Resolution getNextResolutionByDirection(final Resolution startingResolution,
final CountingDirection direction) {
try {
return getResoultionByResolutionSize(
startingResolution.getResolutionSize() + direction.getDirectionValue());
} catch (final NoSuchElementException nsee) {
return startingResolution;
}
}


static Resolution getResoultionByResolutionSize(final int searchedResolutionSize) {
for (final Resolution currentResolution : Resolution.values()) {
if (searchedResolutionSize == currentResolution.getResolutionSize()) {
return currentResolution;
}
}

throw new NoSuchElementException(
String.format("Resolution with ResolutionIndex %d not found", searchedResolutionSize));
}

public String getDescription() {
return description;
}

public int getResolutionSize() {
return resolutionSize;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import mServer.crawler.sender.base.JsonUtils;
import mServer.crawler.sender.base.UrlUtils;
import mServer.crawler.sender.br.Resolution;
import mServer.crawler.sender.kika.KikaApiVideoInfoDto;
import mServer.crawler.sender.kika.Resolution;

import java.lang.reflect.Type;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import mServer.crawler.sender.base.AbstractRecursivConverterTask;
import mServer.crawler.sender.base.GeoLocations;
import mServer.crawler.sender.base.UrlUtils;
import mServer.crawler.sender.br.Resolution;
import mServer.crawler.sender.kika.KikaApiFilmDto;
import mServer.crawler.sender.kika.KikaApiVideoInfoDto;
import mServer.crawler.sender.kika.Resolution;
import mServer.crawler.sender.kika.json.KikaApiVideoInfoPageDeserializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down

0 comments on commit 503db1e

Please sign in to comment.