Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'net.nemerosa.versioning' version '1.3.0'
id 'com.jfrog.bintray' version '1.1'
id 'com.jfrog.bintray' version '1.2'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason to upgrade the bintray plugin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was when using gradle 2.9.

id 'com.jfrog.artifactory' version '3.0.1'
}

Expand Down
25 changes: 14 additions & 11 deletions src/main/java/org/schedulesdirect/api/Airing.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ static public enum DolbyStatus {
/**
* An unknown value was provided for Dolby status; report the unknown value as a bug ticket for future inclusion
*/
UNKNOWN
UNKNOWN;

public static DolbyStatus fromValue(String val) {
switch(val.toLowerCase().replaceAll("\\W", "")) {
case "dd": return DD;
case "dd51": return DD51;
case "dolby": return DOLBY;
}

return UNKNOWN;
}
}

/**
Expand Down Expand Up @@ -251,14 +261,10 @@ static public enum ContentType {
case "stereo": stereo = true; break;
case "dvs": descriptiveVideo = true; break;
case "subtitled": subtitled = true; break;
case "SAP": sap = true; break;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the incoming value is caps? Usually the values are lower case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is in caps.

default:
if(val.startsWith("D")) { // This is a Dolby marker
try {
dolbyStatus = DolbyStatus.valueOf(val.replaceAll(" ", "").replaceAll("\\.", ""));
} catch(IllegalArgumentException e) {
LOG.warn(String.format("Unknown DolbyStatus encountered! [%s]", val));
dolbyStatus = DolbyStatus.UNKNOWN;
}
dolbyStatus = DolbyStatus.fromValue(val);
} else
LOG.warn(String.format("Unknown audio property encountered! [%s]", val));
}
Expand All @@ -267,9 +273,6 @@ static public enum ContentType {
timeApproximate = src.optBoolean("timeApproximate");
if(subtitled && src.has("subtitledLanguage"))
subtitleLanguage = src.getString("subtitledLanguage");
sap = src.optBoolean("sap");
if(sap && src.has("sapLanguage"))
sapLanguage = src.getString("sapLanguage");
cableInTheClassroom = src.optBoolean("cableInTheClassroom");
subjectToBlackout = src.optBoolean("subjectToBlackout");
educational = src.optBoolean("educational");
Expand Down Expand Up @@ -703,7 +706,7 @@ public void setFinaleStatus(FinaleStatus finaleStatus) {
}

/**
* @param tvRating the tvRating to set
* @param tvRatings the tvRatings to set
*/
public void setTvRatings(ContentRating[] tvRatings) {
this.tvRatings = tvRatings;
Expand Down
127 changes: 127 additions & 0 deletions src/main/java/org/schedulesdirect/api/Artwork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.schedulesdirect.api;

import org.json.JSONObject;

public class Artwork {

public static enum Size {
MASSIVE,
LARGE,
MEDIUM,
SMALL,
EXTRA_SMALL,
UNKNOWN;

public static Size fromString(String val) {
if(val != null) {
switch(val) {
case "Ms":
return Size.MASSIVE;
case "Lg":
return Size.LARGE;
case "Md":
return Size.MEDIUM;
case "Sm":
return Size.SMALL;
case "Xs":
return Size.EXTRA_SMALL;
}
}

return Size.UNKNOWN;
}
}

private String aspect;
private int width;
private int height;
private boolean text;
private String category;
private String uri;
private String tier;
private Size size;

public Artwork(JSONObject obj, EpgClient clnt) {
aspect = obj.optString("aspect");
String width = obj.optString("width");
this.width = width.length() == 0 ? 0 : Integer.parseInt(width);
String height = obj.optString("height");
this.height = height.length() == 0 ? 0 : Integer.parseInt(height);
text = "yes".equalsIgnoreCase(obj.optString("text"));
category = obj.optString("category");
tier = obj.optString("tier");
String uri = obj.optString("uri");
if(uri.matches("^https?:\\/\\/.*")) {
this.uri = uri;
}
else {
this.uri = String.format("%s/%s/image/%s", clnt.getBaseUrl(), EpgClient.API_VERSION, uri);
}

size = Size.fromString(obj.optString("size"));
}

public String getAspect() {
return aspect;
}

public void setAspect(String aspect) {
this.aspect = aspect;
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public boolean isText() {
return text;
}

public void setText(boolean text) {
this.text = text;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

public String getTier() {
return tier;
}

public void setTier(String tier) {
this.tier = tier;
}

public Size getSize() {
return size;
}

public void setSize(Size size) {
this.size = size;
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a unit test for this class as well. Even if it's just a basic one that validates good vs. bad json input. You'll see some simplistic examples for other classes that are this simple already. Basic validation is good, but also provides a starting point should something more substantial be needed later.

13 changes: 10 additions & 3 deletions src/main/java/org/schedulesdirect/api/EpgClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static public String getUriPathForLineupId(String id) {
/**
* Constructor
* @param userAgent The user agent to pass along to all SD HTTP requests
* @param baseUri The base URI to use when constructing URIs/URLs based on relative data in the raw JSON
* @param baseUrl The base URI to use when constructing URIs/URLs based on relative data in the raw JSON
*/
public EpgClient(final String userAgent, final String baseUrl) {
this.userAgent = userAgent;
Expand All @@ -64,7 +64,6 @@ public EpgClient(final String userAgent, final String baseUrl) {
* @param location The 3 letter ISO country code; must be a country supported by the service (USA, CAN, etc.)
* @param zip The zip/postal code to find headends for
* @return An array of Lineup objects representing all available Lineups for the given zip; never returns null, but may return an empty array
* @throws InvalidZipCodeException Thrown if the given zip/postal code is invalid
* @throws IOException Thrown if there is any kind of IO error accessing the raw data feed
*/
public final Lineup[] getLineups(final String location, final String zip) throws IOException {
Expand Down Expand Up @@ -181,6 +180,14 @@ protected void writeLogoToFile(final Station station, final File dest) throws IO
*/
abstract protected Program fetchProgram(final String progId) throws IOException;

/**
* Fetches artwork for a single program
* @param progId The program id to fetch artwork for
* @return The Artwork instance for the given program id or null if unavailable
* @throws IOException Thrown on any IO error accessing the data
*/
abstract protected Artwork[] fetchArtwork(final String progId) throws IOException;

/**
* Fetch multiple recording schedules in batch.
*
Expand Down Expand Up @@ -263,7 +270,7 @@ public String getBaseUrl() {
}

/**
* @param baseUri the baseUrl to set
* @param baseUrl the baseUrl to set
*/
public void setBaseUri(String baseUrl) {
this.baseUrl = baseUrl;
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/org/schedulesdirect/api/NetworkEpgClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -119,7 +122,7 @@ public NetworkEpgClient(final String id, final String pwd) throws InvalidCredent
}

/**
* ctor; typically only used for development & testing; allows overriding of JsonRequestFactory instance
* ctor; typically only used for development & testing; allows overriding of JsonRequestFactory instance
* @param id
* @param pwd
* @param factory
Expand All @@ -145,7 +148,7 @@ public NetworkEpgClient(final String id, final String pwd, final String userAgen
}

/**
* ctor; typically only used for development & testing; allows overriding of JsonRequestFactory instance
* ctor; typically only used for development & testing; allows overriding of JsonRequestFactory instance
* @param id
* @param pwd
* @param userAgent
Expand All @@ -165,7 +168,6 @@ public NetworkEpgClient(final String id, final String pwd, final String userAgen
* @param userAgent The user agent to send on all requests to the SD servers
* @param baseUrl The base URL to use for all HTTP communication; most should not set this value as it is for testing and development only!
* @param useCache Should the client instance maintain a cache of created objects or hit the SD server on every request? Though memory intensive, use of the cache is greatly encouraged!
* @param factory The JsonRequestFactory to be used for this client to generate network requests
* @throws InvalidCredentialsException Thrown if the given credentials were invalid
* @throws IOException Thrown if there is any IO error communicating with the Schedules Direct servers
* @throws ServiceOfflineException Thrown if the web service reports itself as offline/unavailable
Expand Down Expand Up @@ -423,6 +425,39 @@ protected Airing[] fetchSchedule(final Station station) throws IOException {
protected Program fetchProgram(final String progId) throws IOException {
return fetchPrograms(new String[] { progId }).values().toArray(new Program[1])[0];
}

@Override
protected Artwork[] fetchArtwork(String progId) throws IOException {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fetching artwork isn't to be supported via the NetworkClient then this method should throw an UnsupportedOperationException so clients know that it will never return data.

In order for the ZipClient to have data to access, you'll have to modify the grabber to pull down and store this data into the zip file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will implement. I didn't need it initially for my needs, but it may be useful to someone in the future. I have already updated the grabber (locally) to pull the data from SD.

String artProgId = progId;
if(artProgId.length() > 10) {
artProgId = artProgId.substring(0, 10);
}

List<Artwork> aList = new ArrayList<>();

JSONArray req = new JSONArray();
req.put(artProgId);

JSONArray resp = Config.get().getObjectMapper().readValue(factory.get(DefaultJsonRequest.Action.POST, RestNouns.METADATA, getHash(), getUserAgent(), getBaseUrl()).submitForJson(req), JSONArray.class);
for(int i=0; i<resp.length(); i++) {
JSONObject o = resp.getJSONObject(i);
if(!JsonResponseUtils.isErrorResponse(o)) {
Object temp = o.get("data");
if(temp instanceof JSONArray) {
JSONArray artworkArr = o.getJSONArray("data");

for(int j=0; j<artworkArr.length(); j++) {
JSONObject awObj = artworkArr.getJSONObject(j);
aList.add(new Artwork(awObj, this));
}
}
} else {
throw new InvalidJsonObjectException("Error received for Program", o.toString(3));
}
}

return aList.toArray(new Artwork[0]);
}

private void prefetch(JSONArray airings) throws IOException {
List<String> ids = new ArrayList<>();
Expand Down
Loading