1919import xbmcgui
2020import xbmcplugin
2121
22+ import json
2223import sys
2324
24- from libs .show import getEpisodes
25- from libs .episode import mapEpisode , appendStreams
25+ from bs4 import BeautifulSoup
26+
27+ from libs .network import fetchHtml
28+ from libs .network import fetchJson
2629
2730
2831# -- Addon --
3437base_path = sys .argv [0 ]
3538
3639
37- # -- Constants --
38- sources = {
39- "rbb" : "https://api.ardmediathek.de/page-gateway/widgets/ard/editorials/3GuLb6bWPNyeenTBjK9u5l%3A7561660580516351848?pageNumber=0&pageSize=100" ,
40- "mdr" : "https://api.ardmediathek.de/page-gateway/widgets/ard/editorials/3GuLb6bWPNyeenTBjK9u5l%3A7561660580516351848?pageNumber=0&pageSize=100"
41- }
42-
43-
4440# -- Settings --
4541dgs = addon .getSettingInt ("dgs2" )
4642interval = addon .getSettingInt ("interval2" )
5046
5147
5248def sandmann ():
53- if update == 1 :
54- li_refresh = xbmcgui .ListItem (label = addon .getLocalizedString (30020 ))
55- xbmcplugin .addDirectoryItem (addon_handle , base_path , li_refresh , True )
49+ li_refresh = xbmcgui .ListItem (label = addon .getLocalizedString (30020 ))
50+ xbmcplugin .addDirectoryItem (addon_handle , base_path , li_refresh , True )
5651
57- url = sources ["rbb" ]
58- if source == 1 :
59- url = sources ["mdr" ]
52+ html = fetchWebsite ()
6053
61- episodes = getEpisodes (url )
62- episodes2 = map (mapEpisode , episodes )
63- episodes3 = filterDgs (episodes2 , dgs )
64- episodes4 = map (appendStreams , episodes3 )
54+ if dgs == 0 :
55+ episodes = getEpisodes (html , 1 )
56+ elif dgs == 2 :
57+ episodes = getEpisodes (html , 2 )
58+ else :
59+ episodes = getEpisodes (html , 1 ) + getEpisodes (html , 2 )
6560
6661 item_list = []
67- for episode in episodes4 :
68- item_list .append ((getStream (episode , quality ), getListItem (episode ), False ))
62+ for episode , description in episodes :
63+ path = getEpisodePath (episode )
64+ details = fetchEpisodeDetails (path )
6965
70- xbmcplugin . addDirectoryItems ( addon_handle , item_list , len ( item_list ))
66+ item_list . append (( details [ "stream" ], getListItem ( details , description ), False ))
7167
68+ # xbmcgui.Dialog().ok("DEBUG", f'{item_list[0]}')
69+ xbmcplugin .addDirectoryItems (addon_handle , item_list , len (item_list ))
7270 xbmcplugin .endOfDirectory (addon_handle )
7371
7472
75- def filterDgs (episodes , dgs ):
76- if dgs == 0 :
77- return [e for e in episodes if e ["dgs" ] == False ]
78- elif dgs == 2 :
79- return [e for e in episodes if e ["dgs" ] == True ]
80- else :
81- return episodes
73+ def fetchWebsite ():
74+ url = "https://www.sandmann.de/videos/"
75+ html = fetchHtml (url )
8276
77+ return html
8378
84- def getStream (episode , quality ):
85- streams = episode ["streams" ]
8679
87- index = quality - 1
88- if index in streams :
89- return streams [index ]
90- else :
91- return streams ["auto" ]
80+ def getEpisodes (html , count ):
81+ soup = BeautifulSoup (html , "html.parser" )
82+ episodes = soup .select (f"#main > .count{ count } .manualteaserpicture" )
83+ html_descriptions = soup .select (f"#main > .count{ count } .manualteasershorttext p" )
84+ descriptions = [p .get_text () for p in html_descriptions ]
85+
86+ return list (zip (episodes , descriptions ))
87+
88+
89+ def getEpisodePath (episode ):
90+ jsb_string = episode .get ("data-jsb" )
91+ jsb_object = json .loads (jsb_string )
92+
93+ return jsb_object ["media" ]
94+
95+
96+ def fetchEpisodeDetails (path ):
97+ json = fetchJson (f"https://www.sandmann.de{ path } " )
98+
99+ streams = {}
100+ for stream in json ["_mediaArray" ][0 ]["_mediaStreamArray" ]:
101+ streams [stream ["_quality" ]] = stream ["_stream" ]
102+
103+ title = json ["rbbtitle" ].split (" | " )
104+ previewImage = "https://www.sandmann.de" + json ["_previewImage" ].rsplit ("/" , 1 )[0 ]
105+
106+ return {
107+ "date" : title [2 ],
108+ # "dgs": json["dgs"],
109+ "duration" : json ["_duration" ],
110+ "fanart" : previewImage + "/size=1920x1080.jpg" ,
111+ "stream" : streams ["auto" ],
112+ "thumb" : previewImage + "/size=640x360.jpg" ,
113+ "title" : f"{ title [2 ]} | { title [0 ]} "
114+ }
92115
93116
94- def getListItem (item ):
117+ def getListItem (item , description ):
95118 li = xbmcgui .ListItem ()
96119 li .setLabel (item ["title" ])
97120 li .setArt ({
@@ -103,7 +126,7 @@ def getListItem(item):
103126 infoLabels = {
104127 "aired" : item ["date" ],
105128 "duration" : item ["duration" ],
106- "plot" : item [ "desc" ] ,
129+ "plot" : description ,
107130 }
108131 )
109132 li .setProperty ("IsPlayable" , "true" )
0 commit comments