예제 #1
0
    def _downloadImage( self, picname ):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s"%picname
        try:
        
            filetodlUrl = picname # image path on FTP server
            print "filetodlUrl"
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name( picname )
            print thumbnail
            print localFilePath
#            loc = urllib.URLopener()
#            loc.retrieve(filetodlUrl, localFilePath)   
            ftp = ftplib.FTP( self.host, self.user, self.password )
            localFile = open( localFilePath, "wb" )
            try:
                ftp.retrbinary( 'RETR ' + filetodlUrl, localFile.write )
            except:
                print "_downloaddossier: Exception - Impossible de telecharger le fichier: %s" % remoteFilePath
                print_exc()
                thumbnail, localFilePath = "", ""
            localFile.close()
            ftp.quit()

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile( localFilePath ):
                if os.path.getsize( localFilePath ) <= 0:
                    os.remove( localFilePath )
                    #TODO: create a thumb for the default image?
                    #TODO: return empty and manage default image at the level of the caller
                    thumbnail = "" 
                else:
                    thumb_size = int( self.thumb_size_on_load )
                    thumbnail = makeThumbnails( localFilePath, thumbnail, w_h=( thumb_size, thumb_size ) )
                    if thumbnail == "": thumbnail = localFilePath

#            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
#                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except Exception, e:
            #TODO: create a thumb for the default image?
            #TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", "" 
            print "_downloadImage: Exception - Impossible to download the picture: %s" % picname
            print_exc()
예제 #2
0
    def _downloadFile(self, remoteFilePath, isTBN=True, listitem=None):
        """
        Fonction de telechargement commune : version, archive, script de mise a jour
        """
        try:
            filetodlUrl = remoteFilePath
            if isTBN:
                thumbnail, localFilePath = set_cache_thumb_name(remoteFilePath)
            else:
                thumbnail = ""
                localFilePath = os.path.join(self.configManager.CACHEDIR,
                                             os.path.basename(remoteFilePath))

            name, ext = os.path.splitext(filetodlUrl)
            if ext and not os.path.isfile(localFilePath):
                ftp = ftplib.FTP(self.srvHost, self.srvUser, self.srvPassword)
                localFile = open(localFilePath, "wb")
                try:
                    ftp.retrbinary('RETR ' + filetodlUrl, localFile.write)
                except:
                    print "_downloaddossier: Exception - Impossible de telecharger le fichier: %s" % remoteFilePath
                    print_exc()
                    thumbnail, localFilePath = "", ""
                localFile.close()
                ftp.quit()

            # remove file if size is 0 bytes and report error if exists error
            if isTBN and localFilePath and os.path.isfile(localFilePath):
                if os.path.getsize(localFilePath) <= 0:
                    os.remove(localFilePath)
                else:
                    thumb_size = int(self.thumb_size_on_load)
                    thumbnail = makeThumbnails(localFilePath,
                                               thumbnail,
                                               w_h=(thumb_size, thumb_size))
                    if thumbnail == "": thumbnail = localFilePath

            if thumbnail and os.path.isfile(thumbnail) and hasattr(
                    listitem, "setThumbnailImage"):
                listitem.setThumbnailImage(thumbnail)
                listitem.setProperty("fanartpicture", "")
                listitem.setProperty("fanartpicture", thumbnail)
        except:
            print "_downloaddossier: Exception - Impossible de telecharger le fichier: %s" % remoteFilePath
            print_exc()
예제 #3
0
    def _downloadImage(self, picname):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s" % picname
        try:

            filetodlUrl = picname  # image path on FTP server
            print "filetodlUrl"
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name(picname)
            print thumbnail
            print localFilePath

            # Retrieve image
            if not self.passionFTPCtrl.downloadImage(filetodlUrl,
                                                     localFilePath):
                print "ERROR while retrieving image via FTP"
                thumbnail, localFilePath = "", ""

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile(localFilePath):
                if os.path.getsize(localFilePath) <= 0:
                    os.remove(localFilePath)
                    #TODO: create a thumb for the default image?
                    #TODO: return empty and manage default image at the level of the caller
                    thumbnail = ""
                else:
                    thumb_size = int(self.thumb_size_on_load)
                    thumbnail = makeThumbnails(localFilePath,
                                               thumbnail,
                                               w_h=(thumb_size, thumb_size))
                    if thumbnail == "": thumbnail = localFilePath

#            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
#                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except Exception, e:
            #TODO: create a thumb for the default image?
            #TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", ""
            print "_downloadImage: Exception - Impossible to download the picture: %s" % picname
            print_exc()
예제 #4
0
    def _downloadImage(self, picname):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s" % picname
        try:

            filetodlUrl = self.baseURLPreviewPicture + picname
            print "filetodlUrl"
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name(picname)
            print thumbnail
            print localFilePath
            loc = urllib.URLopener()
            loc.retrieve(filetodlUrl, localFilePath)

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile(localFilePath):
                if os.path.getsize(localFilePath) <= 0:
                    os.remove(localFilePath)
                    #TODO: create a thumb for the default image?
                    #TODO: return empty and manage default image at the level of the caller
                    thumbnail = ""
                else:
                    thumb_size = int(self.thumb_size_on_load)
                    thumbnail = makeThumbnails(localFilePath,
                                               thumbnail,
                                               w_h=(thumb_size, thumb_size))
                    if thumbnail == "": thumbnail = localFilePath

#            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
#                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except:
            print "_downloadImage: Exception - Impossible to downlod the picture: %s" % picname
            print_exc()
            #TODO: create a thumb for the default image?
            #TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", ""
        print "thumbnail = %s" % thumbnail
        print "localFilePath = %s" % localFilePath
        return thumbnail, localFilePath
예제 #5
0
    def _downloadImage(self, picname):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s" % picname
        try:

            filetodlUrl = picname  # image path on FTP server
            print "filetodlUrl"
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name(picname)
            print thumbnail
            print localFilePath

            # Retrieve image
            if not self.passionFTPCtrl.downloadImage(filetodlUrl, localFilePath):
                print "ERROR while retrieving image via FTP"
                thumbnail, localFilePath = "", ""

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile(localFilePath):
                if os.path.getsize(localFilePath) <= 0:
                    os.remove(localFilePath)
                    # TODO: create a thumb for the default image?
                    # TODO: return empty and manage default image at the level of the caller
                    thumbnail = ""
                else:
                    thumb_size = int(self.thumb_size_on_load)
                    thumbnail = makeThumbnails(localFilePath, thumbnail, w_h=(thumb_size, thumb_size))
                    if thumbnail == "":
                        thumbnail = localFilePath

            #            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
            #                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except Exception, e:
            # TODO: create a thumb for the default image?
            # TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", ""
            print "_downloadImage: Exception - Impossible to download the picture: %s" % picname
            print_exc()
예제 #6
0
    def _downloadFile( self, remoteFilePath, isTBN=True, listitem=None ):
        """
        Fonction de telechargement commune : version, archive, script de mise a jour
        """
        try:
            filetodlUrl = remoteFilePath
            if isTBN:
                thumbnail, localFilePath = set_cache_thumb_name( remoteFilePath )
            else:
                thumbnail = ""
                localFilePath = os.path.join( self.configManager.CACHEDIR, os.path.basename( remoteFilePath ) )

            name, ext = os.path.splitext( filetodlUrl )
            if ext and not os.path.isfile( localFilePath ):
                ftp = ftplib.FTP( self.srvHost, self.srvUser, self.srvPassword )
                localFile = open( localFilePath, "wb" )
                try:
                    ftp.retrbinary( 'RETR ' + filetodlUrl, localFile.write )
                except:
                    print "_downloaddossier: Exception - Impossible de telecharger le fichier: %s" % remoteFilePath
                    print_exc()
                    thumbnail, localFilePath = "", ""
                localFile.close()
                ftp.quit()

            # remove file if size is 0 bytes and report error if exists error
            if isTBN and localFilePath and os.path.isfile( localFilePath ):
                if os.path.getsize( localFilePath ) <= 0:
                    os.remove( localFilePath )
                else:
                    thumb_size = int( self.thumb_size_on_load )
                    thumbnail = makeThumbnails( localFilePath, thumbnail, w_h=( thumb_size, thumb_size ) )
                    if thumbnail == "": thumbnail = localFilePath

            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
                listitem.setThumbnailImage( thumbnail )
                listitem.setProperty( "fanartpicture", "" )
                listitem.setProperty( "fanartpicture", thumbnail )
        except:
            print "_downloaddossier: Exception - Impossible de telecharger le fichier: %s" % remoteFilePath
            print_exc()
예제 #7
0
    def _downloadImage( self, picname ):
        """
        Download picture from the server, save it, create the thumbnail and return path of it
        """
        print "_downloadImage %s"%picname
        try:
        
            filetodlUrl = self.baseURLPreviewPicture + picname
            print "filetodlUrl"            
            print filetodlUrl
            thumbnail, localFilePath = set_cache_thumb_name( picname )
            print thumbnail
            print localFilePath
            loc = urllib.URLopener()
            loc.retrieve(filetodlUrl, localFilePath)   

            # remove file if size is 0 bytes and report error if exists error
            if localFilePath and os.path.isfile( localFilePath ):
                if os.path.getsize( localFilePath ) <= 0:
                    os.remove( localFilePath )
                    #TODO: create a thumb for the default image?
                    #TODO: return empty and manage default image at the level of the caller
                    thumbnail = "" 
                else:
                    thumb_size = int( self.thumb_size_on_load )
                    thumbnail = makeThumbnails( localFilePath, thumbnail, w_h=( thumb_size, thumb_size ) )
                    if thumbnail == "": thumbnail = localFilePath

#            if thumbnail and os.path.isfile( thumbnail ) and hasattr( listitem, "setThumbnailImage" ):
#                listitem.setThumbnailImage( thumbnail )
            else:
                thumbnail, localFilePath = "", ""
        except:
            print "_downloadImage: Exception - Impossible to downlod the picture: %s" % picname
            print_exc()
            #TODO: create a thumb for the default image?
            #TODO: return empty and manage default image at the level of the caller
            thumbnail, localFilePath = "", "" 
        print "thumbnail = %s"%thumbnail
        print "localFilePath = %s"%localFilePath
        return thumbnail, localFilePath
예제 #8
0
        def _load_movie_info( movie ):
            def _set_default_movie_info( movie ):
                self.idMovie = movie[ 0 ]
                self.title = movie[ 1 ]
                self.urls = eval( movie[ 2 ] )
                self.trailer_urls = []
                self.old_trailer_urls = []
                if ( movie[ 3 ] is not None ):
                    self.old_trailer_urls = eval( movie[ 3 ] )
                    self.old_trailer_urls.sort()
                self.poster = ""
                self.plot = ""
                self.rating = ""
                self.rating_url = ""
                self.release_date = ""
                self.runtime = ""
                if ( movie[ 10 ] ):
                    self.times_watched = movie[ 10 ]
                else:
                    self.times_watched = 0
                if ( movie[ 11 ] ):
                    self.last_watched = movie[ 11 ]
                else:
                    self.last_watched = ""
                if ( movie[ 12 ] ):
                    self.favorite = movie[ 12 ]
                else:
                    self.favorite = 0
                if ( movie[ 13 ] ):
                    self.saved = eval( movie[ 13 ] )
                else:
                    self.saved = []
                if ( movie[ 14 ] is not None ):
                    self.date_added = movie[ 14 ].replace( "u", "" )
                else:
                    self.date_added = str( datetime.date.today() )
                self.actors = []
                self.studio = ""

            try:
                _set_default_movie_info( movie )
                date_added = str( datetime.date.today() )
                
                # get the main index xml file
                for url in self.urls:
                    if "index" in url:
                        if ( not url.startswith( "http://" ) ):
                            url = self.base_url + str( url )
                        break
                # xml parsing. replace <b> and </b> for in theaters. TODO: remove if noticeably slower
                source = fetcher.urlopen( url ).replace( "<b>", "" ).replace( "</b>", "" )
                try:
                    element = ET.fromstring( source )
                except:
                    source = self.cleanXML( source.decode( "utf-8", "replace" ).encode( "utf-8", "ignore" ) )
                    element = ET.fromstring( source )
                
                # -- poster & thumbnails --
                poster = element.getiterator( self.ns( "PictureView" ) )[ 1 ].get( "url" )
                if poster:
                    # if it's not the full url add the base url
                    if ( not poster.startswith( "http://" ) ):
                        poster = self.base_movie_url + str( poster )
                    # download the actual poster to the local filesystem (or get the cached filename)
                    poster = fetcher.urlretrieve( poster )
                    if poster:
                        # make thumbnails
                        success = pil_util.makeThumbnails( poster )
                        self.poster = os.path.basename( poster )

                # -- plot --
                plot = element.getiterator( self.ns( "SetFontStyle" ) )[ 2 ].text.strip()#encode( "ascii", "ignore" ).strip()
                if plot:
                    # remove any linefeeds so we can wrap properly to the text control this is displayed in
                    plot = plot.replace( "\r\n", " " )
                    plot = plot.replace( "\r", " " )
                    plot = plot.replace( "\n", " " )
                    self.plot = plot
                
                # -- release date --
                release_date = element.getiterator( self.ns( "SetFontStyle" ) )[ 3 ].text.strip()
                if release_date and "In Theaters:" in release_date:
                    self.release_date = release_date.split( ":" )[ 1 ].strip()

                # -- actors --
                SetFontStyles = element.getiterator( self.ns( "SetFontStyle" ) )
                actors = list()
                for i in range( 5, 10 ):
                    actor = SetFontStyles[ i ].text.replace( "(The voice of)", "" ).title().strip()
                    if ( len( actor ) and not actor.startswith( "." ) and actor != "1:46" and not actor.startswith( "Posted:" ) and not actor.startswith( "Runtime:" ) and not actor == "Available Clips" and not actor == "Official Website" and not actor.startswith( "Trailer" ) ) :
                        actors += [ ( actor, ) ]
                        actor_id = records.fetch( self.query[ "actor_exists" ], ( actor, ) )
                        if ( actor_id is None ): idActor = records.add( "actors", ( actor, ) )
                        else: idActor = actor_id[ 0 ]
                        records.add( "actor_link_movie", ( idActor, self.idMovie, ) )
                self.actors = actors
                self.actors.sort()

                # -- runtime --
                try:
                    runtime = element.getiterator( self.ns( "SetFontStyle" ) )[ 13 ].text
                    if runtime and "Runtime" in runtime:
                        runtime = runtime.replace( "Runtime", "" ).replace( ":", "" ).replace( ".", "" ).strip().rjust( 4, "0" )
                        runtime = "%s:%s" % ( runtime[ : 2 ], runtime[ 2 : ], )
                        self.runtime = runtime
                except:
                    pass

                # -- studio --
                studio = element.getiterator( self.ns( "PathElement" ) )[ 1 ].get( "displayName" ).strip()
                if studio:
                    studio_id = records.fetch( self.query[ "studio_exists" ], ( studio, ) )
                    if ( studio_id is None ): idStudio = records.add( "studios", ( studio, ) )
                    else: idStudio = studio_id[ 0 ]
                    records.add( "studio_link_movie", ( idStudio, self.idMovie, ) )
                    self.studio = studio

                # -- rating --
                temp_url = element.getiterator( self.ns( "PictureView" ) )[ 2 ].get( "url" )
                if temp_url:
                    if "/mpaa" in temp_url:
                        if ( not temp_url.startswith( "http://" ) ):
                            if ( not temp_url.startswith( "/" ) ):
                                tmp_url = "/" + tmp_url
                            temp_url = "http://images.apple.com" + temp_url
                        rating_url = fetcher.urlretrieve( temp_url )
                        if rating_url:
                            self.rating_url = os.path.basename( rating_url )
                            self.rating = os.path.split( temp_url )[ 1 ][ : -4 ].replace( "mpaa_", "" )

                # TODO: maybe parse the index xml file(s) for other trailer xml files, keeping as a list of lists, so user can select
                # -- trailer urls --
                # get all url xml files
                for each in element.getiterator( self.ns( "GotoURL" ) ):
                    temp_url = each.get( "url" )
                    if not temp_url.endswith( ".xml" ): continue
                    if "/moviesxml/g" in temp_url: continue
                    if temp_url in self.urls: continue
                    self.urls += [ temp_url ]
                all_urls = ()
                for xml_url in self.urls:
                    new_xml_url = self.base_url + xml_url
                    if new_xml_url != url:
                        # xml parsing. replace <b> and </b> for in theaters. remove if noticeably slower
                        source = fetcher.urlopen( new_xml_url ).replace( "<b>", "" ).replace( "</b>", "" )
                        try:
                            element = ET.fromstring( source )
                        except:
                            source = self.cleanXML( source.decode( "utf-8", "replace" ).encode( "utf-8", "ignore" ) )
                            try:
                                element = ET.fromstring( source )
                            except:
                                continue
                    urls = ()
                    for each in element.getiterator( self.ns( "string" ) ):
                        text = each.text
                        # invalid urls
                        if text is None: continue
                        if not text.endswith( ".mov" ): continue
                        new_url = text.replace( "//", "/" ).replace( "/", "//", 1 )
                        if new_url in all_urls:
                            add_trailer = False
                        else:
                            add_trailer = True
                            all_urls += ( new_url, )
                        # add the trailer url to our list
                        if add_trailer:
                            urls += ( text.replace( "//", "/" ).replace( "/", "//", 1 ), )
                    if len( urls ):
                        self.trailer_urls += [ urls ]
                self.trailer_urls.sort()
                if ( self.trailer_urls == self.old_trailer_urls ):
                    date_added = self.date_added
            except:
                print "Trailer XML %s: %s is %s" % ( self.idMovie, repr( url ), ( "missing", "corrupt" )[ os.path.isfile( fetcher.make_cache_filename( url ) ) ] )

            info_list = ( self.idMovie, self.title, repr( self.urls ), repr( self.trailer_urls ), self.poster, self.plot, self.runtime,
                            self.rating, self.rating_url, self.release_date, self.times_watched, self.last_watched, self.favorite,
                            repr( self.saved ), date_added, self.actors, self.studio, )
            success = records.update( "movies", ( 2, 15, ), ( info_list[ 2 : 15 ] ) + ( self.idMovie, ), "idMovie" )
            return info_list