def parseDate(day, channel): variables = { "slots": ["MORNING", "NOON", "EVENING", "NIGHT"], "day": day, "broadcasterId": "av:http://ard.de/ontologies/ard#" + channel } p = json.dumps({'query': queries.getQueryDate(), 'variables': variables}) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for epg in j['data']['viewer']['allLivestreams']['edges'][0]['node'][ 'epg']: broadcastEvent = epg['broadcastEvent'] publicationOf = broadcastEvent['publicationOf'] if len(publicationOf['essences']['edges']) != 0: d = _buildVideoDict(publicationOf) start = broadcastEvent['start'].split('+') if (len(start) == 1): airedtime = datetime.datetime( *(time.strptime(start[0], "%Y-%m-%dT%H:%M:%S.%fZ")[0:6])) tz_offset = datetime.timedelta( minutes=(time.timezone / -60) + (time.localtime().tm_isdst * 60)) airedtime += tz_offset else: airedtime = datetime.datetime( *(time.strptime(start[0], "%Y-%m-%dT%H:%M:%S.%f")[0:6])) d['_airedtime'] = airedtime.strftime("%H:%M") d['_type'] = 'date' l.append(d) return l
def getSearch(s): l = [] url = 'http://www.arte.tv/hbbtvv2/services/web/index.php/OPA/v3/videos/search/text/'+urllib.quote_plus(s)+'/de' response = libMediathek.getUrl(url) j = json.loads(response) #http://www.arte.tv/hbbtvv2/services/web/index.php/OPA/v3/videos/collection/MAGAZINE/RC-014077/de for teaser in j['teasers']: d = {} d['_name'] = teaser['title'] d['_tvshowtitle'] = teaser['title'] if teaser['imageUrl'] != None: d['_thumb'] = teaser['imageUrl'] if teaser['kind'] == 'PLAYLIST' or teaser['kind'] == 'TV_SERIES' or teaser['kind'] == 'TOPIC': d['url'] = 'http://www.arte.tv/hbbtvv2/services/web/index.php/OPA/v3/videos/collection/MAGAZINE/'+teaser['programId']+'/de' d['mode'] = 'libArteListVideos' d['_type'] = 'dir' l.append(d) elif teaser['kind'] == 'SHOW': d['url'] = 'https://api.arte.tv/api/player/v1/config/de/'+teaser['programId']+'?autostart=0&lifeCycle=1&lang=de_DE&config=arte_tvguide' d['mode'] = 'libArtePlay' d['_type'] = 'video' l.append(d) else: libMediathek.log('unsupported kind found: '+teaser['kind']) return l
def parseVideo(id): variables = {'clipId': id} #variables = {'clipId':'av:5896c99cab0d0d001203ea82'} #variables = {'clipId':'av:5a3caa4ec96563001843d591'} p = json.dumps({'query': queries.getQueryVideo(), 'variables': variables}) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] x = j['data']['viewer']['clip']['videoFiles']['edges'] if x: node = x[0]['node'] d = {} d['media'] = [] d['media'].append({'url': node['publicLocation'], 'stream': 'hls'}) try: sub = node['subtitles']['edges'][0]['node']['timedTextFiles'][ 'edges'][0]['node']['publicLocation'] d['subtitle'] = [{'url': sub, 'type': 'ttml', 'lang': 'de'}] except: pass return d else: return None
def parseSeries(): p = json.dumps({'query': queries.getQuerySeries()}) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for edge in j['data']['viewer']['allSeries']['edges']: d = {} node = edge['node'] d['name'] = node['title'] if node['kicker'] != None: d['_tvshowtitle'] = node['kicker'] d['_plotoutline'] = node['kicker'] d['plot'] = node['kicker'] if node['shortDescription'] != None: d['_plotoutline'] = node['shortDescription'] d['plot'] = node['shortDescription'] if node['description'] != None: d['plot'] = node['description'] try: d['thumb'] = node['defaultTeaserImage']['imageFiles']['edges'][0][ 'node']['publicLocation'] except: pass #libMediathek.log(d['thumb']) d['_type'] = 'dir' d['id'] = node['id'] d['mode'] = 'libBrListEpisodes' l.append(d) return l
def parseVideos(url): response = libMediathek.getUrl(url) s = response.split('<div class="pagepadding">') s2 = s[-1].split('<div class="pagination">') #videos = re.compile('<div class="modulepadding">.+?<img src="(.+?)".+?<span class="icon icon_video"></span>(.+?)<.+?<a href="(.+?)".+?>(.+?)</a>.+?<p>(.+?)<', re.DOTALL).findall(s2[0]) videos = re.compile( '<div class="modulepadding">.+?<img src="(.+?)".+?<span class="icon "></span>(.+?)<.+?<a href="(.+?)".+?>(.+?)</a>.+?<p>(.+?)<', re.DOTALL).findall(s2[0]) l = [] for thumb, duration, url, name, plot in videos: d = {} libMediathek.log(duration) MM, SS = duration.split(' ')[0].split(':') d['_duration'] = str(int(MM) * 60 + int(SS)) d['id'] = url.replace('.html', '').split(',')[-1] d['_name'] = name d['_thumb'] = baseUrl + thumb.replace('-einspaltig.jpg', '-zweispaltig.jpg') d['_plot'] = plot d['_type'] = 'video' d['mode'] = 'libNdrPlay' l.append(d) if len(s2) > 1 and '<a title="weiter" href="' in s2[1]: d = {} d['url'] = baseUrl + re.compile('<a title="weiter" href="(.+?)"', re.DOTALL).findall(s2[1])[0] d['_type'] = 'nextPage' d['mode'] = 'libNdrListVideos' l.append(d) return l
def _parseVideo(j): libMediathek.log(str(j)) d = {} d['_name'] = j['attributes']['title'] d['_thumb'] = j['attributes']['image']['url'] if 'text' in j['attributes']: d['_plot'] = _cleanPlot(j['attributes']['text']) while '\n\n\n' in d['_plot']: d['_plot'] = d['_plot'].replace('\n\n\n', '\n\n') d['_duration'] = str(j['attributes']['duration']) if 'season' in j['attributes']: d['_season'] = j['attributes']['season'] if 'episode' in j['attributes']: d['_episode'] = j['attributes']['episode'] if 'fsk' in j['attributes']: d['_mpaa'] = 'FSK ' + j['attributes']['fsk'] d['_airedISO8601'] = j['attributes']['createdAt'] d['url'] = 'https://cdnapisec.kaltura.com/p/1985051/sp/198505100/playManifest/entryId/' + j[ 'attributes'][ 'rootEntryId'] + '/flavorIds/0/format/applehttp/protocol/https/a.m3u8' #d['url'] += '?referrer=aHR0cHM6Ly93d3cuZnVuay5uZXQ=' d['entryId'] = j['attributes']['rootEntryId'] d['mode'] = 'play' d['_type'] = 'video' return d
def parseNew(boardId='l:http://ard.de/ontologies/mangoLayout#mainBoard_web', itemCount=50): #variables = {'boardId':boardId,"itemCount":itemCount} variables = {'boardId': boardId} #p = json.dumps({'query': libbrgraphqlqueries.getStart(), 'variables':variables}) p = json.dumps({'query': queries.getQueryBoard(), 'variables': variables}) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for edge in j['data']['viewer']['board']['sections']['edges'][1]['node'][ 'contents']['edges']: node = edge['node']['represents'] if node: d = {} d['name'] = node['title'] if node['kicker'] != None: d['_tvshowtitle'] = node['kicker'] d['_plotoutline'] = node['kicker'] d['plot'] = node['kicker'] if node['shortDescription'] != None: d['_plotoutline'] = node['shortDescription'] d['plot'] = node['shortDescription'] if node['description'] != None: d['plot'] = node['description'] d['_duration'] = str(node['duration']) d['thumb'] = node['defaultTeaserImage']['imageFiles']['edges'][0][ 'node']['publicLocation'] #libMediathek.log(d['thumb']) d['_type'] = 'video' d['id'] = node['id'] d['mode'] = 'libBrPlay' l.append(d) return l
def getSearch(a): libMediathek.log(a) urlargs = json.loads(a) i = 0 args = '' for arg in urlargs: if i == 0: args += '?' else: args += '&' args += arg + '=' + urlargs[arg] i += 1 url = 'https://www.sr-mediathek.de/API/suche.json.js.php'+args response = libMediathek.getUrl(url) j = json.loads(response) l = [] for item in j: d = {} d['name'] = item['ueberschrift'] d['plot'] = item['teasertext'] d['id'] = item['id'] if 'playtime_hh' in item: d['_duration'] = str(int(item['playtime_hh']) * 3600 + int(item['playtime_mm']) * 60 + int(item['playtime_ss'])) d['thumb'] = item['bild'] if 'start' in item: d['_aired'] = item['start'][:4] + '-' + item['start'][4:6] + '-' + item['start'][6:8] d['_airedtime'] = item['start'][8:10] + ':' + item['start'][10:12] d['mode'] = 'libSrPlay' d['_type'] = 'video' l.append(d) return l
def parseVideos(url, ty=False, grepShowFromVideo=False): if grepShowFromVideo: response = libMediathek.getUrl(url) url = re.compile('<link rel="alternate".+?href="(.+?)"').findall( response)[0] url = base + url.replace('.feed', '~_variant-android.mobile') response = libMediathek.getUrl(url) items = re.compile('<item>(.+?)</item>', re.DOTALL).findall(response) l = [] for item in items: d = {} dctype = re.compile('<dc:type>(.+?)</dc:type>', re.DOTALL).findall(item)[0] if 'Video' in dctype: # or (dctype == 'Sportnachricht - sportschau.de' and '<title>' in item): d['_name'] = re.compile('<title>(.+?)</title>', re.DOTALL).findall(item)[0] d['url'] = re.compile('<link>(.+?)</link>', re.DOTALL).findall(item)[0] mediagroup = re.compile('<media:group>(.+?)</media:group>', re.DOTALL).findall(item)[0] try: d['_duration'], d['m3u8'] = re.compile( '<media:content duration="(.+?)".+?url="(.+?)"', re.DOTALL).findall(mediagroup)[0] except: libMediathek.log(item) d['_name'] = '##################' + re.compile( '<title>(.+?)</title>', re.DOTALL).findall(item)[0] if '<content:encoded>' in item: d['_plot'] = re.compile( '<content:encoded>(.+?)</content:encoded>', re.DOTALL).findall(item)[0].replace('\n ', '\n') d['_channel'] = re.compile('<dc:creator>(.+?)</dc:creator>', re.DOTALL).findall(item)[0] d['_tvshowtitle'] = re.compile('<mp:topline>(.+?)</mp:topline>', re.DOTALL).findall(item)[0] if '<mp:expires>' in item: d['_ttl'] = re.compile('<mp:expires>(.+?)</mp:expires>', re.DOTALL).findall(item)[0] d['_thumb'] = _chooseThumb( re.compile('<mp:image>(.+?)</mp:image>', re.DOTALL).findall(item)) dcdate = re.compile('<dc:date>(.+?)</dc:date>', re.DOTALL).findall(item)[0] #TODO s = dcdate.split('T') d['_aired'] = s[0] t = s[1].replace('Z', '').split(':') d['_airedtime'] = str(int(t[0]) + 2) + ':' + t[1] d['sort'] = s[1].replace('Z', '').replace(':', '') if len(d['_airedtime']) == 4: d['_airedtime'] = '0' + d['_airedtime'] if ty: d['_type'] = ty else: d['_type'] = 'video' d['mode'] = 'libWdrPlay' l.append(d) return l
def parseVideos(id, type=None, grepShowFromVideo=False): if grepShowFromVideo: url = 'http://www1.wdr.de/Medien/mediathek/video/sendungen-a-z/' + id + '~_variant-android.rss' response = libMediathek.getUrl(url) url = re.compile('<link>(.+?)</link>').findall(response)[0] else: url = 'http://www1.wdr.de/' + id + '~_variant-android.mobile' response = libMediathek.getUrl(url) items = re.compile('<item>(.+?)</item>', re.DOTALL).findall(response) l = [] for item in items: d = {} dctype = re.compile('<dc:type>(.+?)</dc:type>', re.DOTALL).findall(item)[0] if 'Video' in dctype: # or (dctype == 'Sportnachricht - sportschau.de' and '<title>' in item): d['name'] = re.compile('<title>(.+?)</title>', re.DOTALL).findall(item)[0] d['url'] = re.compile('<link>(.+?)</link>', re.DOTALL).findall(item)[0] mediagroup = re.compile('<media:group>(.+?)</media:group>', re.DOTALL).findall(item)[0] try: d['_duration'], d['m3u8'] = re.compile( '<media:content duration="(.+?)".+?url="(.+?)"', re.DOTALL).findall(mediagroup)[0] except: libMediathek.log(item) d['name'] = '##################' + re.compile( '<title>(.+?)</title>', re.DOTALL).findall(item)[0] if '<content:encoded>' in item: d['plot'] = re.compile( '<content:encoded>(.+?)</content:encoded>', re.DOTALL).findall(item)[0].replace('\n ', '\n') d['_channel'] = re.compile('<dc:creator>(.+?)</dc:creator>', re.DOTALL).findall(item)[0] d['_tvshowtitle'] = re.compile('<mp:topline>(.+?)</mp:topline>', re.DOTALL).findall(item)[0] if '<mp:expires>' in item: d['_ttl'] = re.compile('<mp:expires>(.+?)</mp:expires>', re.DOTALL).findall(item)[0] d['thumb'] = _chooseThumb( re.compile('<mp:image>(.+?)</mp:image>', re.DOTALL).findall(item)) dcdate = re.compile('<dc:date>(.+?)</dc:date>', re.DOTALL).findall(item)[0] #TODO d['_airedISO8601'] = dcdate if type: d['_type'] = type else: d['_type'] = 'date' d['mode'] = 'libWdrPlay' l.append(d) l.sort(key=lambda x: x.get('_airedISO8601', None), reverse=(type != 'date')) return l
def getVideoUrl(entryId): url = base url += '&apiVersion=' + apiVersion url += '&expiry=' + expiry url += '&clientTag=' + clientTag url += '&format=' + format url += '&ignoreNull=' + ignoreNull url += '&action=' + action n = '1' url += '&' + n + ':service=' + one_service url += '&' + n + ':action=' + one_action url += '&' + n + ':widgetId=' + one_widgetId n = '2' url += '&' + n + ':ks=%7B1%3Aresult%3Aks%7D' #url += '&'+n+':contextDataParams:referrer=http%3A%2F%2Fplayer.kaltura.com%2FkWidget%2Ftests%2FkWidget.getSources.html%23__1985051%2C' + entryId url += '&' + n + ':contextDataParams:referrer=https%3a%2f%2fwww.funk.net' url += '&' + n + ':contextDataParams:objectType=KalturaEntryContextDataParams' url += '&' + n + ':contextDataParams:flavorTags=all' url += '&' + n + ':service=baseentry' url += '&' + n + ':entryId=' + entryId url += '&' + n + ':action=getContextData' n = '3' url += '&' + n + ':action=list' url += '&' + n + ':filter:entryIdEqual=' + entryId url += '&' + n + ':filter:objectType=KalturaAssetFilter' url += '&' + n + ':filter:statusEqual=2' url += '&' + n + ':ks=%7B1%3Aresult%3Aks%7D' url += '&' + n + ':pager:pageSize=50' url += '&' + n + ':service=caption_captionasset' #url += '&kalsig=' + kalsig response = libMediathek.getUrl(url) libMediathek.log(response) j = json.loads(response) d = {} flavorIds = '' for flavorAsset in j[1]['flavorAssets']: flavorIds += flavorAsset['id'] + ',' videoUrl = 'https://cdnapisec.kaltura.com/p/1985051/sp/198505100/playManifest/entryId/' + entryId + '/flavorIds/' + flavorIds[: -1] + '/format/applehttp/protocol/https/a.m3u8' videoUrl += '?referrer=aHR0cHM6Ly93d3cuZnVuay5uZXQ=' d['media'] = [] d['media'].append({'url': videoUrl, 'type': 'HLS'}) for object in j[2]['objects']: d['subtitle'] = [] lang = object['languageCode'] subUrl = 'https://cdnsecakmi.kaltura.com/api_v3/index.php/service/caption_captionAsset/action/serve/captionAssetId/' + object[ 'id'] d['subtitle'].append({'url': subUrl, 'type': 'srt', 'lang': lang}) return d
def parseSeries(): p = json.dumps({'query': queries.getQuerySeries()}) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for edge in j['data']['viewer']['allSeries']['edges']: if edge['node']: l.append( _buildVideoDict(edge['node'], type='dir', mode='libBrListEpisodes')) return l
def headUrl(url): #TODO: move to libmediathek3 libMediathek.log(url) import urllib2 req = urllib2.Request(url) req.get_method = lambda: 'HEAD' req.add_header( 'User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0') response = urllib2.urlopen(req) info = response.info() response.close() return info
def _parseAllClips(filter): variables = {'filter': filter} p = json.dumps({ 'query': queries.getQueryAllClips(), 'variables': variables }) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for edge in j['data']['viewer']['allClips']['edges']: d = _buildVideoDict(edge['node']) l.append(d) return l
def parseSection(id): variables = {'id': id} p = json.dumps({ 'query': queries.getQuerySection(), 'variables': variables }) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for edge in j['data']['viewer']['section']['contents']['edges']: d = _buildVideoDict(edge['node']['represents']) l.append(d) return l
def getSearch(s): #url = 'http://www.daserste.de/dasersteapp/app/index~program_pd-'+day+'.json' url = 'http://www.daserste.de/dasersteapp/index~search_documentTypes-video_s-broadcastDate_dir-desc_f-dateRange_fk-1YEAR%7C14DAYS_searchText-' + urllib.quote_plus( s) + '.json' response = libMediathek.getUrl(url) libMediathek.log(response) j = json.loads(response) l = [] for r in j['result']: if r.has_key('entries'): for entry in r['entries']: d = _parseVideo(entry) l.append(d) libMediathek.log(str(d)) return l
def parseNew(boardId='l:http://ard.de/ontologies/mangoLayout#mainBoard_web', itemCount=50): #variables = {'boardId':boardId,"itemCount":itemCount} variables = {'boardId': boardId} #p = json.dumps({'query': libbrgraphqlqueries.getStart(), 'variables':variables}) p = json.dumps({'query': queries.getQueryBoard(), 'variables': variables}) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for edge in j['data']['viewer']['board']['sections']['edges'][1]['node'][ 'contents']['edges']: if edge['node']['represents']: l.append(_buildVideoDict(edge['node']['represents'])) return l
def parsePage(url): response = getU(url,True) j = json.loads(response) if j['profile'] == 'http://zdf.de/rels/search/result': return _parseSearch(j) elif j['profile'] == 'http://zdf.de/rels/search/result-page': return _parseSearchPage(j) elif j['profile'] == 'http://zdf.de/rels/content/page-index': return _parsePageIndex(j) elif j['profile'] == 'http://zdf.de/rels/content/page-index-teaser': return _parseTeaser(j) elif j['profile'] == 'http://zdf.de/rels/cmdm/resultpage-broadcasts': return _parseBroadcast(j) else: libMediathek.log('Unknown profile: ' + j['profile'])
def parse(url): response = libMediathek.getUrl(url, header) j = json.loads(response) l = [] if 'includes' in j: part = 'includes' else: part = 'data' for item in j[part]: if item['type'] == 'series' or item['type'] == 'format': l.append(_parseSeries(item, item['type'])) elif item['type'] == 'video': l.append(_parseVideo(item)) else: libMediathek.log('unkown type: ' + item['type']) return l
def _parseBroadcast(j): l = [] for broadcast in j['http://zdf.de/rels/cmdm/broadcasts']: if 'http://zdf.de/rels/content/video-page-teaser' in broadcast: target = broadcast['http://zdf.de/rels/content/video-page-teaser'] d = _grepItem(target) if d: #d['airedISO8601'] = broadcast['airtimeBegin'] if broadcast[ 'effectiveAirtimeBegin'] != None: #TODO: find alternative for videos without this field d['_airedISO8601'] = broadcast['effectiveAirtimeBegin'] else: libMediathek.log('ommiting date: ' + str(broadcast)) libMediathek.log(str(broadcast['livestream'])) d['_type'] = 'date' l.append(d) return l
def parse(url): response = libMediathek.getUrl(url,header) j = json.loads(response) l = [] if 'includes' in j: part = 'includes' else: part = 'data' for item in j[part]: if item['type'] == 'series' or item['type'] == 'format': d = _parseSeries(item,types[item['type']]) if d: l.append(d) elif item['type'] == 'video': l.append(_parseVideo(item)) else: libMediathek.log('unkown type: '+item['type']) return l
def parsePage(url): if url.startswith('https://api.zdf.de/search/documents'): #response = libMediathek.getUrl(url,headerMenu) response = getU(url, True) else: #response = libMediathek.getUrl(url,headerMenu) response = getU(url, True) j = json.loads(response) libMediathek.log(response) if j['profile'] == 'http://zdf.de/rels/search/result': return _parseSearch(j) elif j['profile'] == 'http://zdf.de/rels/search/result-page': return _parseSearchPage(j) elif j['profile'] == 'http://zdf.de/rels/content/page-index': return _parsePageIndex(j) elif j['profile'] == 'http://zdf.de/rels/content/page-index-teaser': return _parseTeaser(j) elif j['profile'] == 'http://zdf.de/rels/cmdm/resultpage-broadcasts': return _parseBroadcast(j) else: log('Unknown profile: ' + j['profile'])
def parseDate(day, channel): variables = { "slots": ["MORNING", "NOON", "EVENING", "NIGHT"], "day": day, "broadcasterId": "av:http://ard.de/ontologies/ard#" + channel } p = json.dumps({'query': queries.getQueryDate(), 'variables': variables}) libMediathek.log(p) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for epg in j['data']['viewer']['allLivestreams']['edges'][0]['node'][ 'epg']: broadcastEvent = epg['broadcastEvent'] publicationOf = broadcastEvent['publicationOf'] if len(publicationOf['essences']['edges']) != 0: d = _buildVideoDict(publicationOf) d['_airedISO8601'] = broadcastEvent['start'] d['_type'] = 'date' l.append(d) return l
def parseBoards(): boards = [ 'Board:http://ard.de/ontologies/mangoLayout#entdecken-film-krimi', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-kabarett-comedy', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-doku-reportage', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-news-politik', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-natur-tiere', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-wissen', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-berge', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-kultur', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-heimat', 'Board:http://ard.de/ontologies/mangoLayout#discover2', 'Board:http://ard.de/ontologies/mangoLayout#discover1', 'Board:http://ard.de/ontologies/mangoLayout#entdecken-kinder', ] variables = {'nodes': boards} p = json.dumps({ 'query': libbrgraphqlqueries.getCats(), 'variables': variables }) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response) j = json.loads(response) l = [] for node in j['data']['nodes']: d = {} d['name'] = node['title'].title() if 'shortDescription' in node and node['shortDescription'] != None: d['_plotoutline'] = node['shortDescription'] d['plot'] = node['shortDescription'] if 'description' in node and node['description'] != None: d['plot'] = node['description'] d['boardId'] = node['id'] d['_type'] = 'dir' d['mode'] = 'libBrListBoard' l.append(d) return l
def enrichEpg(l, date): epg = [] newL = [] response = libMediathek.getUrl( 'https://www.3sat.de/programm/?viewlong=viewlong&d=20170521') response = response.split('<div id="EpgLongView" class="EpgBody">')[1] response = response.split('<div id="FlagEpg" class="FlagLoaded">')[0] response = response.split('class="EpgItemDay"')[1:] for item in response: time = re.compile('<div class="EpgTimeDay">(.+?)<', re.DOTALL).findall(item)[0] if 'class="EpgTextL"' in item: plotS = re.compile('class="EpgTextS">.+?</a>(.+?)</div>', re.DOTALL).findall(item)[0] plotL = re.compile('class="EpgTextL">.+?</a>(.+?)</div>', re.DOTALL).findall(item)[0] else: plotS = re.compile('<h4.+?>(.+?)</h4>', re.DOTALL).findall(item)[0] plotL = plotS plotS = plotS.replace('<br/><br/><br/>', ' ').replace('<br/><br/>', ' ').replace('<br/>', ' ') plotL = plotL.replace('<br/><br/><br/>', '\n\n').replace('<br/><br/>', '\n\n').replace('<br/>', '\n') libMediathek.log(plotS) epg.append([time, plotL, plotS]) libMediathek.log(str(epg)) for item in l: libMediathek.log('###' + item['_plot']) d = item for epgTime, epgPlot, epgPlotShorted in epg: if item['_plot'][:-5] in epgPlotShorted: d['_plot'] = '###' + epgPlot if item['_date'] == '23:59': d['_date'] = epgTime newL.append(d) return newL
def getXML(url, modePrefix, forcedType=False, channel=False): baseUrl = url.split('/xmlservice')[0] l = [] response = libMediathek.getUrl(url) if not '<teasers>' in response: return l teasers = re.compile('<teasers>(.+?)</teasers>', re.DOTALL).findall(response)[0] match_teaser = re.compile('<teaser(.+?)</teaser>', re.DOTALL).findall(teasers) for teaser in match_teaser: d = {} #match_member=re.compile('member="(.+?)"', re.DOTALL).findall(teaser) type = re.compile('<type>(.+?)</type>', re.DOTALL).findall(teaser)[0] if type == 'video': d['_thumb'] = chooseThumb( re.compile('<teaserimages>(.+?)</teaserimages>', re.DOTALL).findall(teaser)[0]) else: d['_thumb'] = chooseThumb( re.compile('<teaserimages>(.+?)</teaserimages>', re.DOTALL).findall(teaser)[0], -1) d.update( getInfo( re.compile('<information>(.+?)</information>', re.DOTALL).findall(teaser)[0])) d.update( getDetails( re.compile('<details>(.+?)</details>', re.DOTALL).findall(teaser)[0])) #title = cleanTitle(title) if type == 'sendung': if d['_duration'] == '0': libMediathek.log('No videos in: ' + type) else: d['url'] = baseUrl + '/xmlservice/web/aktuellste?maxLength=50&id=' + d[ '_assetId'] d['_fanart'] = d['_thumb'] d['mode'] = 'xmlListPage' if modePrefix: d['mode'] = modePrefix + 'XmlListPage' if channel: d['_channel'] = channel d['_type'] = 'shows' l.append(d) elif type == 'video': d['url'] = baseUrl + '/xmlservice/web/beitragsDetails?id=' + d[ '_assetId'] d['mode'] = 'xmlPlay' if modePrefix: d['mode'] = modePrefix + 'XmlPlay' if forcedType: d['_type'] = forcedType else: d['_type'] = 'video' HH, MM = d['_airtime'].split(' ')[-1].split(':') d['_date'] = HH + ':' + MM d['_time'] = str(int(HH) * 60 + int(MM)) if channel: d['_channel'] = channel l.append(d) elif type == 'rubrik' or type == 'thema': d['url'] = baseUrl + '/xmlservice/web/aktuellste?maxLength=50&id=' + d[ '_assetId'] d['mode'] = 'xmlListPage' if modePrefix: d['mode'] = modePrefix + 'XmlListPage' if channel: d['_channel'] = channel d['_type'] = 'dir' l.append(d) else: libMediathek.log('unsupported item type "' + type + '"') nextPageUrl = _checkIfNextPageExists(url, response) if nextPageUrl: d = {} d['url'] = nextPageUrl d['_type'] = 'nextPage' d['mode'] = 'xmlListPage' l.append(d) return l
def getIntrospection(): p = json.dumps({'query': libbrgraphqlqueries.getIntrospectionQuery()}) response = libMediathek.getUrl(graphqlUrl, header, post=p) libMediathek.log(response)
def libDasErstePlay(): vid = libDasErsteJsonParser.getVideo(params['url']) libMediathek.log(str(vid)) return vid
def _grepItem(target): if target['profile'] == 'http://zdf.de/rels/not-found': return False if not ('contentType' in target): return False d = {} d['name'] = target['teaserHeadline'] d['plot'] = target['teasertext'] d['thumb'] = _chooseImage(target['teaserImageRef']) #d['url'] = base + target['http://zdf.de/rels/brand']['http://zdf.de/rels/target']['canonical'] if target['contentType'] == 'brand' or target['contentType'] == 'category': try: #d['url'] = base + target['canonical'] d['url'] = base + target['http://zdf.de/rels/search/page-video-counter-with-video']['self'].replace('&limit=0','&limit=100') d['_type'] = 'dir' d['mode'] = 'libZdfListPage' except: d = False elif target['contentType'] == 'clip': try: d['url'] = base + target['mainVideoContent']['http://zdf.de/rels/target']['http://zdf.de/rels/streams/ptmd-template'].replace('{playerId}',playerId) if 'duration' in target['mainVideoContent']['http://zdf.de/rels/target']: d['_duration'] = str(target['mainVideoContent']['http://zdf.de/rels/target']['duration']) d['_type'] = 'clip' #d['_type'] = 'video' d['mode'] = 'libZdfPlay' except: d = False elif target['contentType'] == 'episode':# or target['contentType'] == 'clip': try: if not target['hasVideo']: return False #if target['mainVideoContent']['http://zdf.de/rels/target']['showCaption']: # d['suburl'] = base + target['mainVideoContent']['http://zdf.de/rels/target']['captionUrl'] if 'mainVideoContent' in target: content = target['mainVideoContent']['http://zdf.de/rels/target'] elif 'mainContent' in target: content = target['mainContent'][0]['videoContent'][0]['http://zdf.de/rels/target'] d['url'] = base + content['http://zdf.de/rels/streams/ptmd-template'].replace('{playerId}',playerId) if 'duration' in content: d['_duration'] = str(content['duration']) d['_type'] = 'video' d['mode'] = 'libZdfPlay' programmeItem = target.get('programmeItem', None) if isinstance(programmeItem, list) and len(programmeItem) > 0: episode = programmeItem[0].get('http://zdf.de/rels/target', None) if episode: episodeNumber = episode.get('episodeNumber', None) if episodeNumber: ep_nr = str(episodeNumber) if len(ep_nr) == 1: ep_nr = ' ' + ep_nr d['name'] = 'Folge ' + ep_nr + ' - ' + d['name'] season = episode.get('http://zdf.de/rels/cmdm/season', None) if season: seasonTitle = season.get('seasonTitle', None) if seasonTitle: d['name'] = str(seasonTitle) + ' - ' + d['name'] series = season.get('http://zdf.de/rels/cmdm/series',None) if series: brand = series.get('http://zdf.de/rels/cmdm/brand',None) if brand: brandName = brand.get('brandName', None) if brandName: d['name'] = brandName + ' - ' + d['name'] else: brand = target.get('http://zdf.de/rels/brand',None) if brand: title = brand.get('title',None) if title: d['name'] = title + ' - ' + d['name'] except: d = False else: libMediathek.log('Unknown target type: ' + target['contentType']) d = False return d
def parseVideos(url): l = [] response = libMediathek.getUrl(url) j = json.loads(response) #j1 = j["sections"][-1]["modCons"][-1]["mods"][-1] #j1 = j["sections"][-1]["modCons"][-1]["mods"][-1] j1 = j["sections"][-1]["modCons"][-1]["mods"][-1] for j2 in j1["inhalte"]: d = {} if "ueberschrift" in j2: d["_name"] = j2["ueberschrift"].encode("utf-8") if 'Hörfassung' in d["_name"] or 'Audiodeskription' in d["_name"]: d["_name"] = d["_name"].replace(' - Hörfassung','').replace(' - Audiodeskription','') d["_name"] = d["_name"].replace(' (mit Hörfassung)','').replace(' (mit Audiodeskription)','') d["_name"] = d["_name"].replace(' mit Hörfassung','').replace(' mit Audiodeskription','') d["_name"] = d["_name"].replace(' (Hörfassung)','').replace(' (Audiodeskription)','') d["_name"] = d["_name"].replace(' Hörfassung','').replace(' Audiodeskription','') d["_name"] = d["_name"].replace('Hörfassung','').replace('Audiodeskription','') d["_name"] = d["_name"].strip() if d["_name"].endswith(' -'): d["_name"] = d["_name"][:-2] d["_name"] = d["_name"] + ' - Hörfassung' d["_audioDesc"] = True if "unterzeile" in j2: d["_duration"] = str(runtimeToInt(j2["unterzeile"])) if "bilder" in j2: d["_thumb"] = j2["bilder"][0]["schemaUrl"].replace("##width##","384").encode("utf-8") if "teaserTyp" in j2: if j2["teaserTyp"] == "PermanentLivestreamClip" or j2["teaserTyp"] == "PodcastClip": continue elif j2["teaserTyp"] == "OnDemandClip": d["_type"] = 'video' d['mode'] = 'libArdPlay' elif j2["teaserTyp"] == "Sammlung": d["_type"] = 'dir' d['mode'] = 'libArdListVideos' else: libMediathek.log('json parser: unknown item type: ' + j2["teaserTyp"]) d["_type"] = 'dir' d['mode'] = 'libArdListVideos' if "link" in j2: d["url"] = j2["link"]["url"].encode("utf-8") d["documentId"] = j2["link"]["url"].split("/player/")[-1].split("?")[0].encode("utf-8") if "dachzeile" in j2: d["_releasedate"] = j2["dachzeile"].encode("utf-8") if 'ut' in j2['kennzeichen']: d["_subtitle"] = True if 'geo' in j2['kennzeichen']: d['_geo'] = 'DACH' if 'fsk6' in j2['kennzeichen']: d['_mpaa'] = 'FSK6' if 'fsk12' in j2['kennzeichen']: d['_mpaa'] = 'FSK12' if 'fsk16' in j2['kennzeichen']: d['_mpaa'] = 'FSK16' if 'fsk18' in j2['kennzeichen']: d['_mpaa'] = 'FSK18' #d["_pluginpath"] = pluginpath l.append(d) aktiv = False for buttons in j1['buttons']: if buttons["label"]["text"] == "Seiten": for button in buttons["buttons"]: if aktiv: d = {} d["url"] = button["buttonLink"]["url"] d["type"] = 'nextPage' d['mode'] = 'libArdListVideos' l.append(d) aktiv = button['aktiv'] return l
def parseVideos(url): l = [] response = libMediathek.getUrl(url) j = json.loads(response) #j1 = j["sections"][-1]["modCons"][-1]["mods"][-1] #j1 = j["sections"][-1]["modCons"][-1]["mods"][-1] j1 = j["sections"][-1]["modCons"][-1]["mods"][-1] for j2 in j1["inhalte"]: d = {} if "ueberschrift" in j2: ueberschrift = j2["ueberschrift"] if sys.version_info[0] < 3: # for Python 2 ueberschrift = ueberschrift.encode('utf-8') d["name"] = ueberschrift try: d["plot"] = htmlParser.unescape(ueberschrift) except UnicodeDecodeError: d["plot"] = ueberschrift if 'Hörfassung' in d["name"] or 'Audiodeskription' in d["name"]: d["name"] = d["name"].replace(' - Hörfassung', '').replace( ' - Audiodeskription', '') d["name"] = d["name"].replace(' (mit Hörfassung)', '').replace( ' (mit Audiodeskription)', '') d["name"] = d["name"].replace(' mit Hörfassung', '').replace( ' mit Audiodeskription', '') d["name"] = d["name"].replace(' (Hörfassung)', '').replace( ' (Audiodeskription)', '') d["name"] = d["name"].replace(' Hörfassung', '').replace( ' Audiodeskription', '') d["name"] = d["name"].replace('Hörfassung', '').replace( 'Audiodeskription', '') d["name"] = d["name"].strip() if d["name"].endswith(' -'): d["name"] = d["name"][:-2] d["name"] = d["name"] + ' - Hörfassung' d["_audioDesc"] = True if "unterzeile" in j2: d["_duration"] = str(runtimeToInt(j2["unterzeile"])) if "bilder" in j2: thumb = j2["bilder"][0]["schemaUrl"].replace("##width##", "1024") thumb = thumb.split("?")[0] if sys.version_info[0] < 3: # for Python 2 thumb = thumb.encode('utf-8') d["thumb"] = thumb if "teaserTyp" in j2: if j2["teaserTyp"] == "PermanentLivestreamClip" or j2[ "teaserTyp"] == "PodcastClip": continue elif j2["teaserTyp"] == "OnDemandClip": d["_type"] = 'video' d['mode'] = 'libArdPlayClassic' elif j2["teaserTyp"] == "Sammlung": d["_type"] = 'dir' d['mode'] = 'libArdListVideos' else: libMediathek.log('json parser: unknown item type: ' + j2["teaserTyp"]) d["_type"] = 'dir' d['mode'] = 'libArdListVideos' if "link" in j2: url = j2["link"]["url"] documentId = j2["link"]["url"].split("/player/")[-1].split("?")[0] if sys.version_info[0] < 3: # for Python 2 url = url.encode('utf-8') documentId = documentId.encode('utf-8') d["url"] = url d["documentId"] = documentId if "dachzeile" in j2: dachzeile = j2["dachzeile"] if sys.version_info[0] < 3: # for Python 2 dachzeile = dachzeile.encode('utf-8') d["_releasedate"] = dachzeile if 'ut' in j2['kennzeichen']: d["_subtitle"] = True if 'geo' in j2['kennzeichen']: d['_geo'] = 'DACH' if 'fsk6' in j2['kennzeichen']: d['_mpaa'] = 'FSK6' if 'fsk12' in j2['kennzeichen']: d['_mpaa'] = 'FSK12' if 'fsk16' in j2['kennzeichen']: d['_mpaa'] = 'FSK16' if 'fsk18' in j2['kennzeichen']: d['_mpaa'] = 'FSK18' l.append(d) aktiv = False for buttons in j1['buttons']: if buttons["label"]["text"] == "Seiten": for button in buttons["buttons"]: if aktiv: d = {} d["url"] = button["buttonLink"]["url"] d["type"] = 'nextPage' d['mode'] = 'libArdListVideos' l.append(d) aktiv = button['aktiv'] return l