Example #1
0
    def search(self, searchReq):
        query = Session().query(MediaObject).filter(MediaObject.source==self.__module__)
        
        if isinstance(searchReq, dict):
            search_title = searchReq.get('title')
            search_artist = searchReq.get('artist')
            search_album = searchReq.get('album')

            if search_title:
                query = query.filter(MediaObject.title.like("%"+search_title+"%"))

            if search_artist:
                query = query.filter(MediaObject.artist.like("%"+search_artist+"%"))

            if search_album:
                query = query.filter(MediaObject.album.like("%"+search_album+"%"))
        else:
            searchText = "%" + searchReq + "%"

            query = query.filter(or_(
                MediaObject.title.like(searchText),
                MediaObject.album.like(searchText),
                MediaObject.artist.like(searchText)
                ))
            
        mediaList = []
        
        for row in query:
            mediaList.append(row)

        return mediaList
Example #2
0
def play():
    global __activeSource
    global __activeQueue
    
    session = Session()
    nextItem = session.query(Queue).filter(Queue.play_date==None).order_by(Queue.queue_date).first()
    
    if nextItem:
        log.msg("Playing %s" % nextItem.media_object)
        __activeSource = __runningPlugins[str(nextItem.media_object.source)]
        __activeQueue = nextItem
        nextItem.setPlayed()
        __activeSource.play(nextItem.media_object)
        session.commit()
        
        for key, mediactr in __controllers.items():
            log.msg("\tSending Queue Change to %s" % key)
            mediactr.queueUpdated(QueueActions.PLAY, __activeQueue)

    else:
        log.msg("Queue Is Empty")
Example #3
0
def remQueuedItem(remId):
    mysession = Session()
    item = mysession.query(Queue).filter(Queue.media_object_id==remId, Queue.play_date==None).first()
    
    if item:
        mysession.delete(item)
        mysession.commit()

        for key, mediactr in __controllers.items():
            log.msg("\tSending Queue Change to %s" % key)
            mediactr.queueUpdated(QueueActions.REMOVE, item)
        return True
            
    return False
Example #4
0
def queue(mediaObj):
    log.msg("Queueing %s" % mediaObj)
    
    session = Session()
    inQueue = session.query(Queue).filter(Queue.media_object==mediaObj).filter(Queue.play_date==None).first()

    if not inQueue:
        qob = Queue(mediaObj)
        session.add(qob)
        session.commit()
    
        if not __activeSource:
            play()
        else:
            for key, mediactr in __controllers.items():
                log.msg("\tSending Queue Change to %s" % key)
                mediactr.queueUpdated(QueueActions.ADD, qob)
        return True
    else:
        return False
Example #5
0
    def readFiles(self):
        print "Starting to index files"
        session = Session()
        fileList = []
        hashList = []
        for d in ["/home/jlew/Music","/home/jlew/BACKUP_TO_SORT/Music"]:
            for root, dirs, files in os.walk(d):
                for f in files:
                    fileList.append( root + "/" + f )
        
        fileLen = len(fileList)
        print "Found %d Files" % fileLen
        
        for i,f in enumerate(fileList):
            filePath = f.decode('utf-8')
            filePathSha = sha1(filePath).hexdigest()
            hashList.append(filePathSha)
            fileTime = str(os.path.getmtime(f)).decode('UTF-8')
            
            item = session.query(MediaObject)\
                .filter(MediaObject.source_id==filePathSha)\
                .filter(MediaObject.source==self.__module__).first()
            
            if item:
                if item.valid == False:
                    item.setValid(True)
                    
                for attribute in item.attributes:
                    if attribute.key == u"filetime" and attribute.value != fileTime:                        
                        title,artist,album = self.getTagInfo(f)
                        item.title = title
                        item.artist = artist
                        item.album = album
                        attribute.value = fileTime
                        print "Updated", item
            else:    
                title,artist,album = self.getTagInfo(f)
                print "Indexed %s %s %s" % (artist,album, title)
                
                m = MediaObject(self.__module__,title,artist,album, source_id = filePathSha)
                session.add(m)
                session.flush() # Flush the session so we get the ID
                session.add(MediaObjectAttribute(m.id,u"filename", filePath))
                session.add(MediaObjectAttribute(m.id,u"filetime", fileTime))

            if (i % 500) == 0:
                print "Commiting Batch"
                session.commit()
            
        session.commit()
        
        # Invalidate Files that are no longer found
        print "Files indexed, checking for missing files"
        query = session.query(MediaObject)\
                .filter(MediaObject.source==self.__module__)\
                .filter(MediaObject.valid==True)
                
        for obj in query:
            if obj.source_id not in hashList:
                print "DEACTIVATED", obj
                obj.setValidState(False)
        session.commit()
        session.close()
        print "File Indexing Completed"