3232_fanart = addon .getAddonInfo ('fanart' )
3333_path = addon .getAddonInfo ('path' )
3434_ipath = '{0}/resources/images/' .format (_path )
35+ _kodiver = float (xbmcaddon .Addon ('xbmc.addon' ).getAddonInfo ('version' )[:4 ])
3536
3637if hasattr (xbmcvfs , "translatePath" ):
3738 translate_path = xbmcvfs .translatePath
@@ -111,10 +112,49 @@ def index():
111112 addDir (translation (30034 ), "" , "personalMain" , "{0}my_stuff.png" .format (_ipath ))
112113 else :
113114 addFavDir (translation (30024 ), "" , "favouriteUsers" , "{0}favourite_users.png" .format (_ipath ))
115+ xbmcplugin .endOfDirectory (pluginhandle )
114116 xbmcplugin .setContent (pluginhandle , "addons" )
115117 if force_mode :
116118 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
117- xbmcplugin .endOfDirectory (pluginhandle )
119+
120+
121+ def update_listitem (li , infoLabels ):
122+ if isinstance (infoLabels , dict ):
123+ labels = infoLabels .copy ()
124+ if _kodiver > 19.8 :
125+ vtag = li .getVideoInfoTag ()
126+ if labels .get ('Title' ):
127+ vtag .setTitle (labels ['Title' ])
128+ if labels .get ('Plot' ):
129+ vtag .setPlot (labels ['Plot' ])
130+ if labels .get ('Duration' ):
131+ vtag .setDuration (labels ['Duration' ])
132+ if labels .get ('Aired' ):
133+ vtag .setFirstAired (labels ['Aired' ])
134+ if labels .get ('Episode' ):
135+ vtag .setEpisode (int (labels ['Episode' ]))
136+ else :
137+ li .setInfo (type = 'Video' , infoLabels = labels )
138+
139+ return
140+
141+
142+ def make_listitem (name = '' , labels = None , path = '' ):
143+ if _kodiver >= 18.0 : # Include Kodi version 18 in the condition
144+ offscreen = True
145+ if name :
146+ li = xbmcgui .ListItem (name , offscreen = offscreen )
147+ else :
148+ li = xbmcgui .ListItem (path = path , offscreen = offscreen )
149+ else :
150+ if name :
151+ li = xbmcgui .ListItem (name )
152+ else :
153+ li = xbmcgui .ListItem (path = path )
154+
155+ if isinstance (labels , dict ):
156+ update_listitem (li , labels )
157+ return li
118158
119159
120160def personalMain ():
@@ -123,10 +163,10 @@ def personalMain():
123163 addDir (translation (30036 ), "{0}/user/{1}/subscriptions?fields=description,duration,id,owner.username,taken_time,thumbnail_large_url,title,views_total&sort=recent&limit={2}&family_filter={3}&localization={4}&page=1" .format (urlMain , dmUser , itemsPerPage , familyFilter , language ), 'listVideos' , "{0}following.png" .format (_ipath ))
124164 addDir (translation (30037 ), "{0}/user/{1}/favorites?fields=description,duration,id,owner.username,taken_time,thumbnail_large_url,title,views_total&sort=recent&limit={2}&family_filter={3}&localization={4}&page=1" .format (urlMain , dmUser , itemsPerPage , familyFilter , language ), 'listVideos' , "{0}favourites.png" .format (_ipath ))
125165 addDir (translation (30038 ), "{0}/user/{1}/playlists?fields=id,name,videos_total&sort=recent&limit={2}&family_filter={3}&localization={4}&page=1" .format (urlMain , dmUser , itemsPerPage , familyFilter , language ), 'listUserPlaylists' , "{0}playlists.png" .format (_ipath ))
166+ xbmcplugin .endOfDirectory (pluginhandle )
126167 xbmcplugin .setContent (pluginhandle , 'addons' )
127168 if force_mode :
128169 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
129- xbmcplugin .endOfDirectory (pluginhandle )
130170
131171
132172def listUserPlaylists (url ):
@@ -158,10 +198,10 @@ def favouriteUsers():
158198 match = re .compile ('###USER###=(.+?)###THUMB###=(.*?)###END###' , re .DOTALL ).findall (content )
159199 for user , thumb in match :
160200 addUserFavDir (user , 'owner:{0}' .format (user ), 'sortVideos1' , thumb )
201+ xbmcplugin .endOfDirectory (pluginhandle )
161202 xbmcplugin .setContent (pluginhandle , "addons" )
162203 if force_mode :
163204 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
164- xbmcplugin .endOfDirectory (pluginhandle )
165205
166206
167207def listChannels ():
@@ -187,10 +227,10 @@ def sortVideos1(url):
187227 addDir (translation (30009 ), url .replace ("sort=recent" , "sort=visited" ), 'sortVideos2' , "{0}most_viewed.png" .format (_ipath ))
188228 if item_type == "owner" :
189229 addDir ("- {0}" .format (translation (30038 )), "{0}/user/{1}/playlists?fields=id,name,videos_total&sort=recent&limit={2}&family_filter={3}&localization={4}&page=1" .format (urlMain , gid , itemsPerPage , familyFilter , language ), 'listUserPlaylists' , "{0}playlists.png" .format (_ipath ))
230+ xbmcplugin .endOfDirectory (pluginhandle )
190231 xbmcplugin .setContent (pluginhandle , 'addons' )
191232 if force_mode :
192233 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
193- xbmcplugin .endOfDirectory (pluginhandle )
194234
195235
196236def sortVideos2 (url ):
@@ -199,10 +239,10 @@ def sortVideos2(url):
199239 addDir (translation (30012 ), url .replace ("sort=visited" , "sort=visited-week" ), "listVideos" , "{0}most_viewed.png" .format (_ipath ))
200240 addDir (translation (30013 ), url .replace ("sort=visited" , "sort=visited-month" ), "listVideos" , "{0}most_viewed.png" .format (_ipath ))
201241 addDir (translation (30014 ), url , 'listVideos' , "{0}most_viewed.png" .format (_ipath ))
242+ xbmcplugin .endOfDirectory (pluginhandle )
202243 xbmcplugin .setContent (pluginhandle , 'addons' )
203244 if force_mode :
204245 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
205- xbmcplugin .endOfDirectory (pluginhandle )
206246
207247
208248def sortUsers1 ():
@@ -259,10 +299,10 @@ def listVideos(url):
259299 currentPage = content ['page' ]
260300 nextPage = currentPage + 1
261301 addDir ("{0} ({1})" .format (translation (30001 ), nextPage ), url .replace ("page={0}" .format (currentPage ), "page={0}" .format (nextPage )), 'listVideos' , "{0}next_page2.png" .format (_ipath ))
302+ xbmcplugin .endOfDirectory (pluginhandle )
262303 xbmcplugin .setContent (pluginhandle , "episodes" )
263304 if force_mode :
264305 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (video_mode ))
265- xbmcplugin .endOfDirectory (pluginhandle )
266306
267307
268308def listUsers (url ):
@@ -279,10 +319,10 @@ def listUsers(url):
279319 currentPage = content ['page' ]
280320 nextPage = currentPage + 1
281321 addDir ("{0} ({1})" .format (translation (30001 ), nextPage ), url .replace ("page={0}" .format (currentPage ), "page={0}" .format (nextPage )), 'listUsers' , "{0}next_page.png" .format (_ipath ))
322+ xbmcplugin .endOfDirectory (pluginhandle )
282323 xbmcplugin .setContent (pluginhandle , "addons" )
283324 if force_mode :
284325 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
285- xbmcplugin .endOfDirectory (pluginhandle )
286326
287327
288328def listLive (url ):
@@ -293,15 +333,15 @@ def listLive(url):
293333 vid = item ['id' ]
294334 thumb = item ['thumbnail_large_url' ]
295335 views = item ['views_last_hour' ]
296- addLiveLink (title , vid , 'playLiveVideo' , thumb .replace ("\\ " , "" ), views )
336+ addLiveLink (title , vid , 'playLiveVideo' , thumb .replace ("\\ " , "" ), 'Views: {}' . format ( views ) )
297337 if content ['has_more' ]:
298338 currentPage = content ['page' ]
299339 nextPage = currentPage + 1
300340 addDir ("{0} ({1})" .format (translation (30001 ), nextPage ), url .replace ("page={0}" .format (currentPage ), "page={0}" .format (nextPage )), 'listLive' , "{0}next_page2.png" .format (_ipath ))
341+ xbmcplugin .endOfDirectory (pluginhandle )
301342 xbmcplugin .setContent (pluginhandle , "episodes" )
302343 if force_mode :
303344 xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
304- xbmcplugin .endOfDirectory (pluginhandle )
305345
306346
307347def playVideo (vid , live = False ):
@@ -312,7 +352,12 @@ def playVideo(vid, live=False):
312352 xbmc .log ("DAILYMOTION - FinalUrl = {0}" .format (url ), xbmc .LOGDEBUG )
313353
314354 if url :
355+ subs = []
356+ if isinstance (url , tuple ):
357+ url , subs = url
315358 listitem = xbmcgui .ListItem (path = url )
359+ if subs :
360+ listitem .setSubtitles (subs )
316361 if '.m3u8' in url :
317362 listitem .setMimeType ("application/x-mpegURL" )
318363 else :
@@ -331,26 +376,25 @@ def s(elem):
331376
332377
333378def getStreamUrl (vid , live = False ):
334- if familyFilter == "1" :
335- ff = "on"
336- else :
337- ff = "off"
338379 xbmc .log ('DAILYMOTION - url is {0}' .format (url ), xbmc .LOGDEBUG )
339380 headers = {'User-Agent' : _UA ,
340381 'Origin' : 'https://www.dailymotion.com' ,
341382 'Referer' : 'https://www.dailymotion.com/' }
342383 cookie = {'lang' : language ,
343- 'ff' : ff }
384+ 'ff' : "on" if familyFilter == "1" else "off" }
344385 r = requests .get ("https://www.dailymotion.com/player/metadata/video/{0}" .format (vid ), headers = headers , cookies = cookie )
345386 content = r .json ()
346- if content .get ('error' ) is not None :
347- Error = (content ['error' ]['title ' ])
387+ if content .get ('error' ):
388+ Error = (content ['error' ]['type ' ])
348389 xbmcgui .Dialog ().notification ('Info:' , Error , _icon , 5000 , False )
349390 return
350391 else :
351392 cc = content ['qualities' ]
352393 cc = list (cc .items ())
353394 cc = sorted (cc , key = s , reverse = True )
395+ subs = content .get ('subtitles' , {}).get ('data' )
396+ if subs :
397+ subs = [subs [x ].get ('urls' )[0 ] for x in subs .keys ()]
354398 m_url = ''
355399 other_playable_url = []
356400
@@ -364,15 +408,15 @@ def getStreamUrl(vid, live=False):
364408 if source == "auto" :
365409 mbtext = requests .get (m_url , headers = headers ).text
366410 mb = re .findall ('NAME="([^"]+)",PROGRESSIVE-URI="([^"]+)"' , mbtext )
367- if checkUrl (mb [- 1 ][1 ].split ('#cell' )[0 ]) is False :
368- mb = re .findall (r'NAME="([^"]+)".+ \n([^\n]+)' , mbtext )
411+ if not mb or checkUrl (mb [- 1 ][1 ].split ('#cell' )[0 ]) is False :
412+ mb = re .findall (r'NAME="([^"]+)".* \n([^\n]+)' , mbtext )
369413 mb = sorted (mb , key = s , reverse = True )
370414 for quality , strurl in mb :
371415 quality = quality .split ("@" )[0 ]
372416 if int (quality ) <= int (maxVideoQuality ):
373417 strurl = '{0}|{1}' .format (strurl .split ('#cell' )[0 ], urllib_parse .urlencode (headers ))
374418 xbmc .log ('Selected URL is: {0}' .format (strurl ), xbmc .LOGDEBUG )
375- return strurl
419+ return ( strurl , subs ) if subs else strurl
376420
377421 elif int (source ) <= int (maxVideoQuality ):
378422 if 'video' in item .get ('type' , None ):
@@ -554,29 +598,21 @@ def translation(lid):
554598
555599
556600def getUrl2 (url ):
557- if familyFilter == "1" :
558- ff = "on"
559- else :
560- ff = "off"
561601 xbmc .log ('DAILYMOTION - The url is {0}' .format (url ), xbmc .LOGDEBUG )
562602 headers = {'User-Agent' : _UA }
563603 cookie = {'lang' : language ,
564- 'ff' : ff }
604+ 'ff' : "on" if familyFilter == "1" else "off" }
565605 r = requests .get (url , headers = headers , cookies = cookie )
566606 return r .text
567607
568608
569609def checkUrl (url ):
570- if familyFilter == "1" :
571- ff = "on"
572- else :
573- ff = "off"
574610 xbmc .log ('DAILYMOTION - Check url is {0}' .format (url ), xbmc .LOGDEBUG )
575611 headers = {'User-Agent' : _UA ,
576612 'Referer' : 'https://www.dailymotion.com/' ,
577613 'Origin' : 'https://www.dailymotion.com' }
578614 cookie = {'lang' : language ,
579- 'ff' : ff }
615+ 'ff' : "on" if familyFilter == "1" else "off" }
580616 r = requests .head (url , headers = headers , cookies = cookie )
581617 status = r .status_code == 200
582618 return status
@@ -596,12 +632,11 @@ def parameters_string_to_dict(parameters):
596632def addLink (name , url , mode , iconimage , user , desc , duration , date , nr ):
597633 u = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], urllib_parse .quote_plus (url ), mode )
598634 ok = True
599- liz = xbmcgui . ListItem (name )
635+ liz = make_listitem (name = name , labels = { "Title" : name , "Plot" : desc , "Aired" : date , "Duration" : duration , "Episode" : nr } )
600636 liz .setArt ({'thumb' : iconimage ,
601637 'icon' : _icon ,
602638 'poster' : iconimage ,
603639 'fanart' : _fanart })
604- liz .setInfo (type = "Video" , infoLabels = {"Title" : name , "Plot" : desc , "Aired" : date , "Duration" : duration , "Episode" : nr })
605640 liz .setProperty ('IsPlayable' , 'true' )
606641 entries = []
607642 entries .append ((translation (30044 ), 'RunPlugin(plugin://{0}/?mode=downloadVideo&name={1}&url={2})' .format (addonID , urllib_parse .quote_plus (name ), urllib_parse .quote_plus (url )),))
@@ -617,12 +652,12 @@ def addLink(name, url, mode, iconimage, user, desc, duration, date, nr):
617652def addLiveLink (name , url , mode , iconimage , desc ):
618653 u = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], urllib_parse .quote_plus (url ), mode )
619654 ok = True
655+ liz = make_listitem (name = name , labels = {"Title" : name , "Plot" : desc })
620656 liz = xbmcgui .ListItem (name )
621657 liz .setArt ({'thumb' : iconimage ,
622658 'icon' : _icon ,
623659 'poster' : iconimage ,
624660 'fanart' : _fanart })
625- liz .setInfo (type = "Video" , infoLabels = {"Title" : name , "Plot" : desc })
626661 liz .setProperty ('IsPlayable' , 'true' )
627662 ok = xbmcplugin .addDirectoryItem (handle = int (sys .argv [1 ]), url = u , listitem = liz )
628663 return ok
@@ -631,25 +666,23 @@ def addLiveLink(name, url, mode, iconimage, desc):
631666def addDir (name , url , mode , iconimage , desc = "" ):
632667 u = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], urllib_parse .quote_plus (url ), mode )
633668 ok = True
634- liz = xbmcgui . ListItem (name )
669+ liz = make_listitem (name = name , labels = { "Title" : name , "Plot" : desc } )
635670 liz .setArt ({'thumb' : iconimage ,
636671 'icon' : _icon ,
637672 'poster' : iconimage ,
638673 'fanart' : _fanart })
639- liz .setInfo (type = "Video" , infoLabels = {"Title" : name , "Plot" : desc })
640674 ok = xbmcplugin .addDirectoryItem (handle = int (sys .argv [1 ]), url = u , listitem = liz , isFolder = True )
641675 return ok
642676
643677
644678def addUserDir (name , url , mode , iconimage , desc ):
645679 u = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], urllib_parse .quote_plus (url ), mode )
646680 ok = True
647- liz = xbmcgui . ListItem (name )
681+ liz = make_listitem (name = name , labels = { "Title" : name , "Plot" : desc } )
648682 liz .setArt ({'thumb' : iconimage ,
649683 'icon' : _icon ,
650684 'poster' : iconimage ,
651685 'fanart' : _fanart })
652- liz .setInfo (type = "Video" , infoLabels = {"Title" : name , "Plot" : desc })
653686 if dmUser == "" :
654687 playListInfos = "###MODE###=ADD###USER###={0}###THUMB###={1}###END###" .format (name , iconimage )
655688 liz .addContextMenuItems ([(translation (30028 ), 'RunPlugin(plugin://{0}/?mode=favourites&url={1})' .format (addonID , urllib_parse .quote_plus (playListInfos )),)])
@@ -660,12 +693,11 @@ def addUserDir(name, url, mode, iconimage, desc):
660693def addFavDir (name , url , mode , iconimage ):
661694 u = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], urllib_parse .quote_plus (url ), mode )
662695 ok = True
663- liz = xbmcgui . ListItem (name )
696+ liz = make_listitem (name = name , labels = { "Title" : name } )
664697 liz .setArt ({'thumb' : iconimage ,
665698 'icon' : _icon ,
666699 'poster' : iconimage ,
667700 'fanart' : _fanart })
668- liz .setInfo (type = "Video" , infoLabels = {"Title" : name })
669701 liz .addContextMenuItems ([(translation (30033 ), 'RunPlugin(plugin://{0}/?mode=addFav)' .format ('addonID' ),)])
670702 ok = xbmcplugin .addDirectoryItem (handle = int (sys .argv [1 ]), url = u , listitem = liz , isFolder = True )
671703 return ok
@@ -674,12 +706,11 @@ def addFavDir(name, url, mode, iconimage):
674706def addUserFavDir (name , url , mode , iconimage ):
675707 u = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], urllib_parse .quote_plus (url ), mode )
676708 ok = True
677- liz = xbmcgui . ListItem (name )
709+ liz = make_listitem (name = name , labels = { "Title" : name } )
678710 liz .setArt ({'thumb' : iconimage ,
679711 'icon' : _icon ,
680712 'poster' : iconimage ,
681713 'fanart' : _fanart })
682- liz .setInfo (type = "Video" , infoLabels = {"Title" : name })
683714 if dmUser == "" :
684715 playListInfos = "###MODE###=REMOVE###REFRESH###=TRUE###USER###={0}###THUMB###={1}###END###" .format (name , iconimage )
685716 liz .addContextMenuItems ([(translation (30029 ), 'RunPlugin(plugin://{0}/?mode=favourites&url={1})' .format (addonID , urllib_parse .quote_plus (playListInfos )),)])
@@ -743,12 +774,10 @@ def History():
743774 reversed_content = content [::- 1 ] # reverse order
744775 addHistoryDir (reversed_content )
745776 addDir ("[COLOR red]{0}[/COLOR]" .format (translation (30116 )), "" , "delHistory" , "{0}search.png" .format (_ipath ))
777+ xbmcplugin .endOfDirectory (pluginhandle , cacheToDisc = False )
746778 xbmcplugin .setContent (pluginhandle , "addons" )
747-
748- if force_mode :
749- xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
750-
751- xbmcplugin .endOfDirectory (pluginhandle , cacheToDisc = False )
779+ if force_mode :
780+ xbmc .executebuiltin ('Container.SetViewMode({0})' .format (menu_mode ))
752781
753782
754783def delHistory ():
@@ -761,13 +790,11 @@ def addHistoryDir(listofdicts):
761790 listoflists = []
762791
763792 for item in listofdicts :
764- list_item = xbmcgui .ListItem (label = item ["name" ])
765- list_item .setArt ({"thumb" : "{0}search.png" .format (_ipath ),
766- "icon" : "{0}search.png" .format (_ipath )})
767- list_item .setInfo (type = "Video" , infoLabels = {"genre" : "History" })
793+ liz = make_listitem (name = item ["name" ], labels = {"genre" : "History" })
794+ liz .setArt ({"thumb" : "{0}search.png" .format (_ipath ),
795+ "icon" : "{0}search.png" .format (_ipath )})
768796 url = "{0}?url={1}&mode={2}" .format (sys .argv [0 ], item ["url" ], item ["mode" ])
769-
770- listoflists .append ((url , list_item , True ))
797+ listoflists .append ((url , liz , True ))
771798
772799 ok = xbmcplugin .addDirectoryItems (pluginhandle , listoflists , len (listoflists ))
773800 return ok
0 commit comments