ifxlookup/plugins/guid_channels.py

60 lines
16 KiB
Python
Raw Normal View History

from servicebase import ServiceBase
import re
import requests
import json
class ServiceDelegate(ServiceBase) :
def get_arguments(cls) :
"""Returns an array of information used to construct an argumentparser argument."""
2020-05-22 18:28:13 +00:00
return [ '-gc','--guid_channels', 'store_true', 'Return working channels for GUID' ]
def startup(self) :
# Load sub pack from options
for requirement in ['sub_pack'] :
if requirement not in self.config or (requirement in self.config and self.config[requirement] is ''):
self.error.append('Missing required config option ' + requirement)
return
self.sub_pack = self.config['sub_pack']
self.channels = json.loads(requests.get('https://cbd46b77.cdn.cms.movetv.com/cms/publish3/domain/channels/v4/-0700/770/' + self.sub_pack + '/1.json').text)['subscriptionpacks'][0]['channels']
self.channels_small = {x['channel_guid']:x['title'] for x in self.channels}
self.debug('Beginning search for subscribed channels for GUID.',1)
self.debug('This will take a long time. Increase the verbosity level to watch the progress.',1)
self.progress = 0
self.goal = len(self.channels_small)
def lookup(self,subject) :
channels = {}
guid = list(re.match('([0-9a-fA-F]*)', subject.replace('-','')).groups())
if len(guid) > 0 and len(guid[0]) == 32 :
guid = guid[0]
else :
guid = None
self.debug('Subject does not appear to be a valid GUID',1)
self.error.append('Subject does not appear to be a valid GUID')
return None
for channel in self.channels_small :
self.progress += 1
resp = self.make_drm_request(channel,guid)
if resp == 200 :
channels.update({channel:self.channels_small[channel]})
return {'channels':channels,'count':len(channels)}
def make_drm_request(self,channel_guid,user_guid) :
"""Starts a widevine handshake and looks for 200 to indicate the asset/channel is eligible for play."""
payload = {
'env': 'production',
'user_id': user_guid,
'channel_id': channel_guid,
2020-05-22 18:28:13 +00:00
'message': self.sample_pssh
}
drm_req = requests.post('http://p-drmwv.movetv.com/widevine/proxy', json=payload)
if drm_req.status_code == 200 :
verbosity = 2
else :
verbosity = 3
self.debug('Got ' + str(drm_req.status_code) + ' for channel ' + str(channel_guid) + ' for user ' + str(user_guid) + ' (' + str(self.progress) + '/' + str(self.goal) + ')',verbosity)
return drm_req.status_code
2020-05-22 18:28:13 +00:00
sample_pssh = [8,1,18,129,29,18,82,10,80,10,58,8,1,18,32,99,53,101,53,48,55,51,100,51,102,48,50,52,49,98,102,56,97,99,54,48,99,101,101,48,55,101,98,49,48,98,100,26,7,115,108,105,110,103,116,118,34,4,84,79,80,67,42,5,83,68,95,72,68,16,1,26,16,153,14,129,143,185,186,160,15,125,191,37,127,114,2,45,119,24,1,32,219,170,139,246,5,48,21,66,160,28,10,20,108,105,99,101,110,115,101,46,119,105,100,101,118,105,110,101,46,99,111,109,18,16,23,5,185,23,204,18,4,134,139,6,51,58,47,119,42,140,26,224,25,242,201,29,158,43,232,104,47,129,35,98,111,59,142,28,129,168,11,159,148,192,74,217,38,158,149,123,124,72,122,19,71,206,205,76,213,223,123,198,219,23,213,18,39,213,25,52,46,198,133,224,164,73,42,243,6,44,171,203,212,53,91,230,221,217,48,148,27,33,76,27,51,113,59,125,242,195,48,97,118,233,143,4,132,225,136,102,186,116,83,234,142,98,8,83,121,192,168,147,199,233,89,148,112,35,177,163,120,112,230,129,236,221,183,216,136,207,116,84,131,93,15,86,32,19,237,4,169,196,47,20,229,103,15,66,206,74,163,5,136,242,117,69,135,82,84,97,190,131,1,1,34,35,106,219,137,17,188,11,135,21,244,56,79,147,162,63,87,166,72,2,210,190,1,52,134,186,87,4,36,231,178,252,130,192,1,76,6,232,131,8,126,174,178,89,80,209,155,229,63,19,216,64,207,163,50,222,67,59,209,74,26,136,219,144,26,125,177,76,57,167,51,55,25,88,181,240,106,71,3,168,199,52,16,92,125,143,181,216,176,220,85,29,105,213,190,39,189,17,206,21,16,58,138,180,8,36,164,30,234,19,226,32,101,191,225,145,203,126,148,100,38,237,66,15,192,3,187,144,100,204,50,72,28,20,84,226,184,97,199,129,192,14,60,133,136,19,17,246,202,132,87,137,198,159,129,134,221,203,103,213,32,32,40,65,194,251,102,113,245,137,251,143,142,146,219,114,149,203,81,11,63,39,170,142,134,141,139,15,119,83,228,248,60,183,176,134,161,234,138,65,179,175,142,116,172,223,235,184,0,103,53,80,123,177,252,255,197,47,244,176,70,119,69,45,197,49,74,25,131,141,119,34,145,218,139,157,218,255,163,48,198,74,106,99,92,33,30,220,41,170,88,250,247,198,53,45,226,41,51,192,140,221,78,180,1,72,253,97,191,209,250,154,243,103,142,102,37,56,49,69,77,73,26,252,69,168,42,74,177,127,233,147,53,193,209,152,5,73,81,0,50,247,97,204,107,54,200,64,152,96,144,148,103,59,207,82,44,124,58,191,130,223,41,202,54,74,146,190,170,24,73,208,49,49,87,31,176,67,152,211,135,247,30,107,168,183,168,139,84,198,24,164,48,93,253,119,179,19,127,249,214,57,74,254,122,55,226,202,175,195,211,123,27,255,204,171,152,87,223,3,191,135,245,252,238,78,22,209,184,110,47,65,23,154,204,5,61,249,213,234,30,246,46,71,130,94,250,11,105,74,185,126,40,63,115,160,62,121,128,215,24,170,226,97,22,79,183,65,124,40,245,229,92,87,154,214,74,193,66,69,90,21,191,121,70,130,54,125,85,136,186,85,67,21,92,231,119,15,166,132,135,159,53,67,99,38,79,141,29,177,63,64,10,178,28,229,205,22,217,178,196,56,234,170,168,235,249,66,22,248,103,180,158,5,159,24,104,196,1,146,246,168,84,200,210,81,172,130,103,70,63,201,165,76,16,152,32,106,26,32,60,42,122,122,165,171,204,134,214,194,215,14,85,26,37,87,240,151,191,160,170,53,85,20,253,6,11,72,73,240,207,68,230,145,86,180,126,254,204,59,189,120,5,200,32,140,94,230,115,93,136,175,74,94,152,81,57,187,157,206,159,44,50,59,106,254,196,226,63,184,11,58,24,248,125,78,39,169,60,97,10,231,37,158,162,4,216,238,79,89,45,149,53,88,86,179,101,112,42,202,186,120,238,58,103,202,78,136,224,63,16,108,71,38,49,185,240,1,158,35,79,228,58,25,32,170,59,140,93,89,136,47,10,24,220,1,141,219,200,90,234,176,221,7,242,189,243,113,44,240,16,44,40,156,53,242,123,52,139,108,215,7,148,219,253,39,234,89,38,151,178,26,154,72,26,226,84,207,170,236,25,1,205,210,20,223,95,243,157,87,252,210,38,82,230,148,60,254,182,81,128,14,41,209,153,3,152,190,221,87,224,59,190,58,26,3,245,64,18,175,146,66,34,193,241,56,97,152,155,82,226,155,180,16,126,135,71,137,228,141,199,52,220,143,73,216,92,236,224,57,11,138,240,242,252,113,246,197,111,42,202,134,57,48,114,0,101,11,47,90,195,166,204,55,96,78,47,151,198,203,46,130,220,149,99,181,166,20,90,125,245,211,68,241,51,75,32,96,223,111,10,128,213,87,79,202,246,49,238,43,6,151,77,175,29,36,183,190,92,57,177,69,71,89,18,145,188,73,3,72,225,229,42,34,209,66,241,244,193,200,250,179,29,13,230,226,194,15