|
|
|
@ -6,17 +6,17 @@ from datetime import datetime
|
|
|
|
|
import feedparser
|
|
|
|
|
import requests
|
|
|
|
|
import wx
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
from Channel import Channel
|
|
|
|
|
from Items import Item
|
|
|
|
|
from Utils import (add_video, hash_string, make_bitmap_from_url,
|
|
|
|
|
from Utils import (add_video, get_all_svt_programs, get_svt_id, get_svt_thumbnail, hash_string, make_bitmap_from_url,
|
|
|
|
|
resolve_svt_channel, video_exists)
|
|
|
|
|
|
|
|
|
|
default_rss_url = 'http://www.svtplay.se/rss.xml'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SVT(Channel):
|
|
|
|
|
|
|
|
|
|
def __init__(self, channel_id: str) -> None:
|
|
|
|
|
chan_dict = resolve_svt_channel(channel_id)
|
|
|
|
|
logo = chan_dict['thumbnail']
|
|
|
|
@ -24,7 +24,6 @@ class SVT(Channel):
|
|
|
|
|
super().__init__(channel_id, 'SVT', default_rss_url, logo, name)
|
|
|
|
|
|
|
|
|
|
def parse_feed(self) -> None:
|
|
|
|
|
#self.m_items: list[Item] = list()
|
|
|
|
|
resolved_link = str()
|
|
|
|
|
description = str()
|
|
|
|
|
title = str()
|
|
|
|
@ -33,7 +32,7 @@ class SVT(Channel):
|
|
|
|
|
published_parsed: datetime = datetime.now()
|
|
|
|
|
video_id = str()
|
|
|
|
|
|
|
|
|
|
if self.m_id == 'feed' :
|
|
|
|
|
if self.m_id == 'feed':
|
|
|
|
|
feed = feedparser.parse(self.get_feed())
|
|
|
|
|
entries = feed['entries']
|
|
|
|
|
for entry in entries:
|
|
|
|
@ -46,16 +45,7 @@ class SVT(Channel):
|
|
|
|
|
thumbnail_link = str(link['href'])
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
svt_id = get_svt_id(str(entry['link']))
|
|
|
|
|
resolved_link = self.resolve_link(svt_id)
|
|
|
|
|
description = str(entry['description'])
|
|
|
|
|
published_parsed = entry['published_parsed']
|
|
|
|
@ -67,9 +57,40 @@ class SVT(Channel):
|
|
|
|
|
item = Item(description, resolved_link, self.m_provider_name,
|
|
|
|
|
published_parsed, thumbnail, title)
|
|
|
|
|
self.m_items.append(item)
|
|
|
|
|
add_video(video_id, self.m_id, self.m_provider_name, description,
|
|
|
|
|
resolved_link, published_parsed, thumbnail, title, 0)
|
|
|
|
|
add_video(video_id, self.m_id, self.m_provider_name,
|
|
|
|
|
description, resolved_link, published_parsed,
|
|
|
|
|
thumbnail, title, 0)
|
|
|
|
|
|
|
|
|
|
elif self.m_id == 'allprograms':
|
|
|
|
|
entries = get_all_svt_programs()
|
|
|
|
|
for entry in entries:
|
|
|
|
|
url = entry['item']['urls']['svtplay']
|
|
|
|
|
video_id = hash_string(url.split('/')[1])
|
|
|
|
|
svt_id = str()
|
|
|
|
|
link = "https://svtplay.se{}".format(url)
|
|
|
|
|
if video_exists(video_id, 'allprograms'):
|
|
|
|
|
continue
|
|
|
|
|
thumbnail_link = get_svt_thumbnail(link)
|
|
|
|
|
|
|
|
|
|
svt_id = get_svt_id(link)
|
|
|
|
|
resolved_link = self.resolve_link(svt_id)
|
|
|
|
|
title = str(entry['heading'])
|
|
|
|
|
type = str(entry['item']['__typename'])
|
|
|
|
|
published_parsed = datetime.now()
|
|
|
|
|
swe_only = "no"
|
|
|
|
|
if entry['item']['restrictions']['onlyAvailableInSweden']:
|
|
|
|
|
swe_only = 'yes'
|
|
|
|
|
description = "{}\nOnly available in Sweden:{}\nType of program:{}".format(title, swe_only, type)
|
|
|
|
|
if not resolved_link:
|
|
|
|
|
continue
|
|
|
|
|
thumbnail = make_bitmap_from_url(
|
|
|
|
|
thumbnail_link, wx.Size(int(self.m_screen_width), 150))
|
|
|
|
|
item = Item(description, resolved_link, self.m_provider_name,
|
|
|
|
|
published_parsed, thumbnail, title, sort_key = entry['selection_name'])
|
|
|
|
|
self.m_items.append(item)
|
|
|
|
|
add_video(video_id, self.m_id, self.m_provider_name,
|
|
|
|
|
description, resolved_link, published_parsed,
|
|
|
|
|
thumbnail, title, 0)
|
|
|
|
|
else:
|
|
|
|
|
chan_dict = resolve_svt_channel(self.m_id)
|
|
|
|
|
resolved_link = self.resolve_link(self.m_id)
|
|
|
|
@ -83,12 +104,10 @@ class SVT(Channel):
|
|
|
|
|
published_parsed, thumbnail, title)
|
|
|
|
|
self.m_items.append(item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def resolve_link(self,svt_id) -> str:
|
|
|
|
|
def resolve_link(self, svt_id) -> str:
|
|
|
|
|
url = 'https://api.svt.se/video/{}'.format(svt_id)
|
|
|
|
|
print(url)
|
|
|
|
|
api = json.loads(
|
|
|
|
|
requests.get(url).text)
|
|
|
|
|
api = json.loads(requests.get(url).text)
|
|
|
|
|
resolved_link = ''
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -98,4 +117,3 @@ class SVT(Channel):
|
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
|
|
|
|
return resolved_link
|
|
|
|
|
|
|
|
|
|