def addSubreddit(subreddit, name, type_): from utils import colored_subreddit from reddit import this_is_a_multireddit, format_multihub alreadyIn = False with open(subredditsFile, 'r') as fh: content = fh.readlines() if subreddit: for line in content: if line.lower()==subreddit.lower(): alreadyIn = True if not alreadyIn: with open(subredditsFile, 'a') as fh: fh.write(subreddit+'\n') get_subreddit_entry_info(subreddit) xbmc_notify(colored_subreddit(subreddit), translation(32019) ) else: #dialog = xbmcgui.Dialog() #ok = dialog.ok('Add subreddit', 'Add a subreddit (videos)','or Multiple subreddits (music+listentothis)','or Multireddit (/user/.../m/video)') #would be great to have some sort of help to show first time user here keyboard = xbmc.Keyboard('', translation(32001)) keyboard.doModal() if keyboard.isConfirmed() and keyboard.getText(): subreddit = keyboard.getText() #cleanup user input. make sure /user/ and /m/ is lowercase if this_is_a_multireddit(subreddit): subreddit = format_multihub(subreddit) else: get_subreddit_entry_info(subreddit) for line in content: if line.lower()==subreddit.lower()+"\n": alreadyIn = True if not alreadyIn: with open(subredditsFile, 'a') as fh: fh.write(subreddit+'\n') xbmc.executebuiltin("Container.Refresh")
def addSubreddit(subreddit, name, type_): from utils import colored_subreddit from reddit import this_is_a_multireddit, format_multihub alreadyIn = False with open(subredditsFile, 'r') as fh: content = fh.readlines() if subreddit: for line in content: if line.lower() == subreddit.lower(): alreadyIn = True if not alreadyIn: with open(subredditsFile, 'a') as fh: fh.write(subreddit + '\n') get_subreddit_entry_info(subreddit) xbmc_notify(colored_subreddit(subreddit), translation(30019)) else: #dialog = xbmcgui.Dialog() #ok = dialog.ok('Add subreddit', 'Add a subreddit (videos)','or Multiple subreddits (music+listentothis)','or Multireddit (/user/.../m/video)') #would be great to have some sort of help to show first time user here keyboard = xbmc.Keyboard('', translation(30001)) keyboard.doModal() if keyboard.isConfirmed() and keyboard.getText(): subreddit = keyboard.getText() #cleanup user input. make sure /user/ and /m/ is lowercase if this_is_a_multireddit(subreddit): subreddit = format_multihub(subreddit) else: get_subreddit_entry_info(subreddit) for line in content: if line.lower() == subreddit.lower() + "\n": alreadyIn = True if not alreadyIn: with open(subredditsFile, 'a') as fh: fh.write(subreddit + '\n') xbmc.executebuiltin("Container.Refresh")
def build_reddit_search_context_menu_entries(hasmultiplesubreddit,subreddit,link_url ): cxm_list=[] colored_subreddit_full=colored_subreddit( subreddit ) label_search=translation(32520) parts_of_link_url=urlparse.urlparse(link_url) if cxm_show_search: if GCXM_hasmultiplesubreddit: cxm_list.append( (label_search , build_script("search", '', '') ) ) else: label_search+=' {0}'.format(colored_subreddit_full) cxm_list.append( (label_search , build_script("search", '', subreddit) ) ) #NOTE: can't use the entire link_url because it will work for www.reddit.com but not for oauth.reddit.com part_to_search="{0} {1}".format(parts_of_link_url.path,parts_of_link_url.query) if part_to_search.startswith('/'): part_to_search=part_to_search[1:] #remove starting '/' remove_these_words=['.mp4','.webm','/v/','.jpg','.png'] #mainly to match imgur links where we want to catch the imageID not "imageID.mp4" part_to_search=re.sub('|'.join(re.escape(word) for word in remove_these_words), '', part_to_search) #log('parts to search='+part_to_search) cxm_list.append( (translation(32531) , build_script("listSubReddit", assemble_reddit_filter_string(part_to_search,'','',''), name=translation(32531)) ) ) #"Other posts with this link" return cxm_list
def addSubreddit(subreddit, name, type_): from utils import colored_subreddit from reddit import this_is_a_multireddit, format_multihub alreadyIn = False with open(subredditsFile, 'r') as fh: content = fh.readlines() if subreddit: for line in content: if line.lower()==subreddit.lower(): alreadyIn = True if not alreadyIn: with open(subredditsFile, 'a') as fh: fh.write(subreddit+'\n') get_subreddit_entry_info(subreddit) xbmc_notify(colored_subreddit(subreddit), translation(30019)) else: keyboard = xbmc.Keyboard('', translation(30001)) keyboard.doModal() if keyboard.isConfirmed() and keyboard.getText(): subreddit = keyboard.getText() if this_is_a_multireddit(subreddit): subreddit = format_multihub(subreddit) else: get_subreddit_entry_info(subreddit) for line in content: if line.lower()==subreddit.lower()+"\n": alreadyIn = True if not alreadyIn: with open(subredditsFile, 'a') as fh: fh.write(subreddit+'\n') xbmc.executebuiltin("Container.Refresh")
def build_context_menu_entries(num_comments, commentsUrl, subreddit, domain, link_url, post_id): from reddit import assemble_reddit_filter_string, subreddit_in_favorites, this_is_a_user_saved_list from utils import colored_subreddit s = ( subreddit[:12] + '..' ) if len(subreddit ) > 12 else subreddit #crop long subreddit names in context menu colored_subreddit_short = colored_subreddit(s) colored_subreddit_full = colored_subreddit(subreddit) colored_domain_full = colored_subreddit(domain, 'tan', False) entries = [] #sys.argv[0] is plugin://plugin.video.reddit_viewer/ #prl=zaza is just a dummy: during testing the first argument is ignored... possible bug? if cxm_show_open_browser: entries.append(( translation(30509), #Open in browser "XBMC.RunPlugin(%s?mode=openBrowser&url=%s)" % (sys.argv[0], urllib.quote_plus(link_url)))) if cxm_show_comment_link or cxm_show_comments: if num_comments > 0: #if we are using a custom gui to show comments, we need to use RunPlugin. there is a weird loading/pause if we use XBMC.Container.Update. i think xbmc expects us to use addDirectoryItem # if we have xbmc manage the gui(addDirectoryItem), we need to use XBMC.Container.Update. otherwise we'll get the dreaded "Attempt to use invalid handle -1" error #entries.append( ( translation(30050) + " (c)", #Show comments # "XBMC.RunPlugin(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) #entries.append( ( translation(30052) , #Show comment links # "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s&type=linksOnly)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) if cxm_show_comment_link: entries.append(( translation(30052), #Show comment links "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s&type=linksOnly)" % (sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl)))) if cxm_show_comments: entries.append(( translation(30050), #Show comments "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s)" % (sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl)))) #entries.append( ( translation(30050) + " (ActivateWindow)", #Show comments # "XBMC.ActivateWindow(Video, %s?mode=listLinksInComment&url=%s)" % ( sys.argv[0], urllib.quote_plus(site) ) ) ) #*** ActivateWindow is for the standard xbmc window else: entries.append(( translation(30053), #No comments "xbmc.executebuiltin('Action(Close)')")) if GCXM_hasmultiplesubreddit and cxm_show_go_to: entries.append(( translation(30051) + " %s" % colored_subreddit_full, "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listSubReddit&url=%s)" % (sys.argv[0], sys.argv[0], urllib.quote_plus( assemble_reddit_filter_string("", subreddit, True))))) if cxm_show_new_from: #show check /new from this subreddit if it is all the same subreddit entries.append(( translation(30055) + " %s" % colored_subreddit_short, "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listSubReddit&url=%s)" % (sys.argv[0], sys.argv[0], urllib.quote_plus( assemble_reddit_filter_string("", subreddit + '/new', True))))) if cxm_show_add_shortcuts: if not subreddit_in_favorites(subreddit): #add selected subreddit to shortcuts entries.append((translation(30056) % colored_subreddit_short, "XBMC.RunPlugin(%s?mode=addSubreddit&url=%s)" % (sys.argv[0], subreddit))) if cxm_show_filter_subreddit: entries.append((translation(30057) % colored_subreddit_short, "XBMC.RunPlugin(%s?mode=addtoFilter&url=%s&type=%s)" % (sys.argv[0], subreddit, 'subreddit'))) if cxm_show_filter_domain: entries.append((translation(30057) % colored_domain_full, "XBMC.RunPlugin(%s?mode=addtoFilter&url=%s&type=%s)" % (sys.argv[0], domain, 'domain'))) #only available if user gave reddit_viewer permission to interact with their account #reddit_refresh_token=addon.getSetting("reddit_refresh_token") from reddit import reddit_refresh_token if reddit_refresh_token and cxm_show_reddit_save: if this_is_a_user_saved_list(GCXM_subreddit_key): #only show the unsave option if viewing /user/xxxx/saved entries.append( (translation(30059), "XBMC.RunPlugin(%s?mode=reddit_save&url=%s&name=%s)" % (sys.argv[0], '/api/unsave/', post_id))) else: entries.append( (translation(30058), "XBMC.RunPlugin(%s?mode=reddit_save&url=%s&name=%s)" % (sys.argv[0], '/api/save/', post_id))) if cxm_show_youtube_items: #check if link_url is youtube from domains import ClassYoutube match = re.compile(ClassYoutube.regex, re.I).findall( link_url ) #regex='(youtube.com/)|(youtu.be/)|(youtube-nocookie.com/)|(plugin.video.youtube/play)' if match: #video_id=ClassYoutube.get_video_id(link_url ) #log('video id:'+repr(video_id)) entries.append((translation( 30048 ), "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listRelatedVideo&url=%s&type=%s)" % (sys.argv[0], sys.argv[0], urllib.quote_plus(link_url), 'channel'))) entries.append((translation( 30049 ), "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listRelatedVideo&url=%s&type=%s)" % (sys.argv[0], sys.argv[0], urllib.quote_plus(link_url), 'related'))) #not working... #entries.append( ( translation(30054) , # "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=playURLResolver&url=%s)" % ( sys.argv[0], sys.argv[0],urllib.quote_plus(media_url) ) ) ) #entries.append( ( translation(30054) , # "XBMC.RunPlugin(%s?path=%s?prl=zaza&mode=playURLRVideo&url=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(media_url) ) ) ) #favEntry = '<favourite name="'+title+'" url="'+DirectoryItem_url+'" description="'+description+'" thumb="'+iconimage+'" date="'+credate+'" site="'+site+'" />' #entries.append((translation(30022), 'RunPlugin(plugin://'+addonID+'/?mode=addToFavs&url='+urllib.quote_plus(favEntry)+'&type='+urllib.quote_plus(subreddit)+')',)) return entries
def build_context_menu_entries(num_comments,commentsUrl, subreddit, domain, link_url, post_id): from reddit import assemble_reddit_filter_string, subreddit_in_favorites, this_is_a_user_saved_list from utils import colored_subreddit s=(subreddit[:12] + '..') if len(subreddit) > 12 else subreddit #crop long subreddit names in context menu colored_subreddit_short=colored_subreddit( s ) colored_subreddit_full=colored_subreddit( subreddit ) colored_domain_full=colored_subreddit( domain, 'tan',False ) entries=[] #sys.argv[0] is plugin://plugin.video.reddit_viewer/ #prl=zaza is just a dummy: during testing the first argument is ignored... possible bug? if cxm_show_open_browser: entries.append( ( translation(30509), #Open in browser "XBMC.RunPlugin(%s?mode=openBrowser&url=%s)" % ( sys.argv[0], urllib.quote_plus( link_url ) ) ) ) if cxm_show_comment_link or cxm_show_comments: if num_comments > 0: #if we are using a custom gui to show comments, we need to use RunPlugin. there is a weird loading/pause if we use XBMC.Container.Update. i think xbmc expects us to use addDirectoryItem # if we have xbmc manage the gui(addDirectoryItem), we need to use XBMC.Container.Update. otherwise we'll get the dreaded "Attempt to use invalid handle -1" error #entries.append( ( translation(30050) + " (c)", #Show comments # "XBMC.RunPlugin(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) #entries.append( ( translation(30052) , #Show comment links # "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s&type=linksOnly)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) if cxm_show_comment_link: entries.append( ( translation(30052) , #Show comment links "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s&type=linksOnly)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) if cxm_show_comments: entries.append( ( translation(30050) , #Show comments "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) #entries.append( ( translation(30050) + " (ActivateWindow)", #Show comments # "XBMC.ActivateWindow(Video, %s?mode=listLinksInComment&url=%s)" % ( sys.argv[0], urllib.quote_plus(site) ) ) ) #*** ActivateWindow is for the standard xbmc window else: entries.append( ( translation(30053) , #No comments "xbmc.executebuiltin('Action(Close)')" ) ) if GCXM_hasmultiplesubreddit and cxm_show_go_to: entries.append( ( translation(30051)+" %s" %colored_subreddit_full , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listSubReddit&url=%s)" % ( sys.argv[0], sys.argv[0],urllib.quote_plus(assemble_reddit_filter_string("",subreddit,True) ) ) ) ) if cxm_show_new_from: #show check /new from this subreddit if it is all the same subreddit entries.append( ( translation(30055)+" %s" %colored_subreddit_short , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listSubReddit&url=%s)" % ( sys.argv[0], sys.argv[0],urllib.quote_plus(assemble_reddit_filter_string("",subreddit+'/new',True) ) ) ) ) if cxm_show_add_shortcuts: if not subreddit_in_favorites(subreddit): #add selected subreddit to shortcuts entries.append( ( translation(30056) %colored_subreddit_short , "XBMC.RunPlugin(%s?mode=addSubreddit&url=%s)" % ( sys.argv[0], subreddit ) ) ) if cxm_show_filter_subreddit: entries.append( ( translation(30057) %colored_subreddit_short , "XBMC.RunPlugin(%s?mode=addtoFilter&url=%s&type=%s)" % ( sys.argv[0], subreddit, 'subreddit' ) ) ) if cxm_show_filter_domain: entries.append( ( translation(30057) %colored_domain_full , "XBMC.RunPlugin(%s?mode=addtoFilter&url=%s&type=%s)" % ( sys.argv[0], domain, 'domain' ) ) ) #only available if user gave reddit_viewer permission to interact with their account #reddit_refresh_token=addon.getSetting("reddit_refresh_token") from reddit import reddit_refresh_token if reddit_refresh_token and cxm_show_reddit_save: if this_is_a_user_saved_list(GCXM_subreddit_key): #only show the unsave option if viewing /user/xxxx/saved entries.append( ( translation(30059) , "XBMC.RunPlugin(%s?mode=reddit_save&url=%s&name=%s)" % ( sys.argv[0], '/api/unsave/', post_id ) ) ) else: entries.append( ( translation(30058) , "XBMC.RunPlugin(%s?mode=reddit_save&url=%s&name=%s)" % ( sys.argv[0], '/api/save/', post_id ) ) ) if cxm_show_youtube_items: #check if link_url is youtube from domains import ClassYoutube match=re.compile( ClassYoutube.regex, re.I).findall( link_url ) #regex='(youtube.com/)|(youtu.be/)|(youtube-nocookie.com/)|(plugin.video.youtube/play)' if match: #video_id=ClassYoutube.get_video_id(link_url ) #log('video id:'+repr(video_id)) entries.append( ( translation(30048) , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listRelatedVideo&url=%s&type=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(link_url), 'channel' ) ) ) entries.append( ( translation(30049) , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listRelatedVideo&url=%s&type=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(link_url), 'related' ) ) ) #not working... #entries.append( ( translation(30054) , # "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=playURLResolver&url=%s)" % ( sys.argv[0], sys.argv[0],urllib.quote_plus(media_url) ) ) ) #entries.append( ( translation(30054) , # "XBMC.RunPlugin(%s?path=%s?prl=zaza&mode=playURLRVideo&url=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(media_url) ) ) ) #favEntry = '<favourite name="'+title+'" url="'+DirectoryItem_url+'" description="'+description+'" thumb="'+iconimage+'" date="'+credate+'" site="'+site+'" />' #entries.append((translation(30022), 'RunPlugin(plugin://'+addonID+'/?mode=addToFavs&url='+urllib.quote_plus(favEntry)+'&type='+urllib.quote_plus(subreddit)+')',)) return entries
def addLink(title, title_line2, iconimage, previewimage,preview_w,preview_h,domain, description, credate, reddit_says_is_video, commentsUrl, subreddit, link_url, over_18, posted_by="", num_comments=0,post_id=''): from utils import ret_info_type_icon, build_script,colored_subreddit #from reddit import assemble_reddit_filter_string from domains import parse_reddit_link, sitesBase from ContextMenus import build_context_menu_entries preview_ar=0.0 DirectoryItem_url='' if over_18: mpaa="R" title_line2 = "[COLOR red][NSFW][/COLOR] "+title_line2 else: mpaa="" post_title=title if len(post_title) > 100 or description: il_description='[B]%s[/B][CR][CR]%s' %( post_title, description ) else: il_description='' il={ "title": post_title, "plot": 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 ,label2=title_line2 ,path='') #path not used by gui. if preview_w==0 or preview_h==0: preview_ar=0.0 else: preview_ar=float(preview_w) / preview_h #log(' preview_ar:'+repr(preview_ar)) if preview_ar>1.4: #this triggers whether the (control id 203) will show up #the gui checks for this: String.IsEmpty(Container(55).ListItem.Property(preview_ar)) to show/hide a wider preview # this is overridden if the post is an album. liz.setProperty('preview_ar', str(preview_ar) ) # -- $INFO[ListItem.property(preview_ar)] #text_below_image=il_description+title_line2 + colored_subreddit( posted_by, 'dimgrey',False ) text_below_image='[B]%s[/B][CR]%s %s[CR]%s' %( post_title, title_line2, colored_subreddit( ' by '+posted_by, 'dimgrey',False ), description ) liz.setInfo(type='video', infoLabels={"plotoutline": text_below_image, } ) #makes the gui use a control that allows the user scroll tall image if preview_ar<0.3: liz.setProperty('very_tall_image', str(preview_ar) ) # -- IsEmpty(Container(55).ListItem.Property(very_tall_image)) elif preview_ar<0.5: liz.setProperty('tall_image', str(preview_ar) ) # -- IsEmpty(Container(55).ListItem.Property(tall_image)) if num_comments > 0 or description: liz.setProperty('comments_action', build_script('listLinksInComment', commentsUrl ) ) liz.setProperty('link_url', link_url ) liz.setInfo(type='video', infoLabels=il) #use clearart to indicate if link is video, album or image. here, we default to unsupported. clearart=ret_info_type_icon('', '') liz.setArt({ "clearart": clearart }) #force all links to ytdl to see if they are playable liz.setProperty('item_type','script') liz.setProperty('onClick_action', build_script('playYTDLVideo', link_url,'',previewimage) ) #liz.setProperty('onClick_action', build_script('playYTDLVideo', link_url,'','') ) #get meta_ogimage_content for links that do not have a preview image if previewimage: needs_preview=False else: if any(site in domain for site in sites_that_will_ban_if_excessive_connections): previewimage=iconimage needs_preview=False else: needs_preview=True #reddit has no thumbnail for this link. please get one ld=parse_reddit_link(link_url,reddit_says_is_video, needs_preview, False, preview_ar ) if previewimage=="": if domain.startswith('self.'): liz.setArt({"thumb": ld.thumb if ld else '', "banner": '' , }) else: liz.setArt({"thumb": iconimage, "banner": ld.poster if ld else '' , }) else: liz.setArt({"thumb": iconimage, "banner":previewimage, }) #log( ' %s' %(domain)) #log( ' reddit thumb[%s] ' %(iconimage )) #log( ' reddit preview[%s] ar=%f %dx%d' %(previewimage, preview_ar, preview_w,preview_h )) #if ld: log( ' new-thumb[%s] poster[%s] ' %( ld.thumb, ld.poster )) if ld: #use clearart to indicate the type of link(video, album, image etc.) clearart=ret_info_type_icon(ld.media_type, ld.link_action, domain ) liz.setArt({ "clearart": clearart }) if iconimage in ["","nsfw", "default"]: iconimage=ld.thumb #we gathered a description from the link if ld.desctiption: liz.setInfo(type='video', infoLabels={'plot': il_description + '[CR]' + ld.desctiption, }) if ld.dictlist: #log('****has album images') #listItem is not json serializable so dictlist_to_listItems() is done in the gui #image_listItems=dictlist_to_listItems(ld.dictlist) liz.setProperty('album_images', json.dumps( ld.dictlist ) ) # dictlist=json.loads(string) #overrride the preview_ar flag. (easier to do this here than have the xml figure it out in <visible> liz.setProperty('preview_ar', None ) #log( liz.getProperty('album_images')) #link_action set in domains.py - parse_reddit_link if ld.link_action == sitesBase.DI_ACTION_PLAYABLE: property_link_type=ld.link_action DirectoryItem_url =ld.playable_url else: property_link_type='script' if ld.link_action=='viewTallImage' : #viewTallImage take different args DirectoryItem_url = build_script(mode=ld.link_action, url=ld.playable_url, name=str(preview_w), type_=str(preview_h) ) else: #log( '****' + repr( ld.dictlist )) DirectoryItem_url = build_script(mode=ld.link_action, url=ld.playable_url, name=post_title , type_=previewimage ) #log(' action %s--%s' %( ld.link_action, DirectoryItem_url) ) liz.setProperty('item_type',property_link_type) liz.setProperty('onClick_action',DirectoryItem_url) else: #unsupported type here: pass #***build context menu*** # convert a list of tuple into a string then set it as a property # in GUI, the string is converted back via ast.literal_eval() and put into listItems liz.setProperty('context_menu', str(build_context_menu_entries(num_comments, commentsUrl, subreddit, domain, link_url, post_id, post_title, posted_by, liz.getProperty('onClick_action'), iconimage )) ) return liz
def build_context_menu_entries(num_comments,commentsUrl, subreddit, domain, link_url, post_id, post_title, posted_by, onClick_action, thumbnail): s=truncate(subreddit,15) #crop long subreddit names in context menu colored_subreddit_short=colored_subreddit( s ) colored_domain_full=colored_subreddit( domain, 'tan',False ) post_title_short=truncate(post_title,15) post_author=truncate(posted_by,15) label_view_comments=translation(32504)+' ({0})'.format(num_comments) label_more_by_author=translation(32506).format(author=post_author) label_goto_subreddit=translation(32508).format(subreddit=subreddit) label_goto_domain=translation(32510).format(domain=domain) label_autoplay_after=translation(32513)+' '+colored_subreddit( post_title_short, 'gray',False ) label_add_to_shortcuts=translation(32516).format(subreddit=subreddit) cxm_list=[] cxm_list.extend( build_link_in_browser_context_menu_entries(link_url) ) cxm_list.extend( build_open_browser_to_pair_context_menu_entries(link_url) ) if cxm_show_comments: cxm_list.append((label_view_comments , build_script('listLinksInComment', commentsUrl ) )) #more by author if GCXM_hasmultipleauthor and cxm_show_by_author: cxm_list.append( (label_more_by_author, build_script("listSubReddit", assemble_reddit_filter_string("","/user/"+posted_by+'/submitted'), posted_by) ) ) #more from r/subreddit if GCXM_hasmultiplesubreddit and cxm_show_by_subreddit: cxm_list.append( (label_goto_subreddit, build_script("listSubReddit", assemble_reddit_filter_string("",subreddit), subreddit) ) ) #more from domain if GCXM_hasmultipledomain and cxm_show_by_domain: cxm_list.append( ( label_goto_domain, build_script("listSubReddit", assemble_reddit_filter_string("",'','',domain), domain) ) ) #more random (no setting to disable this) if any(x in GCXM_actual_url_used_to_generate_these_posts.lower() for x in ['/random','/randnsfw']): #if '/rand' in GCXM_actual_url_used_to_generate_these_posts: cxm_list.append( (translation(32511) +' random', build_script('listSubReddit', GCXM_actual_url_used_to_generate_these_posts)) , ) #Reload #Autoplay all #Autoplay after post_title #slideshow if cxm_show_autoplay: cxm_list.extend( [ (translation(32512) , build_script('autoPlay', GCXM_reddit_query_of_this_gui)), (label_autoplay_after , build_script('autoPlay', GCXM_reddit_query_of_this_gui.split('&after=')[0]+'&after='+post_id)), ]) if cxm_show_slideshow: cxm_list.append( (translation(32514) , build_script('autoSlideshow', GCXM_reddit_query_of_this_gui)) ) #Add %s to shortcuts if not subreddit_in_favorites(subreddit) and cxm_show_add_shortcuts: cxm_list.append( (label_add_to_shortcuts, build_script("addSubreddit", subreddit) ) ) #Add to subreddit/domain filter if cxm_show_filter: cxm_list.append( (translation(32519).format(colored_subreddit_short), build_script("addtoFilter", subreddit,'','subreddit') ) ) cxm_list.append( (translation(32519).format(colored_domain_full) , build_script("addtoFilter", domain,'','domain') ) ) #Search / Other posts with this link cxm_list.extend( build_reddit_search_context_menu_entries(GCXM_hasmultiplesubreddit,subreddit,link_url) ) if cxm_show_youtube_items: cxm_list.extend( build_youtube_context_menu_entries('', link_url, video_id=None, title=post_title )) cxm_list.extend( build_add_to_favourites_context_menu_entry(title=post_title, onClick_action=onClick_action,thumbnail=thumbnail) ) return cxm_list
def build_context_menu_entries(num_comments, commentsUrl, subreddit, domain, link_url, post_id, post_title, posted_by): from reddit import assemble_reddit_filter_string, subreddit_in_favorites #, this_is_a_user_saved_list from utils import colored_subreddit, build_script, truncate s = truncate(subreddit, 15) #crop long subreddit names in context menu colored_subreddit_short = colored_subreddit(s) colored_subreddit_full = colored_subreddit(subreddit) colored_domain_full = colored_subreddit(domain, 'tan', False) post_title_short = truncate(post_title, 15) post_author = truncate(posted_by, 15) label_view_comments = translation(32050) + ' ({})'.format(num_comments) label_goto_subreddit = translation(32051) + ' {}'.format( colored_subreddit_full) label_goto_domain = translation(32053) + ' {}'.format(colored_domain_full) label_search = translation(32052) label_autoplay_after = translation(32055) + ' ' + colored_subreddit( post_title_short, 'gray', False) label_more_by_author = translation(32049) + ' ' + colored_subreddit( post_author, 'gray', False) cxm_list = [ ('html to text', build_script('readHTML', link_url)), (label_view_comments, build_script('listLinksInComment', commentsUrl)), ] #more by author if GCXM_hasmultipleauthor: cxm_list.append((label_more_by_author, build_script( "listSubReddit", assemble_reddit_filter_string( "", "/user/" + posted_by + '/submitted'), posted_by))) #more from r/subreddit if GCXM_hasmultiplesubreddit: cxm_list.append( (label_goto_subreddit, build_script("listSubReddit", assemble_reddit_filter_string("", subreddit), subreddit))) #more from domain if GCXM_hasmultipledomain: cxm_list.append( (label_goto_domain, build_script("listSubReddit", assemble_reddit_filter_string("", '', '', domain), domain))) #more random if any(x in GCXM_actual_url_used_to_generate_these_posts.lower() for x in ['/random', '/randnsfw'] ): #if '/rand' in GCXM_actual_url_used_to_generate_these_posts: cxm_list.append( (translation(32053) + ' random', build_script('listSubReddit', GCXM_actual_url_used_to_generate_these_posts)), ) #Reload #Autoplay all #Autoplay after post_title #slideshow cxm_list.extend([ (translation(32054), build_script('autoPlay', GCXM_reddit_query_of_this_gui)), (label_autoplay_after, build_script( 'autoPlay', GCXM_reddit_query_of_this_gui.split('&after=')[0] + '&after=' + post_id)), (translation(32048), build_script('autoSlideshow', GCXM_reddit_query_of_this_gui)), ]) #Add %s to shortcuts if not subreddit_in_favorites(subreddit): cxm_list.append((translation(32056) % colored_subreddit_short, build_script("addSubreddit", subreddit))) #Add to subreddit/domain filter cxm_list.append((translation(32057) % colored_subreddit_short, build_script("addtoFilter", subreddit, '', 'subreddit'))) cxm_list.append((translation(32057) % colored_domain_full, build_script("addtoFilter", domain, '', 'domain'))) #Search if GCXM_hasmultiplesubreddit: cxm_list.append((label_search, build_script("search", '', ''))) else: label_search += ' {}'.format(colored_subreddit_full) cxm_list.append((label_search, build_script("search", '', subreddit))) return cxm_list
def addLink(title, title_line2, iconimage, previewimage, preview_w, preview_h, domain, description, credate, reddit_says_is_video, commentsUrl, subreddit, link_url, over_18, posted_by="", num_comments=0, post_id=''): from utils import ret_info_type_icon, build_script, colored_subreddit #from reddit import assemble_reddit_filter_string from domains import parse_reddit_link, sitesBase preview_ar = 0.0 DirectoryItem_url = '' if over_18: mpaa = "R" title_line2 = "[COLOR red][NSFW][/COLOR] " + title_line2 else: mpaa = "" post_title = title if len(post_title) > 100 or description: il_description = '[B]%s[/B][CR][CR]%s' % (post_title, description) else: il_description = '' il = { "title": post_title, "plot": 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, label2=title_line2, path='') #path not used by gui. if preview_w == 0 or preview_h == 0: preview_ar = 0.0 else: preview_ar = float(preview_w) / preview_h log(' preview_ar:' + repr(preview_ar)) if preview_ar > 1.4: #this triggers whether the (control id 203) will show up #log(' ar and description criteria met') #the gui checks for this: String.IsEmpty(Container(55).ListItem.Property(preview_ar)) to show/hide preview and description liz.setProperty( 'preview_ar', str(preview_ar)) # -- $INFO[ListItem.property(preview_ar)] #text_below_image=il_description+title_line2 + colored_subreddit( posted_by, 'dimgrey',False ) text_below_image = '[B]%s[/B][CR]%s %s[CR]%s' % ( post_title, title_line2, colored_subreddit(' by ' + posted_by, 'dimgrey', False), description) liz.setInfo(type='video', infoLabels={ "plotoutline": text_below_image, }) #makes the gui use a control that allows the user scroll tall image if preview_ar < 0.3: liz.setProperty( 'very_tall_image', str(preview_ar) ) # -- IsEmpty(Container(55).ListItem.Property(very_tall_image)) elif preview_ar < 0.5: liz.setProperty( 'tall_image', str(preview_ar) ) # -- IsEmpty(Container(55).ListItem.Property(tall_image)) if num_comments > 0 or description: liz.setProperty('comments_action', build_script('listLinksInComment', commentsUrl)) liz.setProperty('link_url', link_url) liz.setInfo(type='video', infoLabels=il) #use clearart to indicate if link is video, album or image. here, we default to unsupported. clearart = ret_info_type_icon('', '') liz.setArt({"clearart": clearart}) #force all links to ytdl to see if they are playable liz.setProperty('item_type', 'script') liz.setProperty('onClick_action', build_script('playYTDLVideo', link_url, '', previewimage)) #***build context menu*** # convert a list of tuple into a string then set it as a property # in GUI, the string is converted back via ast.literal_eval() and put into listItems liz.setProperty( 'context_menu', str( build_context_menu_entries(num_comments, commentsUrl, subreddit, domain, link_url, post_id, post_title, posted_by))) if previewimage: needs_preview = False else: needs_preview = True #reddit has no thumbnail for this link. please get one ld = parse_reddit_link(link_url, reddit_says_is_video, needs_preview, False, preview_ar) if previewimage == "": if domain.startswith('self.'): liz.setArt({ "thumb": ld.thumb if ld else '', "banner": '', }) else: liz.setArt({ "thumb": iconimage, "banner": ld.poster if ld else '', }) else: liz.setArt({ "thumb": iconimage, "banner": previewimage, }) #log( ' reddit thumb[%s] ' %(iconimage )) #log( ' reddit preview[%s] ar=%f %dx%d' %(previewimage, preview_ar, preview_w,preview_h )) #if ld: log( ' new-thumb[%s] poster[%s] ' %( ld.thumb, ld.poster )) if ld: #use clearart to indicate the type of link(video, album, image etc.) clearart = ret_info_type_icon(ld.media_type, ld.link_action, domain) liz.setArt({"clearart": clearart}) if iconimage in ["", "nsfw", "default"]: iconimage = ld.thumb #we gathered a description from the link if ld.desctiption: liz.setInfo(type='video', infoLabels={ 'plot': il_description + '[CR]' + ld.desctiption, }) #link_action set in domains.py - parse_reddit_link if ld.link_action == sitesBase.DI_ACTION_PLAYABLE: property_link_type = ld.link_action DirectoryItem_url = ld.playable_url else: property_link_type = 'script' if ld.link_action == 'viewTallImage': #viewTallImage take different args DirectoryItem_url = build_script(mode=ld.link_action, url=ld.playable_url, name=str(preview_w), type_=str(preview_h)) else: #log( '****' + repr( ld.dictlist )) DirectoryItem_url = build_script(mode=ld.link_action, url=ld.playable_url, name=post_title, type_=previewimage) #log(' action %s--%s' %( ld.link_action, DirectoryItem_url) ) liz.setProperty('item_type', property_link_type) liz.setProperty('onClick_action', DirectoryItem_url) liz.setProperty('album_images', json.dumps(ld.dictlist)) # dictlist=json.loads(string) #log( liz.getProperty('album_images')) else: #unsupported type here: pass return liz
def build_context_menu_entries(num_comments,commentsUrl, subreddit, domain, link_url, post_id): from reddit import assemble_reddit_filter_string, subreddit_in_favorites, this_is_a_user_saved_list from utils import colored_subreddit s=(subreddit[:12] + '..') if len(subreddit) > 12 else subreddit #crop long subreddit names in context menu colored_subreddit_short=colored_subreddit( s ) colored_subreddit_full=colored_subreddit( subreddit ) colored_domain_full=colored_subreddit( domain, 'tan',False ) entries=[] if cxm_show_open_browser: entries.append( ( translation(30509), #Open in browser "XBMC.RunPlugin(%s?mode=openBrowser&url=%s)" % ( sys.argv[0], urllib.quote_plus( link_url ) ) ) ) if cxm_show_comment_link or cxm_show_comments: if num_comments > 0: if cxm_show_comment_link: entries.append( ( translation(30052) , #Show comment links "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s&type=linksOnly)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) if cxm_show_comments: entries.append( ( translation(30050) , #Show comments "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listLinksInComment&url=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(commentsUrl) ) ) ) else: entries.append( ( translation(30053) , #No comments "xbmc.executebuiltin('Action(Close)')" ) ) if GCXM_hasmultiplesubreddit and cxm_show_go_to: entries.append( ( translation(30051)+" %s" %colored_subreddit_full , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listSubReddit&url=%s)" % ( sys.argv[0], sys.argv[0],urllib.quote_plus(assemble_reddit_filter_string("",subreddit,True) ) ) ) ) if cxm_show_new_from: entries.append( ( translation(30055)+" %s" %colored_subreddit_short , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listSubReddit&url=%s)" % ( sys.argv[0], sys.argv[0],urllib.quote_plus(assemble_reddit_filter_string("",subreddit+'/new',True) ) ) ) ) if cxm_show_add_shortcuts: if not subreddit_in_favorites(subreddit): entries.append( ( translation(30056) %colored_subreddit_short , "XBMC.RunPlugin(%s?mode=addSubreddit&url=%s)" % ( sys.argv[0], subreddit ) ) ) if cxm_show_filter_subreddit: entries.append( ( translation(30057) %colored_subreddit_short , "XBMC.RunPlugin(%s?mode=addtoFilter&url=%s&type=%s)" % ( sys.argv[0], subreddit, 'subreddit' ) ) ) if cxm_show_filter_domain: entries.append( ( translation(30057) %colored_domain_full , "XBMC.RunPlugin(%s?mode=addtoFilter&url=%s&type=%s)" % ( sys.argv[0], domain, 'domain' ) ) ) from reddit import reddit_refresh_token if reddit_refresh_token and cxm_show_reddit_save: if this_is_a_user_saved_list(GCXM_subreddit_key): entries.append( ( translation(30059) , "XBMC.RunPlugin(%s?mode=reddit_save&url=%s&name=%s)" % ( sys.argv[0], '/api/unsave/', post_id ) ) ) else: entries.append( ( translation(30058) , "XBMC.RunPlugin(%s?mode=reddit_save&url=%s&name=%s)" % ( sys.argv[0], '/api/save/', post_id ) ) ) if cxm_show_youtube_items: from domains import ClassYoutube match=re.compile( ClassYoutube.regex, re.I).findall( link_url ) #regex='(youtube.com/)|(youtu.be/)|(youtube-nocookie.com/)|(plugin.video.youtube/play)' if match: entries.append( ( translation(30048) , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listRelatedVideo&url=%s&type=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(link_url), 'channel' ) ) ) entries.append( ( translation(30049) , "XBMC.Container.Update(%s?path=%s?prl=zaza&mode=listRelatedVideo&url=%s&type=%s)" % ( sys.argv[0], sys.argv[0], urllib.quote_plus(link_url), 'related' ) ) ) return entries