Addition of CMS lookup plugin

This commit is contained in:
Daniel Dayley 2020-07-14 15:34:18 -06:00
parent 2d50c86b86
commit 2c672b23da
2 changed files with 103 additions and 0 deletions

32
plugins/channel.py Normal file
View File

@ -0,0 +1,32 @@
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."""
return [ '-ch','--channel', 'store_true', "Return CMS channel info about the subject (channel)" ]
def startup(self) :
pass
def perform_lookup(self,subject) :
channel_guid = list(re.match('([0-9a-fA-F]*)', subject).groups())
if len(channel_guid) > 0 and len(channel_guid[0]) == 32 :
channel_guid = channel_guid[0]
else :
channel_guid = None
self.debug('Channel does not appear to be a channel_id',3)
if channel_guid :
channel_req = requests.get('https://cbd46b77.cdn.cms.movetv.com/cms/api/channels/' + channel_guid + '/schedule/now/playback_info.qvt')
if channel_req.status_code == 200 :
payload = json.loads(channel_req.text)
return_dict = payload['playback_info']
return return_dict
else :
self.debug('Got ' + channel_req.status_code + ' for channel info request from CMS',1)
def search_for_channel(self,subject) :
pass

71
plugins/cms.py Normal file
View File

@ -0,0 +1,71 @@
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."""
return [ '-cms','--channel', 'store_true', "Return CMS channel info about the subject (cms)" ]
def startup(self) :
pass
def lookup(self,subject) :
self.debug('Checking channel...',1)
guid = list(re.match('([0-9a-fA-F]*)', subject).groups())
if len(guid) > 0 and len(guid[0]) == 32 :
guid = guid[0]
self.debug('Channel appears to be a valid guid',3)
else :
guid = None
self.debug('Channel does not appear to be a valid guid',3)
if guid :
channels = self.get_channel(guid)
if channels :
channels = {'channels':[channels]}
channels['channels'][0].update({'self_url':'https://cbd46b77.cdn.cms.movetv.com/cms/api/channels/' + guid + '/schedule/now/playback_info.qvt'})
try :
asset = self.get_asset(channels['channels'][0]['asset']['guid'])
channels.update({'assets':[asset]})
channels['assets'][0].update({'self_url':'https://cbd46b77.cms.movetv.com/cms/publish3/asset/info/' + channels['channels'][0]['asset']['guid'] + '.json'})
except :
pass
return channels
else :
assets = self.get_asset(guid)
if assets :
assets = {'assets':[assets]}
assets['assets'][0].update({'self_url':'https://cbd46b77.cms.movetv.com/cms/publish3/asset/info/' + guid + '.json'})
# Gets the channels that the asset was played on.
# Since this isn't always accurate for finished live assets, we'll leave it out
# try :
# channels = [x['channel_guid'] for x in [y['schedules'] for y in assets['assets']][0]]
# channels = {'channels':[self.get_channel(x) for x in channels]}
# assets.update(channels)
# except Exception as e:
# print(e)
return assets
def get_channel(self,guid) :
self.debug('Trying channel info request...',2)
channel_req = requests.get('https://cbd46b77.cdn.cms.movetv.com/cms/api/channels/' + guid + '/schedule/now/playback_info.qvt')
if channel_req.status_code == 200 :
self.debug('Channel appears to be a valid channel',3)
payload = json.loads(channel_req.text)
return_dict = payload['playback_info']
return return_dict
else :
self.debug('Got ' + str(channel_req.status_code) + ' for channel info request from CMS',1)
def get_asset(self,guid) :
self.debug('Trying asset info request...',2)
asset_req = requests.get('https://cbd46b77.cms.movetv.com/cms/publish3/asset/info/' + guid + '.json')
if asset_req.status_code == 200 :
self.debug('Channel appears to be a asset',3)
payload = json.loads(asset_req.text)
return_dict = payload
return return_dict
else :
self.debug('Got ' + str(asset_req.status_code) + ' for asset info request from CMS',1)