Exemple #1
0
    def process(self, filepath, langs):
        ''' main method to call on the plugin, pass the filename and the wished 
        languages and it will query OpenSubtitles.org '''

	subs = []
        filehash = self.hashFile(filepath)
        # disabled this part because getFileSize gives negative values for large files
        # on BoxeeBox, which makes this useless for larger movies
	fname = self.getFileName(filepath)
        if xbmc.getFileSize(filepath):
            log.debug(filehash)
            size = long(xbmc.getFileSize(filepath))
            fname = self.getFileName(filepath)
            subs += self.query(moviehash=filehash, langs=langs, bytesize=size, filename=fname)
  
        subs += self.query(langs=langs, filename=fname)
	return subs
    def getFileName(self, filepath):
        if xbmc.getFileSize(filepath):
            filename = os.path.basename(filepath)
            log.warn("This is a file")
        else:
            filename = filepath
            log.warn("This is not a file")
        fname = filename

        # if filename.endswith(('.avi', '.wmv', '.mov', '.mp4', '.mpeg', '.mpg', '.mkv')):
        #    fname = filename.rsplit('.', 1)[0]
        # else:
        #    fname = filename
        return fname
Exemple #3
0
    def search_subtitles( self ):
        try:
            if ( len( self.file_path ) > 0 ):
                LOG( LOG_INFO, _( 642 ) % ( os.path.basename( self.file_path ), ) )
                self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "...", ) )
                #ok,msg = self.osdb_server.searchsubtitlesbyhash( self.file_path )#, "en" )
                self.set_filehash( xbmc.getFileHash( self.file_original_path ) )
                self.set_filesize( xbmc.getFileSize( self.file_original_path ) )    
                ok,msg = self.osdb_server.searchsubtitles( self.file_path, self.file_hash, self.file_size )#, "en" )
                LOG( LOG_INFO, msg )        
            if ( len( self.search_string ) > 0 ):
                LOG( LOG_INFO, _( 642 ) % ( os.path.basename( self.search_string ), ) )
                self.getControl( STATUS_LABEL ).setLabel( _( 642 ) % ( "......", ) )
                ok2,msg2 = self.osdb_server.searchsubtitlesbyname( self.search_string )#, "en" )
                LOG( LOG_INFO, msg2 )
            self.osdb_server.mergesubtitles()
            if not ok and not ok2:
                self.getControl( STATUS_LABEL ).setLabel( _( 634 ) % ( msg, ) )
            elif self.osdb_server.subtitles_list:
                for item in self.osdb_server.subtitles_list:
                    listitem = xbmcgui.ListItem( label=item["language_name"], label2=item["filename"], iconImage=item["rating"], thumbnailImage=item["language_flag"] )
                    #self.getControl( SUBTITLES_LIST ).addItem( xbmcgui.ListItem( item["filename"], item["language_name"], iconImage=item["rating"], thumbnailImage = item["language_flag"] ) )
                    if item["sync"]:
                        listitem.setProperty( "sync", "true" )
                    else:
                        listitem.setProperty( "sync", "false" )
                    self.getControl( SUBTITLES_LIST ).addItem( listitem )

#            elif msg:
#                self.getControl( STATUS_LABEL ).setLabel( msg )

            self.setFocus( self.getControl( SUBTITLES_LIST ) )
            self.getControl( SUBTITLES_LIST ).selectItem( 0 )

        except Exception, e:
            error = _( 634 ) % ( "search_subtitles:" + str ( e ) ) 
            LOG( LOG_ERROR, error )
            return False, error