public class ZipEpgClient extends EpgClient
The zip file to be used must follow a specific format and structure. Such a zip file can be generated by running the EPG Grabber application.
This implementation has two common uses:
Most every real world application should only be accessing EPG data via instances of this class. Apps should download their EPG data once a day using the sdjson grabber application then feeding that generated zip file into instances of this class to access the EPG data in their apps.
Modifier and Type | Field and Description |
---|---|
static String |
INVALID_FILE_CHARS
Regex of invalid chars for file names in the zip
|
static String |
LINEUPS_LIST
The file containing all the lineups stored in this zip cache
|
static String |
USER_DATA
The file containing the user data for this zip cache (i.e.
|
static Charset |
ZIP_CHARSET
The default charset encoding used for all data in the generated zip file
|
static int |
ZIP_VER
The zip file version this grabber generates
|
static String |
ZIP_VER_FILE
Name of the file holding the zip file version number
|
API_VERSION
Constructor and Description |
---|
ZipEpgClient(File zip)
Constructor
|
ZipEpgClient(File zip,
String baseUrl)
Constructor
|
ZipEpgClient(Path zip)
Constructor
|
ZipEpgClient(Path zip,
String baseUrl)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close and free all resources associated with this client connection
|
void |
deleteMessage(Message msg)
Acknowledge receipt of and delete a message object from the upstream provider.
|
protected String |
fetchChannelMapping(Lineup lineup)
Fetch the channel mapping for the given Linup object
|
protected InputStream |
fetchLogoStream(Station station)
Fetch a Station's logo object
|
protected Program |
fetchProgram(String progId)
Fetch a single Program object
|
protected Map<String,Program> |
fetchPrograms(String[] progIds)
Fetch multiple programs in batch.
|
protected Airing[] |
fetchSchedule(Station station)
Fetch a single airing schedule for the given Station reference
|
protected Map<Station,Airing[]> |
fetchSchedules(Lineup lineup)
Fetch multiple recording schedules in batch.
|
protected void |
finalize() |
protected org.json.JSONObject |
findMetadataForDevice(org.json.JSONArray metas,
String dev)
Find the metadata object for the given device name
|
Airing[] |
findScheduleGap()
Check all downloaded schedules for gaps in the airing schedules
|
Lineup |
getLineupByUriPath(String path)
Get the lineup for the given uri
|
Lineup[] |
getLineups()
Provide all available lineups for the logged in user.
|
SystemStatus |
getSystemStatus()
Return details of the current state of the Schedules Direct system
|
UserStatus |
getUserStatus()
Get the UserStatus object associated with this EpgClient connection
|
void |
purgeCache()
Purge the client's object cache.
|
void |
purgeCache(Object obj)
Purge a specific object from the client's cache.
|
int |
registerLineup(String path)
Register the given lineup with the user's SD account
|
static String |
scrubFileName(String input)
Scrub a file name, replacing invalid chars
|
protected Lineup[] |
searchForLineups(String location,
String zip)
Provide all available lineups for the given location.
|
int |
unregisterLineup(Lineup l)
Unregister the lineup from the user's SD account
|
getBaseUrl, getLineups, getUriPathForLineupId, getUserAgent, setBaseUri, setUserAgent, writeLogoToFile
public static final String ZIP_VER_FILE
public static final int ZIP_VER
public static final Charset ZIP_CHARSET
public static final String LINEUPS_LIST
public static final String USER_DATA
public static final String INVALID_FILE_CHARS
public ZipEpgClient(Path zip, String baseUrl) throws IOException
zip
- The zip path to be used as the data source for this client implementationbaseUrl
- The base URL used to construct absolute URLs from relative URL data in the raw JSONIOException
- Thrown on any IO error reading the zip filepublic ZipEpgClient(File zip, String baseUrl) throws IOException
zip
- The zip file to be used as the data source for this client implementationbaseUrl
- The base URL used to construct absolute URLs from relative URL data in the raw JSONIOException
- Thrown on any IO error reading the zip filepublic ZipEpgClient(Path zip) throws IOException
zip
- The zip path to be used as the data source for this client implementationIOException
- Thrown on any IO error reading the zip filepublic ZipEpgClient(File zip) throws IOException
zip
- The zip file to be used as the data source for this client implementationIOException
- Thrown on any IO error reading the zip filepublic static String scrubFileName(String input)
input
- The file name to scrubpublic UserStatus getUserStatus() throws IOException
EpgClient
getUserStatus
in class EpgClient
IOException
- Thrown if there is any kind of IO error accessing the raw data feedpublic void close() throws IOException
EpgClient
close
in class EpgClient
IOException
- On any IO errorprotected void finalize() throws Throwable
protected Airing[] fetchSchedule(Station station) throws IOException
EpgClient
fetchSchedule
in class EpgClient
station
- The station to fetch the airing schedule forIOException
- Thrown on any IO error accessing the schedule dataprotected Program fetchProgram(String progId) throws IOException
EpgClient
fetchProgram
in class EpgClient
progId
- The program id to fetchIOException
- Thrown on any IO error accessing the dataprotected Map<Station,Airing[]> fetchSchedules(Lineup lineup) throws IOException
EpgClient
This method is preferred to fetchSchedule() as it will grab multiple schedules much more efficiently. Use this when ever you can.
fetchSchedules
in class EpgClient
lineup
- The Lineup object to download schedules forIOException
- In case of any IO error accessing the dataprotected Map<String,Program> fetchPrograms(String[] progIds) throws IOException
EpgClient
This method is preferred to fetchProgram() as it will grab multiple programs much more efficiently. Use this when ever you can.
fetchPrograms
in class EpgClient
progIds
- An array of program ids to fetchIOException
- On any IO error accessing the dataprotected org.json.JSONObject findMetadataForDevice(org.json.JSONArray metas, String dev) throws org.json.JSONException
metas
- The array of metadata objectsdev
- The device name being sought afterorg.json.JSONException
- On any JSON error encounteredpublic Lineup[] getLineups() throws IOException
EpgClient
This method will only return those lineups that are configured in the user's Schedules Direct account. These are the only lineups to which the user is guaranteed to have access to listings data for.
getLineups
in class EpgClient
IOException
- Thrown if there is any kind of IO error accessing the data feedpublic void purgeCache()
EpgClient
purgeCache
in class EpgClient
public void purgeCache(Object obj)
EpgClient
purgeCache
in class EpgClient
obj
- The object to purge from the client's local cachepublic void deleteMessage(Message msg) throws IOException
EpgClient
Optional operation
deleteMessage
in class EpgClient
msg
- The message object to be deletedIOException
- In case of any IO error upstreampublic Airing[] findScheduleGap() throws IOException
The data received from upstream should never have gaps in the schedules. If so, that is an error that invalidates the data in the local cache and the data should no longer be trusted.
IOException
- in case of any IO error during the operationpublic SystemStatus getSystemStatus() throws IOException
EpgClient
getSystemStatus
in class EpgClient
IOException
- In case of any errors obtaining the status infoprotected InputStream fetchLogoStream(Station station) throws IOException
EpgClient
fetchLogoStream
in class EpgClient
station
- The station whose logo is to be fetchedIOException
- Thrown on any IO errorpublic int registerLineup(String path) throws IOException
EpgClient
Optional operation
registerLineup
in class EpgClient
path
- The full, absolute URI of the lineup to register; perhaps grab this value from EpgClient.getUriPathForLineupId()
IOException
- On any IO errorpublic int unregisterLineup(Lineup l) throws IOException
EpgClient
Optional operation
unregisterLineup
in class EpgClient
l
- The linup to unregister from the user's accountIOException
- On any IO errorprotected Lineup[] searchForLineups(String location, String zip) throws IOException
EpgClient
searchForLineups
in class EpgClient
location
- The 3 letter ISO country code; must be a country supported by the service (USA, CAN, etc.)zip
- The zip/postal code to find headends forIOException
- Thrown if there is any kind of IO error accessing the raw data feedpublic Lineup getLineupByUriPath(String path) throws IOException
EpgClient
NOTE:This method will only return objects registered to the user's account (or available in the local cache). This method will not construct a Lineup object and return it if you do not have access to the Lineup in question. In other words, you must register a lineup in your SD account before this method will return it.
getLineupByUriPath
in class EpgClient
path
- The absolute path to access the lineup data from; appended to BASE_URL to form full URI to be accessedIOException
- Thrown if there is any kind of IO error accessing the raw data feedprotected String fetchChannelMapping(Lineup lineup) throws IOException
EpgClient
fetchChannelMapping
in class EpgClient
lineup
- The lineup to fetch channel mappings forIOException
- On any IO errorCopyright © 2012–2014 Battams, Derek. All rights reserved.