Created
March 23, 2015 15:03
-
-
Save Noxville/72e0d957669e57d9e848 to your computer and use it in GitHub Desktop.
Stream Interface Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package streams | |
import org.codehaus.jackson.JsonNode | |
class HitboxStream implements Stream { | |
String getName() { | |
'Hitbox' | |
} | |
void update(Date index) { | |
JsonService jsonService = new JsonService() | |
def uri = "http://api.hitbox.tv/media/" | |
print "GET [${name}] ${uri}" | |
try { | |
process(jsonService.fromJson(new URL(uri).text), index) | |
} | |
catch (Exception e) { | |
print "Exception: ${e}: ${e.stackTrace.toString()}" | |
} | |
} | |
void process(json, date) { | |
def streams = json.livestream | |
for (JsonNode stream: streams) { | |
def ss = new StreamSnapshot( | |
date: date, | |
service: name, | |
channel: stream?.media_user_name?.textValue ?: "Unlisted", | |
game: stream?.category_name?.textValue ?: "Unlisted", | |
broadcastName: stream?.media_status?.textValue ?: "Unlisted", | |
viewers: stream?.media_views?.asLong(), | |
json: stream.toString(), | |
url: stream?.channel?.channel_link?.textValue ?: "Unlisted" | |
) | |
if (ss.viewers >= 1) { | |
ss.save(failOnError: true) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment