MasterPuppeteer

Added some catchup and live TV2 regional channels

package tv.puppetmaster.denmark
import org.json.JSONArray
import org.json.JSONObject
import tv.puppetmaster.data.BasePuppetIterator
import tv.puppetmaster.data.i.*
import tv.puppetmaster.data.i.Puppet.PuppetIterator
......@@ -9,38 +11,44 @@ class DRPuppet implements InstallablePuppet {
static final CHANNELS = [
[
name: "DR1",
catchupSlug:"dr1",
description:"General entertainment and news",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/664804230117527552/lBG49nZu.png",
url: "http://drtext-lh.akamaihd.net/i/live/drtext01_0@66578/master.m3u8?b=300-4000",
],
[
name: "DR2",
catchupSlug:"dr2",
description:"Goes more in-depth with news and other topics",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/877456303001677824/D7GXadrJ_400x400.jpg",
url: "http://drtext-lh.akamaihd.net/i/live/drtext02_0@67577/master.m3u8?b=100-4000",
],
[
name: "DR3",
catchupSlug:"dr3",
description:"Aimed at the younger audience (15-30)",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/875643442772058112/mcc8Cwd__400x400.jpg",
url: "https://dr03-lh.akamaihd.net/i/live/dr03_0@147056/master.m3u8?b=300-4000",
],
[
name: "DR K",
catchupSlug:"dr-k",
description:"K for Culture, has some good documentaries, also plays classical music once in a while",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
url: "https://dr04-lh.akamaihd.net/i/live/dr04_0@147057/master.m3u8?b=100-4000",
],
[
name: "DR Ramasjang",
catchupSlug:"dr-ramasjang",
description:"Kids TV pre-/early-school ages",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/514802960140746752/KsD1vkea.jpeg",
url: "https://dr05-lh.akamaihd.net/i/live/dr05_0@147058/master.m3u8?b=100-5000",
],
[
name: "DR Ultra",
catchupSlug:"dr-ultra",
description:"Kids TV for the older kids",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/659663610407448576/TY13Ur6e.jpg",
url: "https://dr06-lh.akamaihd.net/i/live/dr06_0@147059/master.m3u8?b=100-4000",
],
[
......@@ -94,8 +102,48 @@ class DRPuppet implements InstallablePuppet {
url: "https://drevent-lh.akamaihd.net/i/DRweb10_1@143694/master.m3u8",
],
[
name: "Østjylland",
imageUrl: "https://pbs.twimg.com/profile_images/849002256016056324/I4ITBv_F.jpg",
url: "https://cdnapisec.kaltura.com/p/2102081/sp/210208100/playManifest/entryId/0_x4p3licd/format/applehttp/protocol/https/uiConfId/34372181/a.m3u8",
],
[
name: "Øst",
imageUrl: "https://pbs.twimg.com/profile_images/506691136056852481/spVpjgA-_400x400.png",
url: "https://cdnapisec.kaltura.com/p/1953381/sp/195338100/playManifest/entryId/0_zphj9q61/format/applehttp/protocol/https/uiConfId/33111111/a.m3u8",
],
[
name: "Lorry",
imageUrl: "https://pbs.twimg.com/profile_images/691203006084190208/JxkskKwk.png",
url: "https://cdnapisec.kaltura.com/p/2045321/sp/204532100/playManifest/entryId/0_5l7gjlbn/format/applehttp/protocol/https/uiConfId/32599481/a.m3u8",
],
[
name: "Syd",
imageUrl: "https://pbs.twimg.com/profile_images/445317209800200192/RnlSCXNk.png",
url: "https://cdnapisec.kaltura.com/p/1956351/sp/195635100/playManifest/entryId/0_e9slj9wh/format/applehttp/protocol/https/uiConfId/30151771/a.m3u8",
],
[
name: "Fyn",
imageUrl: "https://pbs.twimg.com/profile_images/749530827575463936/rcNgSAy7.jpg",
url: "https://cdnapisec.kaltura.com/p/1966291/sp/196629100/playManifest/entryId/0_vsfrv0zm/format/applehttp/protocol/https/uiConfId/30288171/a.m3u8",
],
[
name: "Midtvest",
imageUrl: "https://pbs.twimg.com/profile_images/897767963658465281/tT7E6o8s.jpg",
url: "https://cdnapisec.kaltura.com/p/1953371/sp/195337100/playManifest/entryId/0_ghzg9q0q/format/applehttp/protocol/https/uiConfId/33632211/a.m3u8",
],
[
name: "Nord",
imageUrl: "https://pbs.twimg.com/profile_images/894481178765479936/yObqEQ6D_400x400.jpg",
url: "https://cdnapisec.kaltura.com/p/1956931/sp/195693100/playManifest/entryId/0_74s20zcv/format/applehttp/protocol/https/uiConfId/41270632/a.m3u8",
],
[
name: "Bornholm",
imageUrl: "https://pbs.twimg.com/profile_images/743003841797316608/8qfB54op_400x400.jpg",
url: "http://live.tv2bornholm.dk/stream/live/playlist.m3u8",
],
[
name: "DR P1",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/378800000774293385/9bcb1103214c0e25e701eb5da3cc22cd_400x400.jpeg",
url: "https://drradio1-lh.akamaihd.net/i/p1_9@143503/master.m3u8",
],
[
......@@ -185,7 +233,7 @@ class DRPuppet implements InstallablePuppet {
],
[
name: "DR Nyheder",
imageUrl: "https://www.dr.dk/assets/img/logos/dr-logo-tv-200x200.png",
imageUrl: "https://pbs.twimg.com/profile_images/583941179915526144/NHwaS7ul_400x400.png",
url: "https://drradio2-lh.akamaihd.net/i/drnyheder_9@143532/master.m3u8",
],
]
......@@ -230,9 +278,22 @@ class DRPuppet implements InstallablePuppet {
it.imageUrl,
mBackgroundImageUrl,
-1,
null,
it.url
))
}
CHANNELS.each {
if (it.containsKey('catchupSlug')) {
children.add(new DRChannelPuppet(
this,
it.name,
it.description,
it.imageUrl,
mBackgroundImageUrl,
it.catchupSlug
))
}
}
return children
}
......@@ -347,6 +408,136 @@ class DRPuppet implements InstallablePuppet {
return list
}
class DRChannelPuppet extends DRPuppet {
String mSlug
DRChannelPuppet(ParentPuppet parent, String name, String description, String imageUrl, String backgroundImageUrl, String slug) {
super(parent, true, name, description, imageUrl, backgroundImageUrl)
mSlug = slug
}
@Override
PuppetIterator getChildren() {
PuppetIterator children = new BasePuppetIterator()
children.add(new DRProgramCardPuppet(
this,
'Last Chance',
mImageUrl,
mBackgroundImageUrl,
"https://www.dr.dk/mu-online/api/1.4/list/view/lastchance?limit=%d&offset=%d&channel=%s",
mSlug,
0
))
children.add(new DRProgramCardPuppet(
this,
'Most Viewed',
mImageUrl,
mBackgroundImageUrl,
"https://www.dr.dk/mu-online/api/1.4/list/view/mostviewed?channelType=TV&limit=%d&offset=%d&channel=%s",
mSlug,
0
))
return children
}
}
class DRProgramCardPuppet extends DRPuppet {
static final int MAX_ITEMS = 25
String mApiUrl
String mSlug
int mOffset
DRProgramCardPuppet(ParentPuppet parent, String name, String imageUrl, String backgroundImageUrl, String apiUrl, String slug, int offset) {
super(parent, false, name, null, imageUrl, backgroundImageUrl)
mApiUrl = apiUrl
mOffset = offset
mSlug = slug
}
@Override
PuppetIterator getChildren() {
PuppetIterator children = new BasePuppetIterator()
String page = new URL(sprintf(mApiUrl, MAX_ITEMS, mOffset, mSlug)).getText(requestProperties: [
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
])
JSONArray items = new JSONObject(page).getJSONArray('Items')
for (int i = 0; i < items.length(); i++) {
JSONObject item = items.getJSONObject(i)
JSONObject asset = item.getJSONObject('PrimaryAsset')
children.add(new DRSourcesPuppet(
this,
item.getString('Title'),
item.getString('SeriesTitle'),
item.getString('PrimaryImageUri'),
mBackgroundImageUrl,
asset.getLong('DurationInMilliseconds'),
item.getString('PrimaryBroadcastStartTime').split('T')[0],
asset.getString('Uri')
))
}
if (items.length() == MAX_ITEMS) {
children.add(new DRProgramCardPuppet(
this,
'>>',
mImageUrl,
mBackgroundImageUrl,
mApiUrl,
mSlug,
mOffset + MAX_ITEMS
))
}
return children
}
}
class DRSeriesPuppet extends DRPuppet {
static final String API_URL = "https://www.dr.dk/mu-online/api/1.4/page/tv/programs?channel=%s&orderBy=LastPrimaryBroadcastWithPublicAsset&orderDescending=true"
DRSeriesPuppet(ParentPuppet parent, String name, String imageUrl, String backgroundImageUrl, String slug) {
super(parent, false, name, null, imageUrl, backgroundImageUrl)
mSlug = slug
}
@Override
PuppetIterator getChildren() {
PuppetIterator children = new BasePuppetIterator()
String page = new URL(sprintf(API_URL, mSlug)).getText(requestProperties: [
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
])
JSONArray items = new JSONObject(page).getJSONArray('Programs')
for (int i = 0; i < items.length(); i++) {
JSONObject item = items.getJSONObject(i)
JSONObject asset = item.getJSONObject('PrimaryAsset')
children.add(new DRSourcesPuppet(
this,
item.getString('Title'),
item.getString('SeriesTitle'),
item.getString('PrimaryImageUri'),
mBackgroundImageUrl,
asset.getLong('DurationInMilliseconds'),
item.getString('PrimaryBroadcastStartTime').split('T')[0],
asset.getString('Uri')
))
}
if (items.length() == MAX_ITEMS) {
children.add(new DRProgramCardPuppet(
this,
'>>',
mImageUrl,
mBackgroundImageUrl,
mApiUrl,
mSlug,
mOffset + MAX_ITEMS
))
}
return children
}
}
class DRSourcesPuppet implements SourcesPuppet {
ParentPuppet mParent
......@@ -355,15 +546,19 @@ class DRPuppet implements InstallablePuppet {
String mImageUrl
String mBackgroundImageUrl
long mDuration
String mPublicationDate
String mUrl
DRSourcesPuppet(ParentPuppet parent, String name, String description, String imageUrl, String backgroundImageUrl, long duration, String url) {
List<SourcesPuppet.SubtitleDescription> mSubtitles = new ArrayList<SourcesPuppet.SubtitleDescription>()
DRSourcesPuppet(ParentPuppet parent, String name, String description, String imageUrl, String backgroundImageUrl, long duration, String publicationDate, String url) {
mParent = parent
mName = name
mDescription = description
mImageUrl = imageUrl
mBackgroundImageUrl = backgroundImageUrl
mDuration = duration
mPublicationDate = publicationDate
mUrl = url
}
......@@ -394,6 +589,10 @@ class DRPuppet implements InstallablePuppet {
@Override
boolean isUnavailableIn(String region) {
if (['kaltura.com', 'tv2bornholm'].any { mUrl.contains(it) })
{
return false
}
return region != 'dk'
}
......@@ -424,7 +623,7 @@ class DRPuppet implements InstallablePuppet {
@Override
String getPublicationDate() {
return null
return mPublicationDate
}
@Override
......@@ -460,6 +659,29 @@ class DRPuppet implements InstallablePuppet {
SourcesPuppet.SourceDescription source = new SourcesPuppet.SourceDescription()
source.url = mUrl
mSources.add(source)
} else {
JSONObject json = new JSONObject(new URL(mUrl).getText(requestProperties: [
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
]))
JSONArray links = json.getJSONArray('Links')
for (int i = 0; i < links.length(); i++) {
JSONObject l = links.getJSONObject(i)
SourcesPuppet.SourceDescription source = new SourcesPuppet.SourceDescription()
source.url = l.getString('Uri')
if (l.has('Bitrate')) {
source.bitrate = l.getLong('Bitrate')
}
mSources.add(source)
}
JSONArray subtitles = json.getJSONArray('SubtitlesList')
for (int i = 0; i < subtitles.length(); i++) {
JSONObject s = subtitles.getJSONObject(i)
SourcesPuppet.SubtitleDescription subtitle = new SourcesPuppet.SubtitleDescription()
subtitle.url = s.getString('Uri')
subtitle.mime = s.getString('MimeType')
subtitle.locale = s.getString('Language')
mSubtitles.add(subtitle)
}
}
}
return mCurrentIndex < mSources.size()
......