You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cast/ChannelProvider/SVT/__init__.py

50 lines
1.6 KiB

#!/usr/bin/env python3
import ChannelProvider
import feedparser
import requests
from bs4 import BeautifulSoup
from Items import Item
import json
class SVT(ChannelProvider.ChannelProvider):
def __init__(self) -> None:
super().__init__('SVT', 'http://www.svtplay.se/rss.xml')
def parse_feed(self) -> list[Item]:
feed = feedparser.parse(self.get_feed())
entries = feed['entries']
items: list[Item] = list()
for entry in entries:
thumbnail = ''
svt_id = ''
for link in entry['links']:
if str(link['type']).startswith('image/'):
thumbnail = str(link['href'])
page = requests.get(str(entry['link']))
soup = BeautifulSoup(page.text, 'html.parser')
for element in soup.find_all('a'):
href = element.get('href')
datart= element.get('data-rt')
if datart == 'top-area-play-button':
svt_id = href.split('=')[1].split('&')[0]
api = json.loads(requests.get('https://api.svt.se/video/{}'.format(svt_id)).text)
#print(api['videoReferences'])
resolved_link = ''
for reference in api['videoReferences']:
if reference['format'] == "dashhbbtv":
resolved_link = reference['url']
print(resolved_link)
item = Item(str(entry['description']), resolved_link,
self.m_provider_name, entry['published_parsed'],
thumbnail, str(entry['title']))
items.append(item)
return items