def getCollection(url): url = opa_url + url response = libMediathek.getUrl(url, opa_token) j = json.loads(response) program_id = j['programs'][0]['programId'] l = getVideos('/zones/collection_videos?id=' + program_id) children = j['programs'][0]['children'] topics = [item for item in children if (item['kind'] == 'TOPIC' or item['kind'] == 'TV_SERIES')] for topic in topics: subresponse = libMediathek.getUrl( opa_url + '/programs?programId=' + topic['programId'] + '&language=' + current_lang + '&fields=title,subtitle,fullDescription,shortDescription,mainImage.url', opa_token ) topic_json = json.loads(subresponse) program = topic_json['programs'][0] if program['title'] in ('**', '', None): break d = {} d['name'] = program['title'] if program['subtitle'] != None: d['name'] = d['name'] + ' | ' + program['subtitle'] if program['fullDescription']: d['plot'] = program['fullDescription'] elif program['shortDescription']: d['plot'] = program['shortDescription'] d['thumb'] = program['mainImage']['url'] d['_type'] = 'dir' d['mode'] = 'libArteListVideos' d['url'] = '/zones/collection_subcollection?id=' + topic['programId'] l.append(d) return l
def parseShows(letter): j = _parseMain() url = j["_links"]["broadcastSeriesAz"]["href"] response = libMediathek.getUrl(url) j = json.loads(response) if not letter.lower() in j['az']['_links']: return [] url = j['az']['_links'][letter.lower()]['href'] response = libMediathek.getUrl(url) j = json.loads(response) l = [] for show in j["_embedded"]["teasers"]: d = {} d['url'] = show["_links"]["self"]["href"] d['_name'] = show["headline"] d['_mediathek'] = 'BR' d['_tvshowtitle'] = show["topline"] if 'br-core:teaserText' in show["documentProperties"]: d['_plot'] = show["documentProperties"]["br-core:teaserText"] try: d['_thumb'] = show['teaserImage']['_links']['original']['href'] except: pass d['_type'] = 'shows' d['mode'] = 'libBrListVideos' 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 parseDate(day='0'): response = libMediathek.getUrl('http://www.mdr.de/mediathek/fernsehen/index.html') url = base + re.compile('<div class="box cssBroadcastDay.+?href="(.+?)"', re.DOTALL).findall(response)[int(day)] #url = 'http://www.mdr.de/mediathek/fernsehen/sendung-verpasst--100_date-20161004_inheritancecontext-header_numberofelements-1_zc-65ef7e36.html' response = libMediathek.getUrl(url) response = response.split('<div class="con">')[-1] videos = response.split('<div data-id=')[1:] l = [] for video in videos: d = {} if "mediathekUrl':''" in video: pass d['url'] = base + re.compile('href="(.+?)"', re.DOTALL).findall(video)[0].split('_')[0] + '-meta.xml' d['_thumb'] = base + re.compile('src="(.+?)"', re.DOTALL).findall(video)[1] d['_plot'] = re.compile('<a.+?>(.+?)<', re.DOTALL).findall(video)[2] d['_airedtime'] = re.compile('<span class="startTime">(.+?)</span>', re.DOTALL).findall(video)[0] sHH,sMM = d['_airedtime'].split(':') eHH,eMM = re.compile('<span class="endTime">(.+?)</span>', re.DOTALL).findall(video)[0].split(':') d['_duration'] = str((int(eHH) - int(sHH)) * 3600 + (int(eMM) - int(sMM)) * 60) d['_name'] = re.compile('<a.+?>(.+?)<', re.DOTALL).findall(video)[1] d['mode'] = 'libMdrPlay' d['_type'] = 'date' l.append(d) return l
def getCollection(url): response = libMediathek.getUrl(url, opa_token) j = json.loads(response) program_id = j['programs'][0]['programId'] topic_children = filter(lambda item: item['kind'] == 'TOPIC', j['programs'][0]['children']) if topic_children: l = [{'_name': 'Übersicht', '_type': 'dir', 'mode': 'libArteListListings', 'url': emac_url + '/zones/collection_videos?id=' + program_id}] else: return getListings(emac_url + '/zones/collection_videos?id=' + program_id) for child in topic_children: subresponse = libMediathek.getUrl(opa_url + '/programs?programId=' + child['programId'] + '&language=' + language + '&fields=title,subtitle,fullDescription,shortDescription,mainImage.url', headers=opa_token) child_json = json.loads(subresponse) program = child_json['programs'][0] d = {} if program['subtitle'] != None and program['title'] != None: d['_name'] = program['title'] + ' | ' + program['subtitle'] elif program['subtitle'] != None: d['_name'] = program['subtitle'] else: d['_name'] = program['title'] if program['fullDescription']: d['_plot'] = program['fullDescription'] elif program['shortDescription']: d['_plot'] = program['shortDescription'] d['_thumb'] = program['mainImage']['url'] d['_type'] = 'dir' d['mode'] = 'libArteListListings' d['url'] = emac_url + '/zones/collection_subcollection?id=' + program_id + '_' + child['programId'] 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 getU(url,Menu=False): try: header = getHeader(Menu) response = libMediathek.getUrl(url,header) except: (tokenMenu, tokenPlayer) = libzdftokengrabber.grepToken() header = getHeader(Menu, tokenMenu, tokenPlayer) response = libMediathek.getUrl(url,header) return response
def getVideoUrl(url, documentId): result = None url = opa_url + url response = libMediathek.getUrl(url, opa_token) j = json.loads(response) if len(j['videoStreams']) > 0: storedLang = 0 bitrate = 0 hls_videos = [value for value in j['videoStreams'] if value['mediaType'] == 'hls'] for video in hls_videos: voice_subtitle = video['audioCode'].split('-'); voice = voice_subtitle[0].split('[')[0] subtitle = voice_subtitle[1].split('[')[0] if len(voice_subtitle) > 1 else ''; currentLang = voices.get(voice, lambda:0)() # if currentLang is native language => prefer "no subtitle" # if currentLang is foreign language => prefer subtitle in native language currentLang = currentLang * 10 + subtitles.get(subtitle, lambda: 9 if (currentLang >= voices[nativeVoice]()) else 0)() currentBitrate = video['bitrate'] if currentLang > storedLang or (currentLang == storedLang and currentBitrate > bitrate): storedLang = currentLang bitrate = currentBitrate result = {'url':video['url'], 'type': 'video', 'stream':'hls'} return {'media': [result]} if result else None else: url = 'https://api.arte.tv/api/player/v2/config/' + current_lang + '/' + documentId response = libMediathek.getUrl(url) j = json.loads(response) storedLang = 0 bitrate = 0 hls_videos = [value for value in j['data']['attributes']['streams'] if value['protocol'][0:3] == 'HLS'] for video in hls_videos: if ('versions' in video) and len(video['versions']) > 0: voice_subtitle = video['versions'][0]['eStat']['ml5'].split('-'); voice = voice_subtitle[0].split('[')[0] subtitle = voice_subtitle[1].split('[')[0] if len(voice_subtitle) > 1 else ''; else: voice = '' subtitle = '' currentLang = voices.get(voice, lambda:0)() # if currentLang is native language => prefer "no subtitle" # if currentLang is foreign language => prefer subtitle in native language currentLang = currentLang * 10 + subtitles.get(subtitle, lambda: 9 if (currentLang >= voices[nativeVoice]()) else 0)() currentBitrate = qualities.get(video['mainQuality']['code'], 0) if currentLang > storedLang or (currentLang == storedLang and currentBitrate > bitrate): storedLang = currentLang bitrate = currentBitrate result = {'url':video['url'], 'type': 'video', 'stream':'hls'} return {'media': [result]} if result else None
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 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 parse(pageIndex, url, partnerKey=None, channelKey=None): result = [] response = libMediathek.getUrl(url) j = json.loads(response) data = j.get('data',None) if data: page = data.get(pageNames[pageIndex],None) if page: widgets = [page] if pageIndex == pageIndexShowPage else page.get('widgets',[]) for widget in widgets: if (channelKey is None) or (channelKey == widget.get('channelKey',None)): teasers = widget.get('teasers',None) if teasers: for teaser in teasers: type = teaser['type'] publicationService = teaser.get('publicationService',None) if ( type in ('live','ondemand','broadcastMainClip','show') and (type == 'live') == (pageIndex == pageIndexLivestreamPage) and ((partnerKey is None) or (publicationService and (partnerKey == publicationService.get('partner',None)))) ): documentId = deep_get(teaser, 'links.target.id') name = teaser['shortTitle'] if documentId and name: d = {} d['documentId'] = documentId d['name'] = name d['plot'] = teaser.get('longTitle',None) if (pageIndex == pageIndexProgramPage) and (partnerKey is None) and publicationService: d['name'] = d['name'] + ' | [COLOR blue]' + publicationService['name'] + '[/COLOR]' duration = teaser.get('duration', None) if duration: d['_duration'] = str(duration) thumb = deep_get(teaser, 'images.aspect16x9.src') if not thumb: thumb = deep_get(teaser, 'images.aspect1x1.src') if not thumb: thumb = deep_get(teaser, 'images.aspect16x7.src') if thumb: d['thumb'] = (thumb.split('?')[0]).replace('{width}','1024') if type == 'show': d['_type'] = 'dir' d['mode'] = 'libArdListShow' else: if pageIndex == pageIndexProgramPage: d['_airedISO8601'] = teaser.get('broadcastedOn', None) if pageIndex == pageIndexLivestreamPage: d['_type'] = 'live' elif pageIndex == pageIndexProgramPage: d['_type'] = 'date' else: d['_type'] = 'video' d['mode'] = 'libArdPlay' result.append(d) # "Alle Sender nach Datum" ist nicht sinnvoll vorsortiert if pageIndex == pageIndexProgramPage and partnerKey is None: result.sort(key = lambda x: x.get('_airedISO8601',None)) return result
def parseShows(url): response = libMediathek.getUrl(url) uls = re.compile('<ul class="list">(.+?)</ul>', re.DOTALL).findall(response) l = [] for ul in uls: lis = re.compile('<li >(.+?)</li>', re.DOTALL).findall(ul) for li in lis: d = {} uri = re.compile('href="(.+?)"', re.DOTALL).findall(li)[0] if uri != 'http://www.wdrmaus.de/': d['url'] = base + uri d['_name'] = re.compile('<span>(.+?)</span>', re.DOTALL).findall(li)[0] try: thumb = re.compile('<img.+?src="(.+?)"', re.DOTALL).findall(li)[0].replace( '~_v-ARDKleinerTeaser.jpg', '~_v-original.jpg').replace( 'http//www', 'http://www') if thumb.startswith('http'): d['_thumb'] = thumb else: d['_thumb'] = base + thumb except: pass d['_channel'] = 'WDR' d['_type'] = 'dir' d['mode'] = 'libWdrListVideos' l.append(d) return l
def parseVideos(url): response = libMediathek.getUrl(url) typeA = re.compile( '<div class="box".+?<a(.+?)>(.+?)</a>.+?<a(.+?)>(.+?)</a>', re.DOTALL).findall(response) l = [] for href, show, href2, stuff in typeA: if '<div class="media mediaA video">' in stuff: d = {} d['url'] = base + re.compile('href="(.+?)"', re.DOTALL).findall(href2)[0] if '<h4' in stuff: d['_name'] = re.compile( '<h4.+?>.+?<span class="hidden">Video:</span>(.+?)<', re.DOTALL).findall(stuff)[0].strip() else: d['_name'] = show.strip() if '<img' in stuff: d['_thumb'] = base + re.compile('<img.+?src="(.+?)"', re.DOTALL).findall(stuff)[0] d['_plot'] = re.compile('<p class="teasertext">(.+?)<', re.DOTALL).findall(stuff)[0] #TODO duration, ut d['_type'] = 'video' d['mode'] = 'libWdrPlay' l.append(d) return l
def parseLetter(pageIndex, url, letter): result = [] response = libMediathek.getUrl(url) j = json.loads(response) shows = deep_get(j, 'data.' + pageNames[pageIndex] + '.glossary.shows' + letter, []) for teaser in shows: type = teaser['type'] documentId = deep_get(teaser, 'links.target.id') name = teaser['shortTitle'] if type == 'show' and documentId and name: d = {} d['documentId'] = documentId d['name'] = name d['plot'] = teaser.get('longTitle',None) thumb = deep_get(teaser, 'images.aspect16x9.src') if not thumb: thumb = deep_get(teaser, 'images.aspect1x1.src') if not thumb: thumb = deep_get(teaser, 'images.aspect16x7.src') if thumb: d['thumb'] = (thumb.split('?')[0]).replace('{width}','1024') d['_type'] = 'dir' d['mode'] = 'libArdListShow' result.append(d) return result
def getVideo(url): d = {} response = libMediathek.getUrl(url) file = re.compile('media.push\("(.+?)"').findall(response)[0] if file.startswith('//'): file = 'http:' + file if file.endswith('.m3u8'): d['media'] = [{'url': file, 'type': 'video', 'stream': 'HLS'}] elif file.endswith('.m.mp4'): s = file.split('/') video = 'http://hls-ondemand.swr.de/i/swr-fernsehen/' + s[4] + '/' + s[ 5] + '/' + s[6] + '.,xl,l,ml,m,sm,s,.mp4.csmil/master.m3u8' d['media'] = [{'url': video, 'type': 'video', 'stream': 'HLS'}] elif file.endswith('.mp3'): d['media'] = [{'url': file, 'type': 'audio', 'stream': 'http'}] sub = re.compile("lucy2captionArray\((.+?)\)").findall(response)[0] if sub != "''": d['subtitle'] = [{ 'url': sub.replace("'", ""), 'type': 'ttml', 'lang': 'de' }] try: name = re.compile("title = '(.+?)'").findall(response)[-1] plot = re.compile("descl = '(.+?)'").findall(response)[-1] thumb = re.compile("image = '(.+?)'").findall(response)[-1] d['metadata'] = {'name': name, 'plot': plot, 'thumb': thumb} except: pass return d
def getAZ(letter): if letter == '#': letter = '0-9' l = [] if letter == 'X' or letter == 'Y': return l content = libMediathek.getUrl( baseUrl+"/tv/sendungen-a-z?buchstabe="+letter) #r = requests.get(baseUrl+"/tv/sendungen-a-z?buchstabe="+letter) #content = r.text.decode('utf-8') spl = content.split('<div class="teaser" data-ctrl') for i in range(1, len(spl), 1): d = {} entry = spl[i] url = re.compile('href="(.+?)"', re.DOTALL).findall(entry)[0] url = url.replace("&", "&") d['url'] = baseUrl+url+'&m23644322=quelle.tv&rss=true' d['name'] = re.compile('class="headline">(.+?)<', re.DOTALL).findall(entry)[0] d['channel'] = re.compile( 'class="subtitle">(.+?)<', re.DOTALL).findall(entry)[0] thumbId = re.compile('/image/(.+?)/16x9/', re.DOTALL).findall(entry)[0] d['thumb'] = baseUrl+"/image/"+thumbId+"/16x9/0" d['fanart'] = d['thumb'] bcastId = url.split('bcastId=')[-1] if '&' in bcastId: bcastId = bcastId.split('&')[0] d['plot'] = libArdBcastId2Desc.toDesc(bcastId) d["mode"] = "libArdListVideos" l.append(d) return l
def parseAZ(letter='A'): if letter == "0-9": letter = '#' l = [] response = libMediathek.getUrl("http://www.ardmediathek.de/appdata/servlet/tv/sendungAbisZ?json") j = json.loads(response) j1 = j["sections"][0]["modCons"][0]["mods"][0]["inhalte"] for entry in j1: #if entry["ueberschrift"] == letter.upper(): if True: for entry in entry["inhalte"]: d = {} d["_name"] = entry["ueberschrift"].encode("utf-8") d["_channel"] = entry["unterzeile"].encode("utf-8") d["_entries"] = int(entry["dachzeile"].encode("utf-8").split(' ')[0]) #d["thumb"] = entry["bilder"][0]["schemaUrl"].replace("##width##","0").encode("utf-8") d["_thumb"] = entry["bilder"][0]["schemaUrl"].replace("##width##","1920").encode("utf-8") d["url"] = entry["link"]["url"].encode("utf-8") d['mode'] = 'libArdListVideos' #d["documentId"] = entry["link"]["url"].split("documentId=")[1].split("&")[0] #d["pluginpath"] = pluginpath d["_type"] = 'shows' l.append(d) return l
def getVideoUrl(uri): response = libMediathek.getUrl(baseUrl+uri) j = json.loads(response) quality = -1 url = None fallbacks = [] for asset in j['assets']: if type(asset['quality']) == type(quality): currentQuality = asset['quality'] if currentQuality > quality: url = asset['url'] quality = currentQuality elif asset['quality'] == 'Video 2014 | MP4 Web XL | 16:9 | 1280x720': url = asset['url'] elif asset['quality'] == 'auto': url = asset['url'] fallbacks.append(asset['url']) if not url: url = fallbacks[-1] if url.startswith('//'): url = 'http:' + url if url.startswith('http://wdradaptiv') or url.endswith('.mp4'): d = {'media':[{'url':url, 'type': 'video', 'stream':'mp4'}]} else: d = {'media':[{'url':url, 'type': 'video', 'stream':'HLS'}]} return d
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 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 libHrListShows(): # return libhrshows.shows l = [] response = libMediathek.getUrl(base + '/sendungen-a-z/index.html') soup = bs.BeautifulSoup(response, 'html.parser') articles = soup.findAll('div', {'class': 'c-teaser__content'}) for article in articles: name = article.find('span', {'class': 'c-teaser__headline'}) href = article.find('a', {'class': 'c-teaser__headlineLink'}) if name and href: d = {} href_str = href.attrs['href'] if href_str.startswith(base): d['showid'] = href_str.replace('/index.html','/sendungen/index.html') elif isHessenschau(href_str): d['showid'] = href_str else: continue d['name'] = name.text.strip() d['mode'] = 'libHrListEpisodes' d['_type'] = 'dir' thumb = article.find('img', {'class': 'image ar__content'}) if thumb: d['_thumb'] = thumb.attrs['src'] l.append(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']: 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(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 getDate(d, type, mode): d = abs(int(d)) response = libMediathek.getUrl('http://swrmediathek.de/app-2/svp.html') day = re.compile( '<ul data-role="listview" data-theme="c" data-divider-theme="d">(.+?)</ul>', re.DOTALL).findall(response)[d] return _findLiEntries(day, type, mode)[::-1]
def getVideoUrlWeb(url): d = {} d['media'] = [] response = libMediathek.getUrl(url) j = json.loads(response) #for caption in j.get('captions',[]): # if caption['format'] == 'ebu-tt-d-basic-de': # d['subtitle'] = [{'url':caption['uri'], 'type':'ttml', 'lang':'de', 'colour':True}] # #elif caption['format'] == 'webvtt': # # d['subtitle'] = [{'url':caption['uri'], 'type':'webvtt', 'lang':'de', 'colour':False}] storedLang = 0 for key in j['videoJsonPlayer']['VSR']:#oh, this is such bullshit. there are endless and senseless permutations of language/subtitle permutations. i'll have to rewrite this in the future for french and other languages, subtitles, hearing disabled, ... who the hell uses baked in subtitles in 2017?!?! l = lang.get(j['videoJsonPlayer']['VSR'][key]['versionCode'].split('[')[0],'ignore').upper() if preferences.get(l,0) > storedLang and j['videoJsonPlayer']['VSR'][key]['mediaType'] == 'hls': storedLang = preferences.get(l,0) result = {'url':j['videoJsonPlayer']['VSR'][key]['url'], 'type': 'video', 'stream':'HLS'} d['media'].append(result) d['metadata'] = {} d['metadata']['name'] = j['videoJsonPlayer']['VTI'] if 'VDE' in j['videoJsonPlayer']: d['metadata']['plot'] = j['videoJsonPlayer']['VDE'] elif 'V7T' in j['videoJsonPlayer']: d['metadata']['plot'] = j['videoJsonPlayer']['V7T'] d['metadata']['thumb'] = j['videoJsonPlayer']['VTU']['IUR'] d['metadata']['duration'] = str(j['videoJsonPlayer']['videoDurationSeconds']) return d
def parseMdrPlus(url): response = libMediathek.getUrl(url) root = ET.fromstring(response) l = [] for property1 in root.find('childNodes').find('childNode').find( 'childNodes').find('childNode').find('childNodes').find( 'childNode').find('properties'): if property1.attrib.get('name', '') == 'sophora:reference': #for document in property1.find('property').find('document').find('customElements').find('queryResult'): for document in property1.find('document').find( 'customElements').find('queryResult'): d = {} d['_duration'] = _durationToS( document.find('customElements').find('duration').text) d['url'] = document.find('customElements').find( 'metaxmlUrl').text for property2 in document.find('properties'): if property2.attrib.get('name', '') == 'mdr-core:headline': d['_name'] = property2[0].text if property2.attrib.get('name', '') == 'mdr-core:teaserText': if property2[0].text != None: d['_plot'] = property2[0].text for childNode in document.find('childNodes'): if childNode.attrib.get('name', '') == 'mdr-core:teaserImage': d['_thumb'] = _getThumb(childNode) d['_type'] = 'video' d['mode'] = 'libMdrPlay' l.append(d) return l
def getDate(yyyymmdd): l = [] response = libMediathek.getUrl('http://www.arte.tv/hbbtvv2/services/web/index.php/OPA/programs/'+yyyymmdd+'/de') j = json.loads(response) for program in j['programs']: if program['video'] != None: d = {} #d['_airedtime'] = program['broadcast']['broadcastBeginRounded'].split(' ')[-2][:5] s = program['broadcast']['broadcastBeginRounded'].split(' ')[-2].split(':') d['_airedtime'] = str(int(s[0]) + 1) + ':' + s[1] if len(d['_airedtime']) == 4: d['_airedtime'] = '0' + d['_airedtime'] d['_name'] = program['program']['title'] #d['url'] = 'http://www.arte.tv/papi/tvguide/videos/stream/player/D/'+program['video']['emNumber']+'_PLUS7-D/ALL/ALL.json' #d['url'] = 'http://www.arte.tv/hbbtvv2/services/web/index.php/OPA/streams/'+program['video']['programId']+'/SHOW/ARTEPLUS7/de/DE' #d['url'] = 'http://www.arte.tv/hbbtvv2/services/web/index.php/OPA/streams/'+program['video']['programId']+'/'+program['video']['kind']+'/'+program['video']['platform']+'/de/DE' d['url'] = 'https://api.arte.tv/api/player/v1/config/de/'+program['video']['programId']+'?autostart=0&lifeCycle=1&lang=de_DE&config=arte_tvguide' #d['programId'] = program['video']['programId'] if program['video']['imageUrl'] != None: d['_thumb'] = program['video']['imageUrl'] if program['video']['durationSeconds'] != None: d['_duration'] = str(program['video']['durationSeconds']) if program['video']['teaserText'] != None: d['_plotoutline'] = program['video']['teaserText'] d['_plot'] = program['video']['teaserText'] if program['video']['fullDescription'] != None: d['_plot'] = program['video']['fullDescription'] d['mode'] = 'libArtePlay' d['_type'] = 'date' l.append(d) return l
def parseShows(letter): l = [] if (letter in ('a', 'x', 'q')): pass else: response = libMediathek.getUrl(base + '/sendungen-' + letter + '-102~_variant-android.mobile') items = re.compile('<mp:additionallink>(.+?)</mp:additionallink>', re.DOTALL).findall(response) l = [] if len(items) > 0: creator = re.compile('<dc:creator>(.+?)</dc:creator>', re.DOTALL).findall(response)[0] for item in items: d = {} d['name'] = re.compile('<mp:label>(.+?)</mp:label>', re.DOTALL).findall(item)[0] if len(l) != 0 and d['name'] == l[-1]['name']: continue tmpstr = re.compile('<mp:link>(.+?)</mp:link>', re.DOTALL).findall(item)[0].split('/')[-1] if '~' not in tmpstr: continue d['id'], extension = tmpstr.split('~') #libMediathek.log(d['id']) #libMediathek.log(re.compile('<mp:link>(.+?)</mp:link>', re.DOTALL).findall(item)[0]) d['_channel'] = creator d['thumb'] = _chooseThumb( re.compile('<mp:image>(.+?)</mp:image>', re.DOTALL).findall(item)) d['_type'] = 'dir' if extension.endswith('rss'): d['grepShowFromVideo'] = 'True' d['mode'] = 'libWdrListVideos' l.append(d) return l
def parseVideos(id): response = libMediathek.getUrl(base + 'vod_main_json?id=' + id) j = json.loads(response) l = [] if j != None: for item in j: d = {} d['name'] = item['title'] if not d['name']: d['name'] = item['smubl'] d['plot'] = item['text_vorspann'] thumbnail_item = None if 'thumbnail_large' in item and item['thumbnail_large']: thumbnail_item = item['thumbnail_large'] elif 'thumbnail_medium' in item and item['thumbnail_medium']: thumbnail_item = item['thumbnail_medium'] if thumbnail_item: if 'systemurl' in thumbnail_item and thumbnail_item[ 'systemurl']: d['thumb'] = 'https://www.phoenix.de' + thumbnail_item[ 'systemurl'] elif 'systemurl_gsid' in thumbnail_item and thumbnail_item[ 'systemurl_gsid']: d['thumb'] = 'https://www.phoenix.de' + thumbnail_item[ 'systemurl_gsid'] d['_type'] = 'video' d['smubl'] = item['smubl'] d['mode'] = 'play' l.append(d) return l
def parseDate(url): l = [] response = libMediathek.getUrl(url) j = json.loads(response) j1 = j["sections"][-1]["modCons"][0]["mods"][0]["inhalte"] for entry in j1: j2 = entry["inhalte"] for entry in j2: d = {} d["_airedtime"] = entry["dachzeile"] #d["_name"] = entry["dachzeile"] + ' - ' #d["_name"] += entry["ueberschrift"] + ' - ' d["_name"] = entry["ueberschrift"] + ' - ' duration = 0 for j3 in entry["inhalte"]: if runtimeToInt(j3["unterzeile"]) > duration: duration = runtimeToInt(j3["unterzeile"]) d["_name"] += j3["ueberschrift"] #d["_channel"] = j3["unterzeile"] #d["_thumb"] = j3["bilder"][0]["schemaUrl"].replace("##width##","0") d["_thumb"] = j3["bilder"][0]["schemaUrl"].replace("##width##","384") d["url"] = j3["link"]["url"] d["documentId"] = j3["link"]["url"].split("player/")[1].split("?")[0] d["_duration"] = str(runtimeToInt(j3["unterzeile"])) #d["_pluginpath"] = pluginpath d["_type"] = 'date' d['mode'] = 'libArdPlay' l.append(d) return l
def parseVideos(url): if not 'latestVideos' in url: response = libMediathek.getUrl(url) j = json.loads(response) if "_links" in j and 'latestVideos' in j["_links"]: url = j["_links"]["latestVideos"]["href"] else: return [] return parseLinks(url)
def parseDate(date,channel='BR'): import time j = _parseMain() url = j["_links"]["epg"]["href"] response = libMediathek.getUrl(url) j = json.loads(response) url = j["epgDays"]["_links"][date]["href"]#date: 2016-12-30 response = libMediathek.getUrl(url) j = json.loads(response) l = [] broadcasts = j["channels"][chan[channel]]["broadcasts"] for b in broadcasts: if "_links" in b and "video" in b["_links"]: d = {} d["_name"] = b["headline"] if len(b["subTitle"]) > 0: d['_name'] += ' - ' + b["subTitle"] d["_plot"] = b["subTitle"] d["_tvshowtitle"] = b["hasSubtitle"] d["url"] = b["_links"]["video"]["href"] #2016-10-14T08:50:00+02:00 d["_epoch"] = int(time.mktime(time.strptime(b["broadcastStartDate"].split('+')[0], '%Y-%m-%dT%H:%M:%S'))) d["_epoch"] = str(d["_epoch"]) d["_time"] = startTimeToInt(b["broadcastStartDate"][11:19]) d['_date'] = b["broadcastStartDate"][11:16] d['_duration'] = (startTimeToInt(b["broadcastEndDate"][11:19]) - startTimeToInt(b["broadcastStartDate"][11:19])) * 60 if d['_duration'] < 0: d['_duration'] = 86400 - abs(d['_duration']) #TODO: rest of properties if b['hasSubtitle']: d['_hasSubtitle'] = 'true' #d['_plot'] += '\n\nUntertitel' d['_type'] = 'date' d['mode'] = 'libBrPlay' l.append(d) return l
def parseVideo(url):#TODO grep the plot and other metadata from here response = libMediathek.getUrl(url) j = json.loads(response) d = {} d['media'] = [] assets = j["assets"] if 'dataTimedTextUrl' in j['_links']: d['subtitle'] = [{'url':j['_links']['dataTimedTextUrl']['href'], 'type':'ttml', 'lang': 'de'}] for asset in assets: if "type" in asset and asset["type"] == "HLS_HD": d['media'].append({'url':asset["_links"]["stream"]["href"], 'type': 'video', 'stream':'HLS'}) return d for asset in assets: if "type" in asset and asset["type"] == "HLS": d['media'].append({'url':asset["_links"]["stream"]["href"], 'type': 'video', 'stream':'HLS'}) return d
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 parseLinks(url): response = libMediathek.getUrl(url) j = json.loads(response) l = [] if not '_embedded' in j: return l for show in j["_embedded"]["teasers"]: d = {} d['url'] = show["_links"]["self"]["href"] d['_name'] = show["topline"] if 'headline' in show: d['_name'] += ' - ' + show['headline'] d['_tvshowtitle'] = show['topline'] d['_subtitle'] = show["topline"] d['_plot'] = show["teaserText"] d['_channel'] = show["channelTitle"] duration = show['documentProperties']["br-core:duration"].split(':') d['_duration'] = str(int(duration[0]) * 3600 + int(duration[1]) * 60 + int(duration[2])) if 'image512' in show["teaserImage"]["_links"]: d['_thumb'] = show["teaserImage"]["_links"]["image512"]["href"] elif 'image256' in show["teaserImage"]["_links"]: d['_thumb'] = show["teaserImage"]["_links"]["image256"]["href"] try: if show['hasSubtitle']: d['_hasSubtitle'] = 'true' #d['plot'] += '\n\nUntertitel' except:pass d['_type'] = 'video' d['mode'] = 'libBrPlay' l.append(d) try: d = {} d['_type'] = 'nextPage' d['url'] = j['_embedded']['_links']['next']['href'] l.append(d) except: pass return l
def parse(url): l = [] response = libMediathek.getUrl(url) j = json.loads(response)
def _parseMain(): response = libMediathek.getUrl("http://www.br.de/system/halTocJson.jsp") j = json.loads(response) url = j["medcc"]["version"]["1"]["href"] response = libMediathek.getUrl(url) return json.loads(response)