-
Notifications
You must be signed in to change notification settings - Fork 5
Artwork, JavaDoc updates #7
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
|
@@ -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"); | ||
|
@@ -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; | ||
|
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; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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<>(); | ||
|
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.
Is there a particular reason to upgrade the bintray plugin?
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.
Yes, it was when using gradle 2.9.