Beispiel #1
0
    def search_subtitles_sub( self ):
        self.getControl( 111 ).setVisible( True )
        self.getControl( 110 ).setVisible( False )
        self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "...", ) )
        sublightWebService = SublightUtils.SublightWebService()
        session_id = sublightWebService.LogInAnonymous()
        self.set_session(session_id)

        movie_title = self.search_string.replace ("+"," ")

        video_hash = ""

        if not self.set_xbox and not self.file_original_path.find("http") > -1 :
#            md5_video_hash = SublightUtils.calculateMD5VideoHash( self.file_original_path )
#            video_hash     = sublightWebService.GetFullVideoHash( session_id, md5_video_hash )
            video_hash     = SublightUtils.calculateVideoHash( self.file_original_path )
        if video_hash == "":
            video_hash = "0000000000000000000000000000000000000000000000000000"

        subtitles = []
        language1 = SublightUtils.toSublightLanguage( self.lang1 )
        language2 = SublightUtils.toSublightLanguage( self.lang2 )
        language3 = SublightUtils.toSublightLanguage( self.lang3 )

        season = xbmc.getInfoLabel("VideoPlayer.Season")
        episode = xbmc.getInfoLabel("VideoPlayer.Episode")
        epchck = episode.lower()
        if epchck.find("s") > -1:
            season = "0"
            episode = episode.replace("s","")
            episode = episode.replace("S","")
        
        title = xbmc.getInfoLabel("VideoPlayer.TVshowtitle")


        if (len(episode) > -1):
            movie_year = ""

        if not (len(title) > 0) or self.manuall:        
            movie_title = self.search_string.replace ("+"," ")
            episode = ""
            season = ""
            movie_year = ""
        else:
            movie_title = title     
        search_string1 = unicode(movie_title, 'utf-8')
        movie_title1 = unicodedata.normalize('NFKD', unicode(search_string1)).encode('ascii','ignore')
        if self.year == 0: 
            year = ""
        else:
            year = str(self.year)
                
        if self.debug :         
            LOG( LOG_INFO, "Sublight Hash [%s]" , str(video_hash) )
            LOG( LOG_INFO, "Sublight Language 1: [%s], Language 2: [%s], Language 3: [%s]" , language1 ,language2 , language3)
            LOG( LOG_INFO, "Sublight Search Title:[%s] , Season:[%s] , Episode:[%s] Year:[%s]" , movie_title1,season,episode,year )
        self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "......", ) )
        subtitles = sublightWebService.SearchSubtitles(session_id, video_hash, movie_title1, year,season, episode, language2, language1, language3 )

        self.set_subtitles(subtitles)
        
        label = ""
        self.list = []                    
        if self.OS :
            label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (  _( 610 ) + " OpenSubtitles.org" )
            listitem = xbmcgui.ListItem( label,label2 )
            self.list.append("OS")
            self.getControl( SUBTITLES_LIST ).addItem( listitem )
        if self.PN :
            label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (  _( 610 ) + " Podnapisi.net" )
            listitem = xbmcgui.ListItem( label,label2 )
            self.list.append("PN")                               
            self.getControl( SUBTITLES_LIST ).addItem( listitem )
        if self.mansearch :
            label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (  _( 612 ) )
            listitem = xbmcgui.ListItem( label,label2 )
            self.list.append("MN")                                
            self.getControl( SUBTITLES_LIST ).addItem( listitem )
                                        


        if len(subtitles) != 0 :
            subscounter = 0
            for subtitle in subtitles:
        
                release       =                          subtitle[ "release" ]
                language      =                          subtitle[ "language" ]
                isLinked      =                          subtitle[ "isLinked" ]
                rate          =                          subtitle[ "rate" ]
                icon_flag     = "flags/" + toOpenSubtitles_two(language) + ".gif"
               
                listitem = xbmcgui.ListItem( label=language, label2=release, thumbnailImage=icon_flag, iconImage=str(int(round(rate*2))) )

                if isLinked == "true" :
                    listitem.setProperty( "sync", "true" )
                else:
                    listitem.setProperty( "sync", "false" )
                self.list.append(subscounter)
                subscounter = subscounter + 1                     
                self.getControl( SUBTITLES_LIST ).addItem( listitem )
        

        self.getControl( STATUS_LABEL ).setLabel( str( len ( self.subtitles ) ) +  _( 744 ) + '"' + self.file_name + '"' )
        self.setFocus( self.getControl( SUBTITLES_LIST ) )
        self.getControl( SUBTITLES_LIST ).selectItem( 0 )
        if self.debug : LOG( LOG_INFO,"Service "+self.service)
    def __init__( self ) :
        #
        # Init
        #
        IMAGES_PATH        = xbmc.translatePath( os.path.join( os.getcwd(), 'resources', 'images' ) )
        sublightWebService = SublightUtils.SublightWebService()
        
        #
        # Parse parameters...
        #
        params   = dict(part.split('=') for part in sys.argv[ 2 ][ 1: ].split('&'))        
        searchBy = params[ "search_by" ]

        #
        # Playing movie...
        #
        if searchBy == "playing" :
            movieFullPath = xbmc.Player().getPlayingFile()
        #
        # Browse for movie file...
        #
        else :
            # Get last location (get up one level if path doesn't exist anymore)...
            lastMoviePath = xbmcplugin.getSetting ("lastMoviePath")
            while lastMoviePath != ""   and         \
                  lastMoviePath != "\\" and         \
                  not os.path.exists(lastMoviePath) :
                lastMoviePath = os.path.dirname(lastMoviePath)
            
            # Browse dialog...
            browse = xbmcgui.Dialog()
            movieFullPath = browse.browse(1, xbmc.getLocalizedString(30200), "video", ".avi|.mp4|.mpg|.mpeg|.wmv|.asf|.divx|.mov|.m2p|.moov|.omf|.qt|.rm|.vob|.dat|.dv|.3ivx|.mkv|.ogm", False, False, lastMoviePath)
            
            # No file selected (exit)...
            if not os.path.isfile(movieFullPath) :
                xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=False )
                return

            # Save last location...
            lastMoviePath = os.path.join(os.path.dirname(movieFullPath), "")
            xbmcplugin.setSetting("lastMoviePath", lastMoviePath)

        # Split in dir and filename...
        movie_dir  = os.path.dirname  (movieFullPath)
        movie_file = os.path.basename (movieFullPath)
        
        #
        # (By Title) Confirm movie title...
        #
        movie_title, movie_year = "", ""
        if searchBy == "title" :
            # Attempt to extract the movie title and year from the file name... 
            movie_title, movie_year = SublightUtils.getMovieTitleAndYear( movie_file )            
            
            #
            # Get a list of similar titles from the webservice...
            #
            movies = sublightWebService.SuggestTitles( movie_title )

            # Ask the user to choose a movie entry...
            if len( movies ) > 0:
                options = []
                for movie in movies :
                   option = "%s (%s)" % ( movie[ "title" ], movie [ "year" ] )
                   options.append( option )
                   
                dialog = xbmcgui.Dialog()
                choice = dialog.select( xbmc.getLocalizedString(30307), options )
                dialog = None
                
                # User made a choice...
                if choice > -1 :
                    movie       = movies[ choice ];
                    movie_title = movie[ "title"]
                    movie_year  = movie[ "year" ]
                # User cancelled...
                else :
                    xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=False )
                    return
            #             
            # No matching results...
            #
            else :
                #
                # Ask the user to confirm movie title and year...
                #
                if movie_year != "" :
                    text = "%s (%s)" % ( movie_title, movie_year )
                else :
                    text = "%s"      % ( movie_title )
                            
                keyboard = xbmc.Keyboard( text )
                keyboard.doModal()
                if keyboard.isConfirmed() :
                    movie_title, movie_year = SublightUtils.getMovieTitleAndYear( keyboard.getText() )
                else :
                    xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=False )
                    return
        
        #
        # (WebService) Login...
        #
        dp = xbmcgui.DialogProgress()
        dp.create("Sublight" )
        dp.update( 33, xbmc.getLocalizedString(30300), " ", " " )        
        
        # Get session id...
        session_id = sublightWebService.LogInAnonymous()

        #
        # (By video hash) Calculate video hash...
        #
        video_hash = "0000000000000000000000000000000000000000000000000000"
        if searchBy == "hash" :
            video_hash     = SublightUtils.calculateVideoHash( movieFullPath, False )
        
        #
        # (By playing movie) Calculate video hash...
        #
        if searchBy == "playing" :
            videoInfoTag = xbmc.Player().getVideoInfoTag()
            movie_title = videoInfoTag.getTitle()
            movie_year  = ( videoInfoTag.getYear(), "" ) [ videoInfoTag.getYear() == 0 ]
            
            # No movie title, ask user...
            if movie_title == "" :
                keyboard = xbmc.Keyboard( "", xbmc.getLocalizedString(30107) )
                keyboard.doModal()
                if keyboard.isConfirmed() :
                    movie_title, movie_year = SublightUtils.getMovieTitleAndYear( keyboard.getText() )
            
            # Calculate hash...
            video_hash  = SublightUtils.calculateVideoHash( movieFullPath, True )
        
        #
        # (WebService) Search...
        #
        if searchBy == "hash" :
            message = movie_file
        elif searchBy == "title" :                                                            
            message = ( "%s (%s)" % ( movie_title, movie_year ), "%s" % ( movie_title ) ) [ movie_year == "" ]
        elif searchBy == "playing" :
            message = ( "%s (%s)" % ( movie_title, movie_year ), "%s" % ( movie_file ) )  [ movie_year == "" ]
        dp.update( 66, xbmc.getLocalizedString(30301), message, " " )

        # Searching...
        subtitles = []
        language1 = SublightUtils.toSublightLanguage( str( int( xbmcplugin.getSetting ("language1") ) + 1 ) )
        language2 = SublightUtils.toSublightLanguage(           xbmcplugin.getSetting ("language2") )
        language3 = SublightUtils.toSublightLanguage(           xbmcplugin.getSetting ("language3") )
        subtitles = sublightWebService.SearchSubtitles(session_id, video_hash, movie_title, movie_year, language1, language2, language3 )
        
        #
        # No subtitles found...
        #
        if len(subtitles) == 0 :
            # Close dialog progress...
            dp.close()
            
            # Message...
            dialog = xbmcgui.Dialog()
            dialog.ok("Sublight", xbmc.getLocalizedString(30305))
            dialog = None

            # End of directory...
            xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=False )
            
        #
        # Subtitles found...
        #
        else:
            for subtitle in subtitles:
                subtitle_id   =                          subtitle[ "subtitleID" ]
                title         =                          subtitle[ "title" ]
                year          = SublightUtils.toInteger( subtitle[ "year" ] )
                release       =                          subtitle[ "release" ]
                language      =                          subtitle[ "language" ]
                mediaType     =                          subtitle[ "mediaType" ]
                numberOfDiscs = SublightUtils.toInteger( subtitle[ "numberOfDiscs" ] )
                downloads     =                          subtitle[ "downloads" ]
                isLinked      =                          subtitle[ "isLinked" ]                
                icon_flag     = os.path.join( IMAGES_PATH, "flag_%s.gif" % language.lower())
                
                # Add directory entry...
                label  = "[%s]  %s" % ( language, release )
                if isLinked == "true" :
                    label2 = "[COLOR=FF00FF00]%s downloads [%u x %s][/COLOR]" % ( downloads, numberOfDiscs, mediaType )
                else:
                    label2 = "%s downloads [%u x %s]" % ( downloads, numberOfDiscs, mediaType )
                
                listitem = xbmcgui.ListItem( label, label2, "DefaultVideoBig.png", icon_flag )
                listitem.setInfo( type="Video", infoLabels={ "Title" : label, "Genre" : label2, "Year" : year  } )
                url = "%s?action=download&session_id=%s&subtitle_id=%s&subtitle_lang=%s&movie_dir=%s&movie_file=%s&number_of_discs=%u" % \
                    ( sys.argv[ 0 ], urllib.quote_plus( session_id ), urllib.quote_plus( subtitle_id ), urllib.quote_plus( language ), urllib.quote_plus( movie_dir ), urllib.quote_plus( movie_file ), numberOfDiscs )
                xbmcplugin.addDirectoryItem( handle = int(sys.argv[ 1 ]), url=url, listitem=listitem, isFolder=False)
    
            # Allow sort by Genre (for list2 labels)...
            xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_GENRE )            
        
            # End of directory...
            xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True )
Beispiel #3
0
    def search_subtitles_sub(self):
        self.getControl(111).setVisible(True)
        self.getControl(110).setVisible(False)
        self.getControl(STATUS_LABEL).setLabel(_(642) % ("...", ))
        sublightWebService = SublightUtils.SublightWebService()
        session_id = sublightWebService.LogInAnonymous()
        self.set_session(session_id)

        movie_title = self.search_string.replace("+", " ")

        video_hash = ""

        if not self.set_xbox and not self.file_original_path.find("http") > -1:
            #            md5_video_hash = SublightUtils.calculateMD5VideoHash( self.file_original_path )
            #            video_hash     = sublightWebService.GetFullVideoHash( session_id, md5_video_hash )
            video_hash = SublightUtils.calculateVideoHash(
                self.file_original_path)
        if video_hash == "":
            video_hash = "0000000000000000000000000000000000000000000000000000"

        subtitles = []
        language1 = SublightUtils.toSublightLanguage(self.lang1)
        language2 = SublightUtils.toSublightLanguage(self.lang2)
        language3 = SublightUtils.toSublightLanguage(self.lang3)

        season = xbmc.getInfoLabel("VideoPlayer.Season")
        episode = xbmc.getInfoLabel("VideoPlayer.Episode")
        epchck = episode.lower()
        if epchck.find("s") > -1:
            season = "0"
            episode = episode.replace("s", "")
            episode = episode.replace("S", "")

        title = xbmc.getInfoLabel("VideoPlayer.TVshowtitle")

        if (len(episode) > -1):
            movie_year = ""

        if not (len(title) > 0) or self.manuall:
            movie_title = self.search_string.replace("+", " ")
            episode = ""
            season = ""
            movie_year = ""
        else:
            movie_title = title
        search_string1 = unicode(movie_title, 'utf-8')
        movie_title1 = unicodedata.normalize('NFKD',
                                             unicode(search_string1)).encode(
                                                 'ascii', 'ignore')
        if self.year == 0:
            year = ""
        else:
            year = str(self.year)

        if self.debug:
            LOG(LOG_INFO, "Sublight Hash [%s]", str(video_hash))
            LOG(
                LOG_INFO,
                "Sublight Language 1: [%s], Language 2: [%s], Language 3: [%s]",
                language1, language2, language3)
            LOG(
                LOG_INFO,
                "Sublight Search Title:[%s] , Season:[%s] , Episode:[%s] Year:[%s]",
                movie_title1, season, episode, year)
        self.getControl(STATUS_LABEL).setLabel(_(642) % ("......", ))
        subtitles = sublightWebService.SearchSubtitles(session_id, video_hash,
                                                       movie_title1, year,
                                                       season, episode,
                                                       language2, language1,
                                                       language3)

        self.set_subtitles(subtitles)

        label = ""
        self.list = []
        if self.OS:
            label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(610) +
                                                     " OpenSubtitles.org")
            listitem = xbmcgui.ListItem(label, label2)
            self.list.append("OS")
            self.getControl(SUBTITLES_LIST).addItem(listitem)
        if self.PN:
            label2 = "[COLOR=FFFF0000]%s[/COLOR]" % (_(610) + " Podnapisi.net")
            listitem = xbmcgui.ListItem(label, label2)
            self.list.append("PN")
            self.getControl(SUBTITLES_LIST).addItem(listitem)
        if self.mansearch:
            label2 = "[COLOR=FF00FF00]%s[/COLOR]" % (_(612))
            listitem = xbmcgui.ListItem(label, label2)
            self.list.append("MN")
            self.getControl(SUBTITLES_LIST).addItem(listitem)

        if len(subtitles) != 0:
            subscounter = 0
            for subtitle in subtitles:

                release = subtitle["release"]
                language = subtitle["language"]
                isLinked = subtitle["isLinked"]
                rate = subtitle["rate"]
                icon_flag = "flags/" + toOpenSubtitles_two(language) + ".gif"

                listitem = xbmcgui.ListItem(label=language,
                                            label2=release,
                                            thumbnailImage=icon_flag,
                                            iconImage=str(int(round(rate *
                                                                    2))))

                if isLinked == "true":
                    listitem.setProperty("sync", "true")
                else:
                    listitem.setProperty("sync", "false")
                self.list.append(subscounter)
                subscounter = subscounter + 1
                self.getControl(SUBTITLES_LIST).addItem(listitem)

        self.getControl(STATUS_LABEL).setLabel(
            str(len(self.subtitles)) + _(744) + '"' + self.file_name + '"')
        self.setFocus(self.getControl(SUBTITLES_LIST))
        self.getControl(SUBTITLES_LIST).selectItem(0)
        if self.debug: LOG(LOG_INFO, "Service " + self.service)