Example #1
0
 def _play_video(self):
     # Youtube client
     client = YoutubeClient()
     # construct the video url with session id and get video details
     url, g_title, g_director, g_genre, g_rating, g_runtime, g_count, g_date, g_thumbnail, g_plotoutline, video_id = client.construct_video_url(
         self.args.video_url, (
             0,
             6,
             18,
         )[int(xbmcplugin.getSetting("quality"))])
     # close the dialog
     pDialog.close()
     if (not pDialog.iscanceled()):
         # get cached thumbnail, no need to redownload
         g_thumbnail = xbmc.getCacheThumbName(sys.argv[0] + sys.argv[2])
         g_thumbnail = os.path.join(xbmc.translatePath("p:\\Thumbnails"),
                                    "Video", g_thumbnail[0], g_thumbnail)
         # construct our listitem
         listitem = xbmcgui.ListItem(g_title, thumbnailImage=g_thumbnail)
         # set the key information
         listitem.setInfo(
             "video", {
                 "Title": g_title,
                 "Plotoutline": g_plotoutline,
                 "Plot": g_plotoutline,
                 "Director": g_director,
                 "Genre": g_genre,
                 "Rating": g_rating,
                 "Date": g_date
             })
         # set special property
         listitem.setProperty("isVideo", "1")
         listitem.setProperty("RecommendLink", sys.argv[0] + sys.argv[2])
         # Play video with the proper core
         xbmc.Player(self.player_core).play(url, listitem)
Example #2
0
 def play_video(self, video_id):
     # Youtube client
     client = YoutubeClient()
     # construct the video url with session id
     video_url = client.BASE_ID_URL % (video_id, )
     # fetch video information
     url, title, author, genre, rating, runtime, count, date, thumbnail_url, plot, video_id = client.construct_video_url(
         video_url, (
             0,
             6,
             18,
         )[int(xbmcplugin.getSetting("quality"))])
     pDialog.close()
     if (not pDialog.iscanceled()):
         listitem = xbmcgui.ListItem(title,
                                     runtime,
                                     thumbnailImage=thumbnail_url)
         # set the key information
         listitem.setInfo(
             "video", {
                 "Title": title,
                 "Director": author,
                 "Genre": genre,
                 "Rating": rating,
                 "Duration": runtime,
                 "Count": count,
                 "Date": date,
                 "PlotOutline": plot,
                 "Plot": plot
             })
         # Play video with the proper core
         xbmc.Player(self.player_core).play(url, listitem)
Example #3
0
 def play_random_video(self):
     # Youtube client
     client = YoutubeClient()
     # fetch video information
     url, title, author, genre, rating, runtime, count, date, thumbnail_url, plot = client.get_random_middio_video(
         (
             0,
             6,
             18,
         )[int(xbmcplugin.getSetting("quality"))])
     pDialog.close()
     if (not pDialog.iscanceled()):
         listitem = xbmcgui.ListItem(title,
                                     runtime,
                                     thumbnailImage=thumbnail_url)
         # set the key information
         listitem.setInfo(
             "video", {
                 "Title": title,
                 "Director": author,
                 "Genre": genre,
                 "Rating": rating,
                 "Duration": runtime,
                 "Count": count,
                 "Date": date,
                 "PlotOutline": plot,
                 "Plot": plot
             })
         # Play video with the proper core
         self.Player.play(url, listitem)
Example #4
0
 def _play_video(self):
     # Youtube client
     client = YoutubeClient(authkey=xbmcplugin.getSetting("authkey"))
     # construct the video url with session id and get video details
     url, title, director, genre, rating, runtime, count, date, thumbnail, plotoutline, video_id = client.construct_video_url(
         self.args.video_url, (
             18,
             22,
         )[xbmcplugin.getSetting("hd_videos") == "true"])
     # get cached thumbnail, no need to redownload
     thumbnail = xbmc.getCacheThumbName(sys.argv[0] + sys.argv[2])
     thumbnail = os.path.join(xbmc.translatePath("special://profile"),
                              "Thumbnails", "Video", thumbnail[0],
                              thumbnail)
     # construct our listitem
     listitem = xbmcgui.ListItem(title, thumbnailImage=thumbnail, path=url)
     # set the key information
     listitem.setInfo(
         "video", {
             "Title": title,
             "Plotoutline": plotoutline,
             "Plot": plotoutline,
             "Director": director,
             "Genre": genre,
             "Rating": rating,
             "Date": date
         })
     # Resolve url
     xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
Example #5
0
 def delete__favorite(self):
     # Youtube client
     client = YoutubeClient(YoutubeClient.BASE_USERS_URL, self.authkey)
     ok = client.delete_favorites(self.args.edit_url)
     # only need to refresh if successful
     if (ok):
         xbmc.executebuiltin("Container.Refresh")
     return False, 0
 def delete__favorite( self ):
     # Youtube client
     client = YoutubeClient( YoutubeClient.BASE_USERS_URL, self.authkey )
     ok = client.delete_favorites( self.args.edit_url )
     # only need to refresh if successful
     if ( ok ):
         xbmc.executebuiltin( "Container.Refresh" )
     return False, 0
Example #7
0
 def _download_video( self ):
     try:
         # Youtube client
         client = YoutubeClient()
         # construct the video url with session id and get video details
         url, self.g_title, self.g_director, self.g_genre, self.g_rating, self.g_runtime, self.g_count, self.g_date, self.g_thumbnail, self.g_plotoutline, video_id = client.construct_video_url( self.args.video_url, ( 0, 6, 18, )[ int( xbmcplugin.getSetting( "quality" ) ) ] )
         # create our temp save path
         tmp_path = xbmc.translatePath( "Z:\\%s.flv" % ( video_id, ) )
         # get a valid filepath
         if ( self.settings[ "use_title" ] ):
             # add extension to video title
             title = self.g_title + ".flv"
         else:
             # we use the urls trailer name
             title = video_id + ".flv"
         # make the path legal for the users platform
         self.filepath = self._make_legal_filepath( title )
         # get the filesystem the trailer will be saved to
         filesystem = self._get_filesystem()
         # win32 requires encoding to work proper
         if ( self._get_filesystem() == "win32" ):
             filepath = self.filepath.encode( "utf-8" )
         else:
             filepath = self.filepath
         # only download if the trailer doesn't exist
         if ( not os.path.isfile( tmp_path ) ):
             # fetch the video
             urllib.urlretrieve( url, tmp_path, self._report_hook )
         ok = True
         # finalize
         if ( not os.path.isfile( filepath ) ):
             # copy to final location
             ok = self._finalize_download( tmp_path )
             # if the copy failed raise an error
             if ( not ok ): raise
     except:
         print "ERROR: %s::%s (%d) - %s" % ( self.__class__.__name__, sys.exc_info()[ 2 ].tb_frame.f_code.co_name, sys.exc_info()[ 2 ].tb_lineno, sys.exc_info()[ 1 ], )
         # filepath is not always released immediately, we may need to try more than one attempt, sleeping between
         urllib.urlcleanup()
         remove_tries = 3
         while remove_tries and os.path.isfile( tmp_path ):
             try:
                 os.remove( tmp_path )
             except:
                 remove_tries -= 1
                 xbmc.sleep( 1000 )
         pDialog.close()
         self.filepath = ""
Example #8
0
 def fetch_videos(self, url, feed_time="", region_id=""):
     # Youtube client
     client = YoutubeClient(url, self.authkey)
     # starting video
     start_index = (self.args.page - 1) * self.settings["perpage"] + 1
     # fetch the videos
     # TODO: format=5, <- put this back if videos fail
     exec 'feeds = client.%s( orderby=self.args.orderby, related=self.args.related, region_id=region_id, time=feed_time, racy=self.settings[ "include_racy" ], start__index=start_index, max__results=self.settings[ "perpage" ], vq=self.args.vq, author=self.args.username, category=self.args.cat )' % (
         self.args.category, )
     # calculate total pages
     pages = self._get_total_pages(
         int(feeds["feed"]["openSearch$totalResults"]["$t"]))
     # if this was a search and there is a spelling correction get the correction
     spell_vq = ""
     if (url == YoutubeClient.BASE_SEARCH_URL and self.args.page == 1):
         spell_vq = self._get_spellcorrection(feeds["feed"]["link"],
                                              feeds["encoding"])
     # if there are results
     if (pages or spell_vq):
         return self._fill_media_list(
             True, feeds["feed"].get("entry", []), self.args.page, pages,
             self.settings["perpage"],
             int(feeds["feed"]["openSearch$totalResults"]["$t"]),
             feeds["encoding"], spell_vq)
     #else return failed
     return False, 0
Example #9
0
 def authenticate( self ):
     # if this is first run open settings
     self.openSettings()
     # authentication is not permanent, so do this only when first launching plugin
     if ( not sys.argv[ 2 ] ):
         # get the users settings
         password = xbmcplugin.getSetting( "user_password" )
         # we can only authenticate if both email and password are entered
         self.authkey = ""
         if ( self.username and password ):
             # our client api
             from YoutubeAPI.YoutubeClient import YoutubeClient
             client = YoutubeClient()
             # make the authentication call
             self.authkey, userid = client.authenticate( self.username, password )
         # save authkey even if failed, so no token expired error
         xbmcplugin.setSetting( "authkey", self.authkey )
Example #10
0
 def get_my_subscriptions( self ):
     self.username = xbmcplugin.getSetting( "username" )
     self.authkey = xbmcplugin.getSetting( "authkey" )
     # our client api
     from YoutubeAPI.YoutubeClient import YoutubeClient
     client = YoutubeClient( base_url=YoutubeClient.BASE_USERS_URL, authkey=self.authkey )
     # start index should be 1, TODO: may need to fix for page 2...
     start_index = ( self.args.page - 1 ) * int( xbmcplugin.getSetting( "perpage" ) ) + 1
     # get subscriptions
     feeds = client.my_subscriptions( orderby=self.args.orderby, related=self.args.related, region_id="", time="", racy=xbmcplugin.getSetting( "include_racy" ), start__index=start_index, max__results=int( xbmcplugin.getSetting( "perpage" ) ), vq=self.args.vq, author=self.args.username, category=self.args.cat )
     # initialize our categories
     categories = []
     # iterate thru and create an item same as user search
     for feed in feeds[ "feed" ].get( "entry", [] ):
         # add subscription to our dictionary
         categories += [ [ feed[ "yt$username" ][ "$t" ], "videos", self.args.vq, feed[ "yt$username" ][ "$t" ], self.args.cat, True, "updated", 0, feed[ "media$thumbnail" ][ "url" ], False ] ]
     # return categories
     return categories
 def _download_video(self):
     try:
         # Youtube client
         client = YoutubeClient(authkey=xbmcplugin.getSetting("authkey"))
         # construct the video url with session id and get video details
         url, self.g_title, self.g_director, self.g_genre, self.g_rating, self.g_runtime, self.g_count, self.g_date, self.g_thumbnail, self.g_plotoutline, video_id = client.construct_video_url(
             self.args.video_url, (18, 22)[xbmcplugin.getSetting("hd_videos") == "true"]
         )
         # create our temp save path
         tmp_path = xbmc.translatePath("special://temp/%s.flv" % (video_id,))
         # get a valid filepath
         if self.settings["use_title"]:
             # add extension to video title
             title = self.g_title + ".flv"
         else:
             # we use the urls trailer name
             title = video_id + ".flv"
         # make the path legal for the users platform
         self.filepath = self._make_legal_filepath(title)
         # get the filesystem the trailer will be saved to
         filesystem = self._get_filesystem()
         # win32 requires encoding to work proper
         if self._get_filesystem() == "win32":
             filepath = self.filepath.encode("utf-8")
         else:
             filepath = self.filepath
         # only download if the trailer doesn't exist
         if not os.path.isfile(tmp_path) and not os.path.isfile(self.filepath):
             # fetch the video
             urllib.urlretrieve(url, tmp_path, self._report_hook)
         ok = True
         # finalize
         if not os.path.isfile(filepath):
             # copy to final location
             ok = self._finalize_download(tmp_path)
         # if the copy failed raise an error
         if not ok:
             raise
     except:
         print "ERROR: %s::%s (%d) - %s" % (
             self.__class__.__name__,
             sys.exc_info()[2].tb_frame.f_code.co_name,
             sys.exc_info()[2].tb_lineno,
             sys.exc_info()[1],
         )
         # filepath is not always released immediately, we may need to try more than one attempt, sleeping between
         urllib.urlcleanup()
         remove_tries = 3
         while remove_tries and os.path.isfile(tmp_path):
             try:
                 os.remove(tmp_path)
             except:
                 remove_tries -= 1
                 xbmc.sleep(1000)
         pDialog.close()
         self.filepath = ""
Example #12
0
 def play_random_video( self ):
     # Youtube client
     client = YoutubeClient()
     # fetch video information
     url, title, author, genre, rating, runtime, count, date, thumbnail_url, plot = client.get_random_middio_video( ( 0, 6, 18, )[ int( xbmcplugin.getSetting( "quality" ) ) ] )
     pDialog.close()
     if ( not pDialog.iscanceled() ):
         listitem = xbmcgui.ListItem( title, runtime, thumbnailImage=thumbnail_url )
         # set the key information
         listitem.setInfo( "video", { "Title": title, "Director": author, "Genre": genre, "Rating": rating, "Duration": runtime, "Count": count, "Date": date, "PlotOutline": plot, "Plot": plot } )
         # Play video with the proper core
         self.Player.play( url, listitem )
 def play_video(self, video_id):
     # Youtube client
     client = YoutubeClient(authkey=xbmcplugin.getSetting("authkey"))
     # construct the video url
     video_url = client.BASE_ID_URL % (video_id, )
     # fetch video information
     url, title, author, genre, rating, runtime, count, date, thumbnail_url, plot, video_id = client.construct_video_url(
         video_url, (
             18,
             22,
         )[xbmcplugin.getSetting("hd_videos") == "true"])
     # get cached thumbnail, no need to redownload
     thumbnail = xbmc.getCacheThumbName(sys.argv[0] + sys.argv[2] +
                                        video_id)
     thumbnail = os.path.join(xbmc.translatePath("special://profile"),
                              "Thumbnails", "Video", thumbnail[0],
                              thumbnail)
     # if thumb not found download it
     if (not os.path.isfile(thumbnail)):
         xbmc.executehttpapi("FileCopy(%s,%s)" % (
             thumbnail_url,
             thumbnail.encode("utf-8"),
         ))
     # construct our listitem
     listitem = xbmcgui.ListItem(title, runtime, thumbnailImage=thumbnail)
     # set the key information
     listitem.setInfo(
         "video", {
             "Title": title,
             "Director": author,
             "Genre": genre,
             "Rating": rating,
             "Duration": runtime,
             "Count": count,
             "Date": date,
             "PlotOutline": plot,
             "Plot": plot
         })
     # Play video with the proper core
     xbmc.Player().play(url, listitem)
Example #14
0
 def _play_video( self ):
     # Youtube client
     client = YoutubeClient( authkey=xbmcplugin.getSetting( "authkey" ) )
     # construct the video url with session id and get video details
     url, title, director, genre, rating, runtime, count, date, thumbnail, plotoutline, video_id = client.construct_video_url( self.args.video_url, ( 18, 22, )[ xbmcplugin.getSetting( "hd_videos" ) == "true" ] )
     # get cached thumbnail, no need to redownload
     thumbnail = xbmc.getCacheThumbName( sys.argv[ 0 ] + sys.argv[ 2 ] )
     thumbnail = os.path.join( xbmc.translatePath( "special://profile" ), "Thumbnails", "Video", thumbnail[ 0 ], thumbnail )
     # construct our listitem
     listitem = xbmcgui.ListItem( title, thumbnailImage=thumbnail, path=url )
     # set the key information
     listitem.setInfo( "video", { "Title": title, "Plotoutline": plotoutline, "Plot": plotoutline, "Director": director, "Genre": genre, "Rating": rating, "Date": date } )
     # Resolve url
     xbmcplugin.setResolvedUrl( int( sys.argv[ 1 ] ), True, listitem )
 def play_video( self, video_id ):
     # Youtube client
     client = YoutubeClient( authkey=xbmcplugin.getSetting( "authkey" ) )
     # construct the video url
     video_url = client.BASE_ID_URL % ( video_id, )
     # fetch video information
     url, title, author, genre, rating, runtime, count, date, thumbnail_url, plot, video_id = client.construct_video_url( video_url, ( 18, 22, )[ xbmcplugin.getSetting( "hd_videos" ) == "true" ] )
     # get cached thumbnail, no need to redownload
     thumbnail = xbmc.getCacheThumbName( sys.argv[ 0 ] + sys.argv[ 2 ] + video_id )
     thumbnail = os.path.join( xbmc.translatePath( "special://profile" ), "Thumbnails", "Video", thumbnail[ 0 ], thumbnail )
     # if thumb not found download it
     if ( not os.path.isfile( thumbnail ) ):
         xbmc.executehttpapi( "FileCopy(%s,%s)" % ( thumbnail_url, thumbnail.encode( "UTF-8" ), ) )
     # construct our listitem
     listitem = xbmcgui.ListItem( title, runtime, thumbnailImage=thumbnail )
     # set the key information
     listitem.setInfo( "video", { "Title": title, "Director": author, "Genre": genre, "Rating": rating, "Duration": runtime, "Count": count, "Date": date, "PlotOutline": plot, "Plot": plot } )
     # Play video with the proper core
     xbmc.Player().play( url, listitem )
 def _play_video( self ):
     # Youtube client
     client = YoutubeClient()
     # construct the video url with session id and get video details
     url, g_title, g_director, g_genre, g_rating, g_runtime, g_count, g_date, g_thumbnail, g_plotoutline, video_id = client.construct_video_url( self.args.video_url, ( 0, 6, 18, )[ int( xbmcplugin.getSetting( "quality" ) ) ] )
     # close the dialog
     pDialog.close()
     if ( not pDialog.iscanceled() ):
         # get cached thumbnail, no need to redownload
         g_thumbnail = xbmc.getCacheThumbName( sys.argv[ 0 ] + sys.argv[ 2 ] )
         g_thumbnail = os.path.join( xbmc.translatePath( "p:\\Thumbnails" ), "Video", g_thumbnail[ 0 ], g_thumbnail )
         # construct our listitem
         listitem = xbmcgui.ListItem( g_title, thumbnailImage=g_thumbnail )
         # set the key information
         listitem.setInfo( "video", { "Title": g_title, "Plotoutline": g_plotoutline, "Plot": g_plotoutline, "Director": g_director, "Genre": g_genre, "Rating": g_rating, "Date": g_date } )
         # set special property
         listitem.setProperty( "isVideo", "1" )
         listitem.setProperty( "RecommendLink", sys.argv[ 0 ] + sys.argv[ 2 ] )
         # Play video with the proper core
         xbmc.Player( self.player_core ).play( url, listitem )
 def add__favorite( self ):
     # Youtube client
     client = YoutubeClient( YoutubeClient.BASE_USERS_URL, self.authkey )
     client.add_favorites( self.args.video_id )
     return False, 0
Example #18
0
 def add__favorite(self):
     # Youtube client
     client = YoutubeClient(YoutubeClient.BASE_USERS_URL, self.authkey)
     client.add_favorites(self.args.video_id)
     return False, 0