def parse_url_and_play(url, name, type_): from domains import parse_reddit_link, sitesBase, ydtl_get_playable_url, build_DirectoryItem_url_based_on_media_type log('parse_url_and_play url='+url) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) ld=parse_reddit_link(url,True, False, False ) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, url) if setProperty_IsPlayable=='true': log( '---------IsPlayable---------->'+ DirectoryItem_url) playVideo(DirectoryItem_url,'','') else: if isFolder: #showing album log( '---------using ActivateWindow------>'+ DirectoryItem_url) xbmc.executebuiltin('ActivateWindow(Videos,'+ DirectoryItem_url+')') else: #viewing image log( '---------using setResolvedUrl------>'+ DirectoryItem_url) listitem = xbmcgui.ListItem(path='') listitem.setProperty('IsPlayable', 'false') xbmcplugin.setResolvedUrl(pluginhandle, True, listitem) xbmc.executebuiltin('RunPlugin(%s)' % ( DirectoryItem_url ) )
def autoPlay(url, name, autoPlay_type): import random from domains import sitesBase, parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import unescape, post_is_filtered_out, log, clean_str from actions import setting_gif_repeat_count from reddit import reddit_request, determine_if_video_media_from_reddit_json gif_repeat_count=setting_gif_repeat_count() entries = [] playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() log("**********autoPlay %s*************" %autoPlay_type) content = reddit_request(url) if not content: return content = json.loads(content.replace('\\"', '\'')) log("Autoplay %s - Parsing %d items" %( autoPlay_type, len(content['data']['children']) ) ) for j_entry in content['data']['children']: try: if post_is_filtered_out( j_entry ): continue title = clean_str(j_entry, ['data','title']) try: media_url = j_entry['data']['url'] except: media_url = j_entry['data']['media']['oembed']['url'] is_a_video = determine_if_video_media_from_reddit_json(j_entry) ld=parse_reddit_link(link_url=media_url, assume_is_video=is_a_video, needs_preview=False, get_playable_url=True ) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, media_url, title, on_autoplay=True) if ld: if ld.media_type not in [sitesBase.TYPE_VIDEO, sitesBase.TYPE_GIF, sitesBase.TYPE_VIDS, sitesBase.TYPE_MIXED]: continue autoPlay_type_entries_append( entries, autoPlay_type, title, DirectoryItem_url) if ld.media_type == sitesBase.TYPE_GIF: for _ in range( 0, gif_repeat_count ): autoPlay_type_entries_append( entries, autoPlay_type, title, DirectoryItem_url) except Exception as e: log(" EXCEPTION Autoplay "+ str( sys.exc_info()[0]) + " " + str(e) ) if autoplayRandomize: random.shuffle(entries) for title, url in entries: listitem = xbmcgui.ListItem(title) playlist.add(url, listitem) log('add to playlist: %s %s' %(title.ljust(25)[:25],url )) xbmc.Player().play(playlist)
def listRelatedVideo(url,name,type_): #type_: 'channel' -other videos in the channel # 'related' -related videos #only youtube is supported for now from domains import ClassYoutube from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type match=re.compile( ClassYoutube.regex, re.I).findall( url ) if match: #log('***** isYouTubeable' + repr(link_url)) yt=ClassYoutube(url) links_dictList=yt.ret_album_list(type_) #returns a list of dict same as one used for albums if links_dictList: #log(pprint.pformat(links_dictList)) for _, d in enumerate(links_dictList): label=d.get('li_label') label2=d.get('li_label2') #li_iconImage=d.get('li_iconImage') ti=d.get('li_thumbnailImage') media_url=d.get('DirectoryItem_url') #media_type=d.get('type') #media_thumb=d.get('thumb') #isPlayable=d.get('isPlayable') #link_action=d.get('link_action') #channel_id=d.get('channel_id') #video_id=d.get('video_id') liz=xbmcgui.ListItem(label,label2) liz.setInfo( type='video', infoLabels=d['infoLabels'] ) #this tricks the skin to show the plot. where we stored the descriptions liz.setArt({"thumb": ti,'icon': ti, "poster":ti, "banner":ti, "fanart":ti, "landscape":ti }) #a little overkill considering we're only matching for youtube ld=parse_reddit_link(media_url) DirectoryItem_url, setProperty_IsPlayable, isFolder, _ = build_DirectoryItem_url_based_on_media_type(ld, media_url, '', '', script_to_call="") #directory_items.append( (url_for_DirectoryItem, liz, False,) ) liz.setProperty('IsPlayable', setProperty_IsPlayable) xbmcplugin.addDirectoryItem(pluginhandle, DirectoryItem_url, liz, isFolder) xbmcplugin.endOfDirectory(handle=pluginhandle, succeeded=True, updateListing=False, #setting this to True causes the ".." entry to quit the plugin cacheToDisc=True) else: xbmc_notify('Nothing to list', url) else: xbmc_notify('cannot identify youtube url', url)
def parse_url_and_play(url, name, type_): from domains import parse_reddit_link, sitesBase, ydtl_get_playable_url, build_DirectoryItem_url_based_on_media_type #from actions import viewImage log('parse_url_and_play url=' + url) #log('pluginhandle='+str(pluginhandle) ) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) ld = parse_reddit_link(url, True, False, False) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type( ld, url) if setProperty_IsPlayable == 'true': log('---------IsPlayable---------->' + DirectoryItem_url) playVideo(DirectoryItem_url, '', '') else: if isFolder: #showing album log('---------using ActivateWindow------>' + DirectoryItem_url) xbmc.executebuiltin('ActivateWindow(Videos,' + DirectoryItem_url + ')') else: #viewing image log('---------using setResolvedUrl------>' + DirectoryItem_url) #viewImage(DirectoryItem_url,'','' ) #error message after picture is displayed, kore remote will be unresponsive #playVideo(DirectoryItem_url,'','') #endless loop. picture windowxml opens after closing, opens again after closing.... #xbmc.executebuiltin('ActivateWindow(Videos,'+ DirectoryItem_url+')') #log( 'Container.Update(%s?path=%s?prl=zaza&mode=viewImage&url=%s)' % ( sys.argv[0], sys.argv[0], urllib.quote_plus(url) ) ) #xbmc.executebuiltin('Container.Update(%s?path=%s?prl=zaza&mode=viewImage&url=%s)' % ( sys.argv[0], sys.argv[0], urllib.quote_plus(url) ) ) listitem = xbmcgui.ListItem(path='') listitem.setProperty('IsPlayable', 'false') xbmcplugin.setResolvedUrl(pluginhandle, True, listitem) #DirectoryItem_url=DirectoryItem_url.replace('plugin://', 'script://') #xbmc.executebuiltin('RunScript(script.reddit.reader)' ) #xbmc.executebuiltin('RunScript(script.reddit.reader,mode=viewImage&url=%s)' %urllib.quote_plus(url) ) #xbmc.executebuiltin('RunPlugin(%s?path=%s?prl=zaza&mode=viewImage&url=%s)' % ( sys.argv[0], sys.argv[0], urllib.quote_plus(url) ) ) xbmc.executebuiltin('RunPlugin(%s)' % (DirectoryItem_url))
def parse_url_and_play(url, name, type_): from domains import parse_reddit_link, sitesBase, ydtl_get_playable_url, build_DirectoryItem_url_based_on_media_type #from actions import viewImage log('parse_url_and_play url='+url) #log('pluginhandle='+str(pluginhandle) ) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) ld=parse_reddit_link(url,True, False, False ) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, url) if setProperty_IsPlayable=='true': log( '---------IsPlayable---------->'+ DirectoryItem_url) playVideo(DirectoryItem_url,'','') else: if isFolder: #showing album log( '---------using ActivateWindow------>'+ DirectoryItem_url) xbmc.executebuiltin('ActivateWindow(Videos,'+ DirectoryItem_url+')') else: #viewing image log( '---------using setResolvedUrl------>'+ DirectoryItem_url) #viewImage(DirectoryItem_url,'','' ) #error message after picture is displayed, kore remote will be unresponsive #playVideo(DirectoryItem_url,'','') #endless loop. picture windowxml opens after closing, opens again after closing.... #xbmc.executebuiltin('ActivateWindow(Videos,'+ DirectoryItem_url+')') #log( 'Container.Update(%s?path=%s?prl=zaza&mode=viewImage&url=%s)' % ( sys.argv[0], sys.argv[0], urllib.quote_plus(url) ) ) #xbmc.executebuiltin('Container.Update(%s?path=%s?prl=zaza&mode=viewImage&url=%s)' % ( sys.argv[0], sys.argv[0], urllib.quote_plus(url) ) ) listitem = xbmcgui.ListItem(path='') listitem.setProperty('IsPlayable', 'false') xbmcplugin.setResolvedUrl(pluginhandle, True, listitem) #DirectoryItem_url=DirectoryItem_url.replace('plugin://', 'script://') #xbmc.executebuiltin('RunScript(script.reddit.reader)' ) #xbmc.executebuiltin('RunScript(script.reddit.reader,mode=viewImage&url=%s)' %urllib.quote_plus(url) ) #xbmc.executebuiltin('RunPlugin(%s?path=%s?prl=zaza&mode=viewImage&url=%s)' % ( sys.argv[0], sys.argv[0], urllib.quote_plus(url) ) ) xbmc.executebuiltin('RunPlugin(%s)' % ( DirectoryItem_url ) )
def listRelatedVideo(url,name,type_): from domains import ClassYoutube from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type match=re.compile( ClassYoutube.regex, re.I).findall( url ) if match: yt=ClassYoutube(url) links_dictList=yt.ret_album_list(type_) #returns a list of dict same as one used for albums if links_dictList: for _, d in enumerate(links_dictList): label=d.get('li_label') label2=d.get('li_label2') ti=d.get('li_thumbnailImage') media_url=d.get('DirectoryItem_url') liz=xbmcgui.ListItem(label,label2) liz.setInfo( type='video', infoLabels=d['infoLabels'] ) #this tricks the skin to show the plot. where we stored the descriptions liz.setArt({"thumb": ti,'icon': ti, "poster":ti, "banner":ti, "fanart":ti, "landscape":ti }) ld=parse_reddit_link(media_url) DirectoryItem_url, setProperty_IsPlayable, isFolder, _ = build_DirectoryItem_url_based_on_media_type(ld, media_url, '', '', script_to_call="") liz.setProperty('IsPlayable', setProperty_IsPlayable) xbmcplugin.addDirectoryItem(pluginhandle, DirectoryItem_url, liz, isFolder) xbmcplugin.endOfDirectory(handle=pluginhandle, succeeded=True, updateListing=False, #setting this to True causes the ".." entry to quit the plugin cacheToDisc=True) else: xbmc_notify('Nothing to list', url) else: xbmc_notify('cannot identify youtube url', url)
def listLinksInComment(url, name, type_): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import markdown_to_bbcode, unescape from guis import progressBG #from resources.domains import make_addon_url_from #called from context menu log('listLinksInComment:%s:%s' %(type_,url) ) #does not work for list comments coz key is the playable url (not reddit comments url) #msg=WINDOW.getProperty(url) #WINDOW.clearProperty( url ) #log( ' msg=' + msg ) directory_items=[] author="" ShowOnlyCommentsWithlink=False if type_=='linksOnly': ShowOnlyCommentsWithlink=True #url='https://www.reddit.com/r/Music/comments/4k02t1/bonnie_tyler_total_eclipse_of_the_heart_80s_pop/' + '.json' #only get up to "https://www.reddit.com/r/Music/comments/4k02t1". # do not include "/bonnie_tyler_total_eclipse_of_the_heart_80s_pop/" # because we'll have problem when it looks like this: "https://www.reddit.com/r/Overwatch/comments/4nx91h/ever_get_that_feeling_déjà _vu/" #url=re.findall(r'(.*/comments/[A-Za-z0-9]+)',url)[0] #use safe='' argument in quoteplus to encode only the weird chars part url=urllib.quote_plus(url,safe=':/?&') if '?' in url: url=url.split('?', 1)[0]+'.json?'+url.split('?', 1)[1] else: url+= '.json' loading_indicator=progressBG(translation(30024)) loading_indicator.update(0,'Retrieving comments') content = reddit_request(url) if not content: loading_indicator.end() return loading_indicator.update(10,'Parsing') content = json.loads(content) del harvest[:] #harvest links in the post text (just 1) r_linkHunter(content[0]['data']['children']) try:submitter=content[0]['data']['children'][0]['data']['author'] except: submitter='' #the post title is provided in json, we'll just use that instead of messages from addLink() try:post_title=content[0]['data']['children'][0]['data']['title'] except:post_title='' #for i, h in enumerate(harvest): # log("aaaaa first harvest "+h[2]) #harvest links in the post itself r_linkHunter(content[1]['data']['children']) comment_score=0 loading_indicator.set_tick_total(len(harvest)) for i, h in enumerate(harvest): try: #log(str(i)+" score:"+ str(h[0]).zfill(5)+" "+ h[1] +'|'+ h[3] ) comment_score=h[0] #log("score %d < %d (%s)" %(comment_score,int_CommentTreshold, CommentTreshold) ) link_url=h[2] desc100=h[3].replace('\n',' ')[0:100] #first 100 characters of description kind=h[6] #reddit uses t1 for user comments and t3 for OP text of the post. like a poster describing the post. d=h[5] #depth of the comment tab=" "*d if d>0 else "-" from urlparse import urlparse domain = '{uri.netloc}'.format( uri=urlparse( link_url ) ) author=h[7] DirectoryItem_url='' if comment_score < int_CommentTreshold: continue #hoster, DirectoryItem_url, videoID, mode_type, thumb_url,poster_url, isFolder,setInfo_type, setProperty_IsPlayable =make_addon_url_from(h[2]) #if link_url: # log( ' comment %s TITLE:%s... link[%s]' % ( str(d).zfill(3), desc100.ljust(20)[:20],link_url ) ) ld=parse_reddit_link(link_url=link_url, assume_is_video=False, needs_preview=True, get_playable_url=True ) if kind=='t1': list_title=r"[COLOR cadetblue]%3d[/COLOR] %s" %( h[0], tab ) elif kind=='t3': list_title=r"[COLOR cadetblue]Title [/COLOR] %s" %( tab ) #helps the the textbox control treat [url description] and (url) as separate words. so that they can be separated into 2 lines plot=h[3].replace('](', '] (') plot= markdown_to_bbcode(plot) plot=unescape(plot) #convert html entities e.g.:(') liz=xbmcgui.ListItem(label=list_title +': '+ desc100) liz.setInfo( type="Video", infoLabels={ "Title": h[1], "plot": plot, "studio": domain, "votes": str(comment_score), "director": author } ) isFolder=False #force all links to ytdl to see if it can be played if link_url: DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, link_url) liz.setProperty('IsPlayable', setProperty_IsPlayable) liz.setProperty('url', DirectoryItem_url) #<-- needed by the xml gui skin liz.setPath(DirectoryItem_url) if domain: plot= " [COLOR greenyellow][%s] %s"%(domain, plot ) + "[/COLOR]" else: plot= " [COLOR greenyellow][%s]"%( plot ) + "[/COLOR]" liz.setLabel(list_title+plot) if ld: liz.setArt({"thumb": ld.poster, "poster":ld.poster, "banner":ld.poster, "fanart":ld.poster, "landscape":ld.poster }) if DirectoryItem_url: #log( 'IsPlayable:'+setProperty_IsPlayable ) directory_items.append( (DirectoryItem_url, liz, isFolder,) ) #xbmcplugin.addDirectoryItem(handle=pluginhandle,url=DirectoryItem_url,listitem=liz,isFolder=isFolder) else: #this section are for comments that have no links if not ShowOnlyCommentsWithlink: result=h[3].replace('](', '] (') result=markdown_to_bbcode(result) liz=xbmcgui.ListItem(label=list_title + desc100) liz.setInfo( type="Video", infoLabels={ "Title": h[1], "plot": result, "studio": domain, "votes": str(h[0]), "director": author } ) liz.setProperty('IsPlayable', 'false') directory_items.append( ("", liz, False,) ) #xbmcplugin.addDirectoryItem(handle=pluginhandle,url="",listitem=liz,isFolder=False) #END section are for comments that have no links or unsupported links except Exception as e: log(' EXCEPTION:' + str(e) ) #for di in directory_items: # log( str(di) ) loading_indicator.tick(1, desc100) loading_indicator.end() #log(' comments_view id=%s' %comments_viewMode) #xbmcplugin.setContent(pluginhandle, "mixed") #in estuary, mixed have limited view id's available. it has widelist which is nice for comments but we'll just stick with 'movies' xbmcplugin.setContent(pluginhandle, "episodes") #files, songs, artists, albums, movies, tvshows, episodes, musicvideos xbmcplugin.setPluginCategory(pluginhandle,'Comments') xbmcplugin.addDirectoryItems(handle=pluginhandle, items=directory_items ) xbmcplugin.endOfDirectory(pluginhandle) if comments_viewMode: xbmc.executebuiltin('Container.SetViewMode(%s)' %comments_viewMode)
def addLink(title, title_line2, iconimage, previewimage,preview_w,preview_h,domain,description, credate, reddit_says_is_video, commentsUrl, subreddit, media_url, over_18, posted_by="", num_comments=0,post_index=1,post_id=''): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type post_title=title il_description="" n="" #will hold red nsfw asterisk string isFolder=True thumb_url='' h="[B]" + domain + "[/B]: " if over_18: mpaa="R" n = "[COLOR red]*[/COLOR] " #description = "[B]" + hoster + "[/B]:[COLOR red][NSFW][/COLOR] "+title+"\n" + description il_description = "[COLOR red][NSFW][/COLOR] "+ h+title+"[CR]" + "[COLOR grey]" + description + "[/COLOR]" else: mpaa="" n="" il_description = h+title+"[CR]" + "[COLOR grey]" + description + "[/COLOR]" if TitleAddtlInfo: #put the additional info on the description if setting set to single line titles #log( repr(title_line2 )) post_title=n+title+"[CR][LIGHT]"+title_line2+'[/LIGHT]' else: post_title=n+title il_description=title_line2+"[CR]"+il_description il={"title": post_title, "plot": il_description, "plotoutline": il_description, "Aired": credate, "mpaa": mpaa, "Genre": "r/"+subreddit, "studio": domain, "director": posted_by } #, "duration": 1271} (duration uses seconds for titan skin liz=xbmcgui.ListItem(label=post_title) #this is a video plugin, set type to video so that infolabels show up. liz.setInfo(type='video', infoLabels=il) if iconimage in ["","nsfw", "default"]: #log( title+ ' iconimage blank['+iconimage+']['+thumb_url+ ']media_url:'+media_url ) iconimage=thumb_url preview_ar=0.0 if (preview_w==0 or preview_h==0) != True: preview_ar=float(preview_w) / preview_h #log("preview ar: "+ repr(preview_ar)) if previewimage: needs_preview=False else: if iconimage: #some sites ban us if we send too many requests asking for preview image(meta og image) needs_preview=False previewimage=iconimage else: needs_preview=True #reddit has no thumbnail for this link. please get one #DirectoryItem_url=sys.argv[0]+"?url="+ urllib.quote_plus(media_url) +"&mode=play" if DoNotResolveLinks: ld=None DirectoryItem_url=sys.argv[0]\ +"?url="+ urllib.quote_plus(media_url) \ +"&name="+urllib.quote_plus(title) \ +"&mode=play" setProperty_IsPlayable='true' isFolder=False title_prefix='' else: ld=parse_reddit_link(media_url,reddit_says_is_video, needs_preview, False, preview_ar ) if needs_preview and ld: queried_preview_image= next((i for i in [ld.poster,ld.thumb] if i ), '') previewimage=queried_preview_image iconimage=ld.thumb arg_name=title arg_type=previewimage #if ld: #log(' ' + ld.media_type + ' -> ' + ld.link_action ) #log(' ***icon:' + ld.thumb + ' -> ' + ld.link_action ) #log(' ***poster:' + ld.poster + ' ' ) #if iconimage in ["","nsfw", "default"]: iconimage=ld.thumb DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, media_url, arg_name, arg_type, script_to_call="", on_autoplay=False, img_w=preview_w, img_h=preview_h) if title_prefix: liz.setLabel( title_prefix+' '+post_title ) liz.setProperty('IsPlayable', setProperty_IsPlayable) liz.setInfo('video', {"title": liz.getLabel(), } ) liz.setContentLookup(False) liz.setArt({"thumb": iconimage, "poster":previewimage, "banner":iconimage, "fanart":previewimage, "landscape":previewimage, }) entries = build_context_menu_entries(num_comments, commentsUrl, subreddit, domain, media_url, post_id) #entries for listbox for when you type 'c' or rt-click liz.addContextMenuItems(entries) #liz.setProperty('isFolder', isFolder) #liz.setPath(DirectoryItem_url) #log( 'playcount=' + repr(getPlayCount(DirectoryItem_url))) #log( 'DirectoryItem_url=' + DirectoryItem_url) #xbmcplugin.addDirectoryItem(pluginhandle, DirectoryItem_url, listitem=liz, isFolder=isFolder, totalItems=post_total) return (DirectoryItem_url,liz,isFolder) #tuple for addDirectoryItems
def listRelatedVideo(url, name, type_): #type_: 'channel' -other videos in the channel # 'related' -related videos #only youtube is supported for now from domains import ClassYoutube from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type match = re.compile(ClassYoutube.regex, re.I).findall(url) if match: #log('***** isYouTubeable' + repr(link_url)) yt = ClassYoutube(url) links_dictList = yt.ret_album_list( type_) #returns a list of dict same as one used for albums if links_dictList: #log(pprint.pformat(links_dictList)) for _, d in enumerate(links_dictList): label = d.get('li_label') label2 = d.get('li_label2') #li_iconImage=d.get('li_iconImage') ti = d.get('li_thumbnailImage') media_url = d.get('DirectoryItem_url') #media_type=d.get('type') #media_thumb=d.get('thumb') #isPlayable=d.get('isPlayable') #link_action=d.get('link_action') #channel_id=d.get('channel_id') #video_id=d.get('video_id') liz = xbmcgui.ListItem(label, label2) liz.setInfo( type='video', infoLabels=d['infoLabels'] ) #this tricks the skin to show the plot. where we stored the descriptions liz.setArt({ "thumb": ti, 'icon': ti, "poster": ti, "banner": ti, "fanart": ti, "landscape": ti }) #a little overkill considering we're only matching for youtube ld = parse_reddit_link(media_url) DirectoryItem_url, setProperty_IsPlayable, isFolder, _ = build_DirectoryItem_url_based_on_media_type( ld, media_url, '', '', script_to_call="") #directory_items.append( (url_for_DirectoryItem, liz, False,) ) liz.setProperty('IsPlayable', setProperty_IsPlayable) xbmcplugin.addDirectoryItem(pluginhandle, DirectoryItem_url, liz, isFolder) xbmcplugin.endOfDirectory( handle=pluginhandle, succeeded=True, updateListing= False, #setting this to True causes the ".." entry to quit the plugin cacheToDisc=True) else: xbmc_notify('Nothing to list', url) else: xbmc_notify('cannot identify youtube url', url)
def display_album_from(dictlist, album_name): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type, sitesBase from utils import build_script directory_items = [] album_viewMode = addon.getSetting("album_viewMode") if album_viewMode == '450': #using custom gui using_custom_gui = True else: using_custom_gui = False #log( repr(dictlist)) for _, d in enumerate(dictlist): ti = d['li_thumbnailImage'] media_url = d.get('DirectoryItem_url') #log(' display_album_from list:'+ media_url + " " ) #There is only 1 textbox for Title and description in our custom gui. # I don't know how to achieve this in the xml file so it is done here: # combine title and description without [CR] if label is empty. [B]$INFO[Container(53).ListItem.Label][/B][CR]$INFO[Container(53).ListItem.Plot] # new note: this is how it is done: # $INFO[Container(53).ListItem.Label,[B],[/B][CR]] $INFO[Container(53).ListItem.Plot] #if the infolabel is empty, nothing is printed for that block #combined = '[B]'+ d['li_label2'] + "[/B][CR]" if d['li_label2'] else "" combined = d['infoLabels'].get('plot') if d['infoLabels'].get( 'plot') else "" d['infoLabels']['plot'] = combined liz = xbmcgui.ListItem(label=d.get('li_label'), label2=d.get('li_label2')) #parse the link so that we can determine whether it is image or video. ld = parse_reddit_link(media_url) DirectoryItem_url, setProperty_IsPlayable, isFolder, _ = build_DirectoryItem_url_based_on_media_type( ld, media_url, '', '', script_to_call="") #log('isFolder:' + repr(isFolder)+ ' IsPlayable:'+repr(setProperty_IsPlayable) + ' DirectoryItem_url:' + repr(DirectoryItem_url)) if using_custom_gui: url_for_DirectoryItem = media_url liz.setProperty('onClick_action', DirectoryItem_url) liz.setProperty('is_video', 'true') #if setProperty_IsPlayable=='true': if ld: if ld.link_action == sitesBase.DI_ACTION_PLAYABLE: liz.setProperty('item_type', 'playable') else: #this part is for playing video that needs to be resolved first. (youtube_dl) #I could not get this to work --> #Attempt to use invalid handle -1 #I think you can't setresolvedUrl a listitem from a custom gui #url_for_DirectoryItem=DirectoryItem_url liz.setProperty('item_type', 'script') else: #sys.argv[0]+"?url="+ urllib.quote_plus(d['DirectoryItem_url']) +"&mode=viewImage" #with xbmc's standard gui, we need to specify to call the plugin to open the gui that shows image #log('***'+'isFolder:' + repr(isFolder)+ ' IsPlayable:'+repr(setProperty_IsPlayable) +'**[diu]:'+ DirectoryItem_url) liz.setProperty('IsPlayable', setProperty_IsPlayable) url_for_DirectoryItem = DirectoryItem_url liz.setInfo( type='video', infoLabels=d['infoLabels'] ) #this tricks the skin to show the plot. where we stored the picture descriptions liz.setArt({ "thumb": ti, 'icon': ti, "poster": media_url, "banner": media_url, "fanart": media_url, "landscape": media_url }) directory_items.append((url_for_DirectoryItem, liz, isFolder)) if using_custom_gui: from guis import cGUI li = [] for di in directory_items: li.append(di[1]) ui = cGUI('view_450_slideshow.xml', addon_path, defaultSkin='Default', defaultRes='1080i', listing=li, id=53) ui.include_parent_directory_entry = False ui.doModal() del ui else: if album_viewMode != '0': xbmc.executebuiltin('Container.SetViewMode(' + album_viewMode + ')') xbmcplugin.addDirectoryItems(handle=pluginhandle, items=directory_items) xbmcplugin.endOfDirectory(pluginhandle)
def listLinksInComment(url, name, type_): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import markdown_to_bbcode, unescape from guis import progressBG log('listLinksInComment:%s:%s' %(type_,url) ) directory_items=[] author="" ShowOnlyCommentsWithlink=False if type_=='linksOnly': ShowOnlyCommentsWithlink=True url=urllib.quote_plus(url,safe=':/?&') if '?' in url: url=url.split('?', 1)[0]+'.json?'+url.split('?', 1)[1] else: url+= '.json' loading_indicator=progressBG(translation(30024)) loading_indicator.update(0,'Retrieving comments') content = reddit_request(url) if not content: loading_indicator.end() return loading_indicator.update(10,'Parsing') content = json.loads(content) del harvest[:] r_linkHunter(content[0]['data']['children']) try:submitter=content[0]['data']['children'][0]['data']['author'] except: submitter='' try:post_title=content[0]['data']['children'][0]['data']['title'] except:post_title='' r_linkHunter(content[1]['data']['children']) comment_score=0 loading_indicator.set_tick_total(len(harvest)) for i, h in enumerate(harvest): try: comment_score=h[0] link_url=h[2] desc100=h[3].replace('\n',' ')[0:100] #first 100 characters of description kind=h[6] #reddit uses t1 for user comments and t3 for OP text of the post. like a poster describing the post. d=h[5] #depth of the comment tab=" "*d if d>0 else "-" from urlparse import urlparse domain = '{uri.netloc}'.format( uri=urlparse( link_url ) ) author=h[7] DirectoryItem_url='' if comment_score < int_CommentTreshold: continue ld=parse_reddit_link(link_url=link_url, assume_is_video=False, needs_preview=True, get_playable_url=True ) if kind=='t1': list_title=r"[COLOR cadetblue]%3d[/COLOR] %s" %( h[0], tab ) elif kind=='t3': list_title=r"[COLOR cadetblue]Title [/COLOR] %s" %( tab ) plot=h[3].replace('](', '] (') plot= markdown_to_bbcode(plot) plot=unescape(plot) #convert html entities e.g.:(') liz=xbmcgui.ListItem(label=list_title +': '+ desc100) liz.setInfo( type="Video", infoLabels={ "Title": h[1], "plot": plot, "studio": domain, "votes": str(comment_score), "director": author } ) isFolder=False if link_url: DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, link_url) liz.setProperty('IsPlayable', setProperty_IsPlayable) liz.setProperty('url', DirectoryItem_url) #<-- needed by the xml gui skin liz.setPath(DirectoryItem_url) if domain: plot= " [COLOR greenyellow][%s] %s"%(domain, plot ) + "[/COLOR]" else: plot= " [COLOR greenyellow][%s]"%( plot ) + "[/COLOR]" liz.setLabel(list_title+plot) if ld: liz.setArt({"thumb": ld.poster, "poster":ld.poster, "banner":ld.poster, "fanart":ld.poster, "landscape":ld.poster }) if DirectoryItem_url: directory_items.append( (DirectoryItem_url, liz, isFolder,) ) else: if not ShowOnlyCommentsWithlink: result=h[3].replace('](', '] (') result=markdown_to_bbcode(result) liz=xbmcgui.ListItem(label=list_title + desc100) liz.setInfo( type="Video", infoLabels={ "Title": h[1], "plot": result, "studio": domain, "votes": str(h[0]), "director": author } ) liz.setProperty('IsPlayable', 'false') directory_items.append( ("", liz, False,) ) except Exception as e: log(' EXCEPTION:' + str(e) ) loading_indicator.tick(1, desc100) loading_indicator.end() xbmcplugin.setContent(pluginhandle, "movies") #files, songs, artists, albums, movies, tvshows, episodes, musicvideos xbmcplugin.setPluginCategory(pluginhandle,'Comments') xbmcplugin.addDirectoryItems(handle=pluginhandle, items=directory_items ) xbmcplugin.endOfDirectory(pluginhandle) if comments_viewMode: xbmc.executebuiltin('Container.SetViewMode(%s)' %comments_viewMode)
def addLink(title, title_line2, iconimage, previewimage, preview_w, preview_h, domain, description, credate, reddit_says_is_video, commentsUrl, subreddit, media_url, over_18, posted_by="", num_comments=0, post_index=1, post_id=''): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type post_title = title il_description = "" n = "" #will hold red nsfw asterisk string isFolder = True thumb_url = '' h = "[B]" + domain + "[/B]: " if over_18: mpaa = "R" n = "[COLOR red]*[/COLOR] " #description = "[B]" + hoster + "[/B]:[COLOR red][NSFW][/COLOR] "+title+"\n" + description il_description = "[COLOR red][NSFW][/COLOR] " + h + title + "[CR]" + "[COLOR grey]" + description + "[/COLOR]" else: mpaa = "" n = "" il_description = h + title + "[CR]" + "[COLOR grey]" + description + "[/COLOR]" if TitleAddtlInfo: #put the additional info on the description if setting set to single line titles #log( repr(title_line2 )) post_title = n + title + "[CR][LIGHT]" + title_line2 + '[/LIGHT]' else: post_title = n + title il_description = title_line2 + "[CR]" + il_description il = { "title": post_title, "plot": il_description, "plotoutline": il_description, "Aired": credate, "mpaa": mpaa, "Genre": "r/" + subreddit, "studio": domain, "director": posted_by } #, "duration": 1271} (duration uses seconds for titan skin liz = xbmcgui.ListItem(label=post_title) #this is a video plugin, set type to video so that infolabels show up. liz.setInfo(type='video', infoLabels=il) if iconimage in ["", "nsfw", "default"]: #log( title+ ' iconimage blank['+iconimage+']['+thumb_url+ ']media_url:'+media_url ) iconimage = thumb_url preview_ar = 0.0 if (preview_w == 0 or preview_h == 0) != True: preview_ar = float(preview_w) / preview_h #log("preview ar: "+ repr(preview_ar)) if previewimage: needs_preview = False else: if iconimage: #some sites ban us if we send too many requests asking for preview image(meta og image) needs_preview = False previewimage = iconimage else: needs_preview = True #reddit has no thumbnail for this link. please get one #DirectoryItem_url=sys.argv[0]+"?url="+ urllib.quote_plus(media_url) +"&mode=play" if DoNotResolveLinks: ld = None DirectoryItem_url=sys.argv[0]\ +"?url="+ urllib.quote_plus(media_url) \ +"&name="+urllib.quote_plus(title) \ +"&mode=play" setProperty_IsPlayable = 'true' isFolder = False title_prefix = '' else: ld = parse_reddit_link(media_url, reddit_says_is_video, needs_preview, False, preview_ar) if needs_preview and ld: queried_preview_image = next( (i for i in [ld.poster, ld.thumb] if i), '') previewimage = queried_preview_image iconimage = ld.thumb arg_name = title arg_type = previewimage #if ld: #log(' ' + ld.media_type + ' -> ' + ld.link_action ) #log(' ***icon:' + ld.thumb + ' -> ' + ld.link_action ) #log(' ***poster:' + ld.poster + ' ' ) #if iconimage in ["","nsfw", "default"]: iconimage=ld.thumb DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type( ld, media_url, arg_name, arg_type, script_to_call="", on_autoplay=False, img_w=preview_w, img_h=preview_h) if title_prefix: liz.setLabel(title_prefix + ' ' + post_title) liz.setProperty('IsPlayable', setProperty_IsPlayable) liz.setInfo('video', { "title": liz.getLabel(), }) liz.setContentLookup(False) liz.setArt({ "thumb": iconimage, "poster": previewimage, "banner": iconimage, "fanart": previewimage, "landscape": previewimage, }) entries = build_context_menu_entries( num_comments, commentsUrl, subreddit, domain, media_url, post_id) #entries for listbox for when you type 'c' or rt-click liz.addContextMenuItems(entries) #liz.setProperty('isFolder', isFolder) #liz.setPath(DirectoryItem_url) #log( 'playcount=' + repr(getPlayCount(DirectoryItem_url))) #log( 'DirectoryItem_url=' + DirectoryItem_url) #xbmcplugin.addDirectoryItem(pluginhandle, DirectoryItem_url, listitem=liz, isFolder=isFolder, totalItems=post_total) return (DirectoryItem_url, liz, isFolder) #tuple for addDirectoryItems
def display_album_from(dictlist, album_name): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type, sitesBase from utils import build_script directory_items=[] album_viewMode=addon.getSetting("album_viewMode") if album_viewMode=='450': #using custom gui using_custom_gui=True else: using_custom_gui=False for _, d in enumerate(dictlist): ti=d['li_thumbnailImage'] media_url=d.get('DirectoryItem_url') combined = d['infoLabels'].get('plot') if d['infoLabels'].get('plot') else "" d['infoLabels']['plot'] = combined liz=xbmcgui.ListItem(label=d.get('li_label'), label2=d.get('li_label2') ) ld=parse_reddit_link(media_url) DirectoryItem_url, setProperty_IsPlayable, isFolder, _ = build_DirectoryItem_url_based_on_media_type(ld, media_url, '', '', script_to_call="") if using_custom_gui: url_for_DirectoryItem=media_url liz.setProperty('onClick_action', DirectoryItem_url ) liz.setProperty('is_video','true') if ld.link_action == sitesBase.DI_ACTION_PLAYABLE: liz.setProperty('item_type','playable') else: liz.setProperty('item_type','script') else: liz.setProperty('IsPlayable',setProperty_IsPlayable) url_for_DirectoryItem=DirectoryItem_url liz.setInfo( type='video', infoLabels=d['infoLabels'] ) #this tricks the skin to show the plot. where we stored the picture descriptions liz.setArt({"thumb": ti,'icon': ti, "poster":media_url, "banner":media_url, "fanart":media_url, "landscape":media_url }) directory_items.append( (url_for_DirectoryItem, liz, isFolder) ) if using_custom_gui: from guis import cGUI li=[] for di in directory_items: li.append( di[1] ) ui = cGUI('view_450_slideshow.xml' , addon_path, defaultSkin='Default', defaultRes='1080i', listing=li, id=53) ui.include_parent_directory_entry=False ui.doModal() del ui else: if album_viewMode!='0': xbmc.executebuiltin('Container.SetViewMode('+album_viewMode+')') xbmcplugin.addDirectoryItems(handle=pluginhandle, items=directory_items ) xbmcplugin.endOfDirectory(pluginhandle)
def display_album_from(dictlist, album_name): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type, sitesBase from utils import build_script directory_items=[] album_viewMode=addon.getSetting("album_viewMode") if album_viewMode=='450': #using custom gui using_custom_gui=True else: using_custom_gui=False #log( repr(dictlist)) for _, d in enumerate(dictlist): ti=d['li_thumbnailImage'] media_url=d.get('DirectoryItem_url') #log(' display_album_from list:'+ media_url + " " ) #There is only 1 textbox for Title and description in our custom gui. # I don't know how to achieve this in the xml file so it is done here: # combine title and description without [CR] if label is empty. [B]$INFO[Container(53).ListItem.Label][/B][CR]$INFO[Container(53).ListItem.Plot] # new note: this is how it is done: # $INFO[Container(53).ListItem.Label,[B],[/B][CR]] $INFO[Container(53).ListItem.Plot] #if the infolabel is empty, nothing is printed for that block #combined = '[B]'+ d['li_label2'] + "[/B][CR]" if d['li_label2'] else "" combined = d['infoLabels'].get('plot') if d['infoLabels'].get('plot') else "" d['infoLabels']['plot'] = combined liz=xbmcgui.ListItem(label=d.get('li_label'), label2=d.get('li_label2') ) #parse the link so that we can determine whether it is image or video. ld=parse_reddit_link(media_url) DirectoryItem_url, setProperty_IsPlayable, isFolder, _ = build_DirectoryItem_url_based_on_media_type(ld, media_url, '', '', script_to_call="") #log('isFolder:' + repr(isFolder)+ ' IsPlayable:'+repr(setProperty_IsPlayable) + ' DirectoryItem_url:' + repr(DirectoryItem_url)) if using_custom_gui: url_for_DirectoryItem=media_url liz.setProperty('onClick_action', DirectoryItem_url ) liz.setProperty('is_video','true') #if setProperty_IsPlayable=='true': if ld: if ld.link_action == sitesBase.DI_ACTION_PLAYABLE: liz.setProperty('item_type','playable') else: #this part is for playing video that needs to be resolved first. (youtube_dl) #I could not get this to work --> #Attempt to use invalid handle -1 #I think you can't setresolvedUrl a listitem from a custom gui #url_for_DirectoryItem=DirectoryItem_url liz.setProperty('item_type','script') else: #sys.argv[0]+"?url="+ urllib.quote_plus(d['DirectoryItem_url']) +"&mode=viewImage" #with xbmc's standard gui, we need to specify to call the plugin to open the gui that shows image #log('***'+'isFolder:' + repr(isFolder)+ ' IsPlayable:'+repr(setProperty_IsPlayable) +'**[diu]:'+ DirectoryItem_url) liz.setProperty('IsPlayable',setProperty_IsPlayable) url_for_DirectoryItem=DirectoryItem_url liz.setInfo( type='video', infoLabels=d['infoLabels'] ) #this tricks the skin to show the plot. where we stored the picture descriptions liz.setArt({"thumb": ti,'icon': ti, "poster":media_url, "banner":media_url, "fanart":media_url, "landscape":media_url }) directory_items.append( (url_for_DirectoryItem, liz, isFolder) ) if using_custom_gui: from guis import cGUI li=[] for di in directory_items: li.append( di[1] ) ui = cGUI('view_450_slideshow.xml' , addon_path, defaultSkin='Default', defaultRes='1080i', listing=li, id=53) ui.include_parent_directory_entry=False ui.doModal() del ui else: if album_viewMode!='0': xbmc.executebuiltin('Container.SetViewMode('+album_viewMode+')') xbmcplugin.addDirectoryItems(handle=pluginhandle, items=directory_items ) xbmcplugin.endOfDirectory(pluginhandle)
def autoPlay(url, name, autoPlay_type): import random from domains import sitesBase, parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import unescape, post_is_filtered_out, log, clean_str from actions import setting_gif_repeat_count from reddit import reddit_request, determine_if_video_media_from_reddit_json gif_repeat_count = setting_gif_repeat_count() entries = [] playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() log("**********autoPlay %s*************" % autoPlay_type) content = reddit_request(url) if not content: return content = json.loads(content.replace('\\"', '\'')) log("Autoplay %s - Parsing %d items" % (autoPlay_type, len(content['data']['children']))) for j_entry in content['data']['children']: try: if post_is_filtered_out(j_entry): continue title = clean_str(j_entry, ['data', 'title']) try: media_url = j_entry['data']['url'] except: media_url = j_entry['data']['media']['oembed']['url'] is_a_video = determine_if_video_media_from_reddit_json(j_entry) ld = parse_reddit_link(link_url=media_url, assume_is_video=is_a_video, needs_preview=False, get_playable_url=True) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type( ld, media_url, title, on_autoplay=True) if ld: if ld.media_type not in [ sitesBase.TYPE_VIDEO, sitesBase.TYPE_GIF, sitesBase.TYPE_VIDS, sitesBase.TYPE_MIXED ]: continue autoPlay_type_entries_append(entries, autoPlay_type, title, DirectoryItem_url) if ld.media_type == sitesBase.TYPE_GIF: for _ in range(0, gif_repeat_count): autoPlay_type_entries_append(entries, autoPlay_type, title, DirectoryItem_url) except Exception as e: log(" EXCEPTION Autoplay " + str(sys.exc_info()[0]) + " " + str(e)) if autoplayRandomize: random.shuffle(entries) for title, url in entries: listitem = xbmcgui.ListItem(title) playlist.add(url, listitem) log('add to playlist: %s %s' % (title.ljust(25)[:25], url)) xbmc.Player().play(playlist)
def autoPlay(url, name, autoPlay_type): import random from domains import sitesBase, parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import unescape, post_is_filtered_out, log, clean_str from actions import setting_gif_repeat_count from reddit import reddit_request, determine_if_video_media_from_reddit_json #collect a list of title and urls as entries[] from the j_entries obtained from reddit #then create a playlist from those entries #then play the playlist gif_repeat_count=setting_gif_repeat_count() entries = [] playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() log("**********autoPlay %s*************" %autoPlay_type) content = reddit_request(url) if not content: return content = json.loads(content.replace('\\"', '\'')) log("Autoplay %s - Parsing %d items" %( autoPlay_type, len(content['data']['children']) ) ) for j_entry in content['data']['children']: try: if post_is_filtered_out( j_entry ): continue title = clean_str(j_entry, ['data','title']) try: media_url = j_entry['data']['url'] except: media_url = j_entry['data']['media']['oembed']['url'] is_a_video = determine_if_video_media_from_reddit_json(j_entry) #log(" Title:%s -%c %s" %( title, ("v" if is_a_video else " "), media_url ) ) #hoster, DirectoryItem_url, videoID, mode_type, thumb_url,poster_url, isFolder,setInfo_type, IsPlayable=make_addon_url_from(media_url,is_a_video) ld=parse_reddit_link(link_url=media_url, assume_is_video=is_a_video, needs_preview=False, get_playable_url=True ) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, media_url, title, on_autoplay=True) if ld: if ld.media_type not in [sitesBase.TYPE_VIDEO, sitesBase.TYPE_GIF, sitesBase.TYPE_VIDS, sitesBase.TYPE_MIXED]: continue autoPlay_type_entries_append( entries, autoPlay_type, title, DirectoryItem_url) if ld.media_type == sitesBase.TYPE_GIF: for _ in range( 0, gif_repeat_count ): autoPlay_type_entries_append( entries, autoPlay_type, title, DirectoryItem_url) except Exception as e: log(" EXCEPTION Autoplay "+ str( sys.exc_info()[0]) + " " + str(e) ) #def k2(x): return x[1] #entries=remove_duplicates(entries, k2) if autoplayRandomize: random.shuffle(entries) #for title, url in entries: # log(" added to playlist:"+ title + " " + urllib.unquote_plus(url) ) for title, url in entries: listitem = xbmcgui.ListItem(title) playlist.add(url, listitem) log('add to playlist: %s %s' %(title.ljust(25)[:25],url )) xbmc.Player().play(playlist)
def autoPlay(url, name, autoPlay_type): import random from domains import sitesBase, parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import unescape, post_is_filtered_out, log, clean_str from actions import setting_gif_repeat_count from reddit import reddit_request, determine_if_video_media_from_reddit_json #collect a list of title and urls as entries[] from the j_entries obtained from reddit #then create a playlist from those entries #then play the playlist gif_repeat_count = setting_gif_repeat_count() entries = [] playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() log("**********autoPlay %s*************" % autoPlay_type) content = reddit_request(url) if not content: return content = json.loads(content.replace('\\"', '\'')) log("Autoplay %s - Parsing %d items" % (autoPlay_type, len(content['data']['children']))) for j_entry in content['data']['children']: try: if post_is_filtered_out(j_entry): continue title = clean_str(j_entry, ['data', 'title']) try: media_url = j_entry['data']['url'] except: media_url = j_entry['data']['media']['oembed']['url'] is_a_video = determine_if_video_media_from_reddit_json(j_entry) #log(" Title:%s -%c %s" %( title, ("v" if is_a_video else " "), media_url ) ) #hoster, DirectoryItem_url, videoID, mode_type, thumb_url,poster_url, isFolder,setInfo_type, IsPlayable=make_addon_url_from(media_url,is_a_video) ld = parse_reddit_link(link_url=media_url, assume_is_video=is_a_video, needs_preview=False, get_playable_url=True) DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type( ld, media_url, title, on_autoplay=True) if ld: if ld.media_type not in [ sitesBase.TYPE_VIDEO, sitesBase.TYPE_GIF, sitesBase.TYPE_VIDS, sitesBase.TYPE_MIXED ]: continue autoPlay_type_entries_append(entries, autoPlay_type, title, DirectoryItem_url) if ld.media_type == sitesBase.TYPE_GIF: for _ in range(0, gif_repeat_count): autoPlay_type_entries_append(entries, autoPlay_type, title, DirectoryItem_url) except Exception as e: log(" EXCEPTION Autoplay " + str(sys.exc_info()[0]) + " " + str(e)) #def k2(x): return x[1] #entries=remove_duplicates(entries, k2) if autoplayRandomize: random.shuffle(entries) #for title, url in entries: # log(" added to playlist:"+ title + " " + urllib.unquote_plus(url) ) for title, url in entries: listitem = xbmcgui.ListItem(title) playlist.add(url, listitem) log('add to playlist: %s %s' % (title.ljust(25)[:25], url)) xbmc.Player().play(playlist)
def listLinksInComment(url, name, type_): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type from utils import markdown_to_bbcode, unescape from guis import progressBG #from resources.domains import make_addon_url_from #called from context menu log('listLinksInComment:%s:%s' % (type_, url)) #does not work for list comments coz key is the playable url (not reddit comments url) #msg=WINDOW.getProperty(url) #WINDOW.clearProperty( url ) #log( ' msg=' + msg ) directory_items = [] author = "" ShowOnlyCommentsWithlink = False if type_ == 'linksOnly': ShowOnlyCommentsWithlink = True #url='https://www.reddit.com/r/Music/comments/4k02t1/bonnie_tyler_total_eclipse_of_the_heart_80s_pop/' + '.json' #only get up to "https://www.reddit.com/r/Music/comments/4k02t1". # do not include "/bonnie_tyler_total_eclipse_of_the_heart_80s_pop/" # because we'll have problem when it looks like this: "https://www.reddit.com/r/Overwatch/comments/4nx91h/ever_get_that_feeling_déjà _vu/" #url=re.findall(r'(.*/comments/[A-Za-z0-9]+)',url)[0] #use safe='' argument in quoteplus to encode only the weird chars part url = urllib.quote_plus(url, safe=':/?&') if '?' in url: url = url.split('?', 1)[0] + '.json?' + url.split('?', 1)[1] else: url += '.json' loading_indicator = progressBG(translation(30024)) loading_indicator.update(0, 'Retrieving comments') content = reddit_request(url) if not content: loading_indicator.end() return loading_indicator.update(10, 'Parsing') content = json.loads(content) del harvest[:] #harvest links in the post text (just 1) r_linkHunter(content[0]['data']['children']) try: submitter = content[0]['data']['children'][0]['data']['author'] except: submitter = '' #the post title is provided in json, we'll just use that instead of messages from addLink() try: post_title = content[0]['data']['children'][0]['data']['title'] except: post_title = '' #for i, h in enumerate(harvest): # log("aaaaa first harvest "+h[2]) #harvest links in the post itself r_linkHunter(content[1]['data']['children']) comment_score = 0 loading_indicator.set_tick_total(len(harvest)) for i, h in enumerate(harvest): try: #log(str(i)+" score:"+ str(h[0]).zfill(5)+" "+ h[1] +'|'+ h[3] ) comment_score = h[0] #log("score %d < %d (%s)" %(comment_score,int_CommentTreshold, CommentTreshold) ) link_url = h[2] desc100 = h[3].replace( '\n', ' ')[0:100] #first 100 characters of description kind = h[ 6] #reddit uses t1 for user comments and t3 for OP text of the post. like a poster describing the post. d = h[5] #depth of the comment tab = " " * d if d > 0 else "-" from urlparse import urlparse domain = '{uri.netloc}'.format(uri=urlparse(link_url)) author = h[7] DirectoryItem_url = '' if comment_score < int_CommentTreshold: continue #hoster, DirectoryItem_url, videoID, mode_type, thumb_url,poster_url, isFolder,setInfo_type, setProperty_IsPlayable =make_addon_url_from(h[2]) #if link_url: # log( ' comment %s TITLE:%s... link[%s]' % ( str(d).zfill(3), desc100.ljust(20)[:20],link_url ) ) ld = parse_reddit_link(link_url=link_url, assume_is_video=False, needs_preview=True, get_playable_url=True) if kind == 't1': list_title = r"[COLOR cadetblue]%3d[/COLOR] %s" % (h[0], tab) elif kind == 't3': list_title = r"[COLOR cadetblue]Title [/COLOR] %s" % (tab) #helps the the textbox control treat [url description] and (url) as separate words. so that they can be separated into 2 lines plot = h[3].replace('](', '] (') plot = markdown_to_bbcode(plot) plot = unescape(plot) #convert html entities e.g.:(') liz = xbmcgui.ListItem(label=list_title + ': ' + desc100) liz.setInfo(type="Video", infoLabels={ "Title": h[1], "plot": plot, "studio": domain, "votes": str(comment_score), "director": author }) isFolder = False #force all links to ytdl to see if it can be played if link_url: DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type( ld, link_url) liz.setProperty('IsPlayable', setProperty_IsPlayable) liz.setProperty( 'url', DirectoryItem_url) #<-- needed by the xml gui skin liz.setPath(DirectoryItem_url) if domain: plot = " [COLOR greenyellow][%s] %s" % (domain, plot) + "[/COLOR]" else: plot = " [COLOR greenyellow][%s]" % (plot) + "[/COLOR]" liz.setLabel(list_title + plot) if ld: liz.setArt({ "thumb": ld.poster, "poster": ld.poster, "banner": ld.poster, "fanart": ld.poster, "landscape": ld.poster }) if DirectoryItem_url: #log( 'IsPlayable:'+setProperty_IsPlayable ) directory_items.append(( DirectoryItem_url, liz, isFolder, )) #xbmcplugin.addDirectoryItem(handle=pluginhandle,url=DirectoryItem_url,listitem=liz,isFolder=isFolder) else: #this section are for comments that have no links if not ShowOnlyCommentsWithlink: result = h[3].replace('](', '] (') result = markdown_to_bbcode(result) liz = xbmcgui.ListItem(label=list_title + desc100) liz.setInfo(type="Video", infoLabels={ "Title": h[1], "plot": result, "studio": domain, "votes": str(h[0]), "director": author }) liz.setProperty('IsPlayable', 'false') directory_items.append(( "", liz, False, )) #xbmcplugin.addDirectoryItem(handle=pluginhandle,url="",listitem=liz,isFolder=False) #END section are for comments that have no links or unsupported links except Exception as e: log(' EXCEPTION:' + str(e)) #for di in directory_items: # log( str(di) ) loading_indicator.tick(1, desc100) loading_indicator.end() #log(' comments_view id=%s' %comments_viewMode) #xbmcplugin.setContent(pluginhandle, "mixed") #in estuary, mixed have limited view id's available. it has widelist which is nice for comments but we'll just stick with 'movies' xbmcplugin.setContent( pluginhandle, "episodes" ) #files, songs, artists, albums, movies, tvshows, episodes, musicvideos xbmcplugin.setPluginCategory(pluginhandle, 'Comments') xbmcplugin.addDirectoryItems(handle=pluginhandle, items=directory_items) xbmcplugin.endOfDirectory(pluginhandle) if comments_viewMode: xbmc.executebuiltin('Container.SetViewMode(%s)' % comments_viewMode)
def addLink(title, title_line2, iconimage, previewimage,preview_w,preview_h,domain,description, credate, reddit_says_is_video, commentsUrl, subreddit, media_url, over_18, posted_by="", num_comments=0,post_index=1,post_id=''): from domains import parse_reddit_link, build_DirectoryItem_url_based_on_media_type post_title=title il_description="" n="" #will hold red nsfw asterisk string isFolder=True thumb_url='' h="[B]" + domain + "[/B]: " if over_18: mpaa="R" n = "[COLOR red]*[/COLOR] " il_description = "[COLOR red][NSFW][/COLOR] "+ h+title+"[CR]" + "[COLOR grey]" + description + "[/COLOR]" else: mpaa="" n="" il_description = h+title+"[CR]" + "[COLOR grey]" + description + "[/COLOR]" if TitleAddtlInfo: #put the additional info on the description if setting set to single line titles post_title=n+title+"[CR][LIGHT]"+title_line2+'[/LIGHT]' else: post_title=n+title il_description=title_line2+"[CR]"+il_description il={"title": post_title, "plot": il_description, "plotoutline": il_description, "Aired": credate, "mpaa": mpaa, "Genre": "r/"+subreddit, "studio": domain, "director": posted_by } #, "duration": 1271} (duration uses seconds for titan skin liz=xbmcgui.ListItem(label=post_title) liz.setInfo(type='video', infoLabels=il) if iconimage in ["","nsfw", "default"]: iconimage=thumb_url preview_ar=0.0 if (preview_w==0 or preview_h==0) != True: preview_ar=float(preview_w) / preview_h if previewimage: needs_preview=False else: needs_preview=True #reddit has no thumbnail for this link. please get one if DoNotResolveLinks: ld=None DirectoryItem_url=sys.argv[0]\ +"?url="+ urllib.quote_plus(media_url) \ +"&name="+urllib.quote_plus(title) \ +"&mode=play" setProperty_IsPlayable='true' isFolder=False title_prefix='' else: ld=parse_reddit_link(media_url,reddit_says_is_video, needs_preview, False, preview_ar ) if needs_preview and ld: queried_preview_image= next((i for i in [ld.poster,ld.thumb] if i ), '') previewimage=queried_preview_image iconimage=ld.thumb arg_name=title arg_type=previewimage DirectoryItem_url, setProperty_IsPlayable, isFolder, title_prefix = build_DirectoryItem_url_based_on_media_type(ld, media_url, arg_name, arg_type, script_to_call="", on_autoplay=False, img_w=preview_w, img_h=preview_h) if title_prefix: liz.setLabel( title_prefix+' '+post_title ) liz.setProperty('IsPlayable', setProperty_IsPlayable) liz.setInfo('video', {"title": liz.getLabel(), } ) liz.setArt({"thumb": iconimage, "poster":previewimage, "banner":iconimage, "fanart":previewimage, "landscape":previewimage, }) entries = build_context_menu_entries(num_comments, commentsUrl, subreddit, domain, media_url, post_id) #entries for listbox for when you type 'c' or rt-click liz.addContextMenuItems(entries) return (DirectoryItem_url,liz,isFolder) #tuple for addDirectoryItems