Beispiel #1
0
    def _doRescan(self):
        
        validExtensions = ['mp4', 'mkv', 'avi', ]
        
        for library in Library.query.all():
            print library.root
            
            #knownMovies = Movie.query.select(Movie.path).filter(Movie.library==library).all() 
            knownMovies = db_session.query(Movie.path).filter(Movie.library==library).all()
            
            knownFiles = [m[0] for m in knownMovies]
            
            #print 'ALL KNOWN', knownFiles
            
            files = []
            newMovies = []
            
            libraryRoot = library.root.encode('utf-8')
            
            #tmpcounter = 0
            
            for dirpath, dirnames, filenames in os.walk(libraryRoot):
                for f in filenames:
                    ext = os.path.splitext(f)[1][1:]
                    if ext in validExtensions:
                        #print dirpath, "::", f
                        relpath = unicode(os.path.join(dirpath[len(libraryRoot):], f), 'utf_8', 'replace')
                        
                        if relpath in knownFiles:
                            continue
                        
                        print 'NEW MOVIE:', relpath
                        #else: print relpath
                        
                        #print relpath
                        
                        #tmpcounter += 1
                        #if tmpcounter % 9 == 0:
                        #    continue
                        
                        movie = Movie(library=library, path=relpath)
                        newMovies.append(movie)
                        print 'ADDING MOVIE:', movie
                        db_session.add(movie)
                        
                        #fp = os.path.join(dirpath, f)
                        #files.append(fp)

            #print 'COMMITING', transaction
            #transaction.commit()
            db_session.commit()
            print 'COMMIT DONE', newMovies
        
        self.rescanStatus = 'idle'
Beispiel #2
0
def shutdown_seesion(exception=None):
    from videodb.db import db_session

    db_session.commit()
    db_session.remove()
Beispiel #3
0
def shutdown_seesion(exception=None):
    from videodb.db import db_session
    
    db_session.commit()
    db_session.remove()