Skip to content

Commit

Permalink
fix new api
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevFreak committed Feb 19, 2020
1 parent 3e2660c commit e7bfeaa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
17 changes: 12 additions & 5 deletions resources/lib/F1TVParser/F1TV_Minimal_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


''' General Entry point for F1TV API'''
__TV_API__='https://f1tv.formula1.com'
__TV_API__='https://f1tv-api.formula1.com/agl/1.0/gbr/en/all_devices/global/'
__OLD_TV_API__='https://f1tv.formula1.com'

''' Parameters for different F1TV API calls'''
__TV_API_PARAMS__ = {"event-occurrence": {"fields_to_expand": "image_urls,sessionoccurrence_urls,sessionoccurrence_urls__image_urls",
Expand Down Expand Up @@ -41,7 +42,7 @@ def login(self, username, password):
def getStream(self, url):
""" Get stream for supplied viewings item
This will get the m3u8 url for Content and Channel."""
complete_url = __TV_API__ + "/api/viewings/"
complete_url = __OLD_TV_API__ + "/api/viewings/"
item_dict = {"asset_url" if 'ass' in url else "channel_url": url}

viewing = self.account_manager.getSession().post(complete_url, data=json.dumps(item_dict))
Expand Down Expand Up @@ -72,23 +73,23 @@ def getEvent(self, url, season = None):

def getSeason(self, url):
""" Get Season object from API by supplying an url"""
complete_url = __TV_API__ + url
complete_url = __OLD_TV_API__ + url
r = self.account_manager.getSession().get(complete_url, params=self.getFields(url)) #__TV_API_PARAMS__["season"])

if r.ok:
return r.json()

def getSeasons(self):
""" Get all season urls that are available at API"""
complete_url = __TV_API__ + "/api/race-season/"
complete_url = __OLD_TV_API__ + "/api/race-season/"
r = self.account_manager.getSession().get(complete_url, params={'order': '-year'})

if r.ok:
return r.json()

def getCircuits(self):
""" Get all Circuit urls that are available at API"""
complete_url = __TV_API__ + "/api/circuit/"
complete_url = __OLD_TV_API__TV_API__ + "/api/circuit/"
r = self.account_manager.getSession().get(complete_url, params={"fields": "name,eventoccurrence_urls,self"})

if r.ok:
Expand All @@ -113,6 +114,12 @@ def getAnyURL(self, url):
r = self.account_manager.getSession().get(complete_url)
if r.ok:
return r.json()

def getAnyOldURL(self, url):
complete_url = __OLD_TV_API__+url
r = self.account_manager.getSession().get(complete_url)
if r.ok:
return r.json()

def getSets(self):
complete_url = __TV_API__ + "/api/sets/?slug=home"
Expand Down
46 changes: 26 additions & 20 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def list_season_events(season_url, year):
'genre': "Motorsport",
'mediatype': 'video'})

url = get_url(action='list_sessions', event_url=event['self'], event_name=event['name'])
url = get_url(action='list_sessions', event_url=event['self'].replace("/api/",""), event_name=event['name'])

is_folder = True
# Add our item to the Kodi virtual folder listing.
Expand Down Expand Up @@ -332,26 +332,27 @@ def list_sessions(event_url, event_name):

for session in event['sessionoccurrence_urls']:

if session['available_for_user'] is False and len(session['content_urls']) == 0:
continue
#if session['available_for_user'] is False and len(session['content_urls']) == 0:
# continue

thumb = ""
for image in session['image_urls']:
if image['type'] == "Thumbnail":
thumb = image['url']
break
#for image in session['image_urls']:
# if image['type'] == "Thumbnail":
# thumb = image['url']
# break
# Create a list item with a text label and a thumbnail image.
list_item = xbmcgui.ListItem(label=session['session_name'])
list_item = xbmcgui.ListItem(label=session['name'])


list_item.setArt({'thumb': thumb,
'icon': thumb,
'fanart': thumb})

list_item.setInfo('video', {'title': session['session_name'],
list_item.setInfo('video', {'title': session['name'],
'genre': "Motorsport",
'mediatype': 'video'})

url = get_url(action='list_content', session_url=session['self'], session_name=session['session_name'])
url = get_url(action='list_content', session_url=session['self'].replace("/api/",""), session_name=session['name'])

is_folder = True
# Add our item to the Kodi virtual folder listing.
Expand All @@ -373,21 +374,26 @@ def list_content(session_url, session_name):
xbmcplugin.setContent(_handle, 'videos')
# Get video categories
session = _api_manager.getSession(session_url)
print(session)

for channel in session['channel_urls']:


thumb = ''
if len(channel['driver_urls']) > 0:
for image in channel['driver_urls'][0]['image_urls']:
if image['type'] == 'Headshot':
thumb = image['url']
break
else:
for image in session['image_urls']:
if image['type'] == 'Thumbnail':
thumb = image['url']
break
try:
if len(channel['driver_urls']) > 0:
for image in channel['driver_urls'][0]['image_urls']:
if image['type'] == 'Headshot':
thumb = image['url']
break
except:
pass
for image in session['image_urls']:
if image['type'] == 'Thumbnail':
thumb = image['url']
break
# Create a list item with a text label and a thumbnail image.
channel = _api_manager.getAnyOldURL(channel)
name = channel['name'] if 'WIF' not in channel['name'] else session['session_name']
list_item = xbmcgui.ListItem(label=name)

Expand Down

0 comments on commit e7bfeaa

Please sign in to comment.