Пример #1
0
def testbench_build_library():
    library = []
    time = DateTime.now()
    for i in range(30):
        song = Song("C:/Folder%d/Artist%d/Title%d.mp3" % (i, i, i))
        song[MpMusic.ARTIST] = u"%dArtist The Band" % (
            i % 10)  # id will have 10 different A,B,T
        song[MpMusic.TITLE] = u"%dTitle of The Song" % (i % 10)
        song[MpMusic.ALBUM] = u"%dMonthly Album" % (i % 10)
        song[MpMusic.GENRE] = (u"ROCK", u"POP", "ALT")[(i % 3)]
        song[MpMusic.DATEVALUE] = time - (60 * 60 * 24 * i
                                          )  # each song is one day older
        song[MpMusic.DATESTAMP] = DateTime.formatDateTime(
            song[MusicContainer.DATEVALUE])
        song[MpMusic.COMMENT] = ""
        song[MpMusic.RATING] = i % 6  # in 30 songs, 5 of each rating value
        song[MpMusic.LENGTH] = 15 * i
        song[MpMusic.SONGINDEX] = 0
        song[MpMusic.PLAYCOUNT] = i
        song[MpMusic.SKIPCOUNT] = i
        song[MpMusic.FILESIZE] = 0
        song[MpMusic.FREQUENCY] = 2 * i
        song[MpMusic.BITRATE] = 0
        song[MpMusic.SPECIAL] = False
        song[MpMusic.SELECTED] = False

        song.update()

        library.append(song)
    return library
Пример #2
0
    def updateSongRecord(self,song,newtime=-1):
        # update the given song because it has just finished playing
        # update the lengths if there is a discrepancy using newtime as the new length
        if song == None:
            debug("None Song Passed to updateSongRecord")
            return
        
        if newtime >= 0:
            if (newtime < song[MpMusic.LENGTH]-1 or newtime > song[MpMusic.LENGTH]+1) and newtime > 1 :
                MpGlobal.Window.emit(SIGNAL("DEBUG_MESSAGE"),"%s : OldTime: %d NewTime: %d"%(song[MpMusic.TITLE],song[MpMusic.LENGTH],newtime))  
                song[MpMusic.LENGTH] = newtime
            
        dt = DateTime()
        days_elapsed = dt.daysElapsed(song[MpMusic.DATESTAMP]) # number of days since the date stamp

        
        song[MpMusic.DATESTAMP] = dt.currentDateTime();
        song[MpMusic.DATEVALUE] = DateTime.now();
        
        song.updateFrequency(days_elapsed)

        song[MpMusic.PLAYCOUNT] += 1 
        
        song.calcBaseScore();
        song.calcScore(MpGlobal.Histogram);
        
        song.update();
        # refill the library, if it was in view, its text needs to be updated
        #Player_set_unsaved()
        MpGlobal.Window.emit(SIGNAL("QUEUE_FUNCTION"),Player_set_unsaved)
        MpGlobal.Window.emit(SIGNAL("FILL_LIBRARY"))
Пример #3
0
def testbench_build_library():
    library = []
    time = DateTime.now()
    for i in range(30):
        song=Song("C:/Folder%d/Artist%d/Title%d.mp3"%(i,i,i))
        song[MpMusic.ARTIST]    = u"%dArtist The Band"%(i%10) # id will have 10 different A,B,T
        song[MpMusic.TITLE]     = u"%dTitle of The Song"%(i%10)  
        song[MpMusic.ALBUM]     = u"%dMonthly Album"%(i%10) 
        song[MpMusic.GENRE]     = (u"ROCK",u"POP","ALT")[(i%3)]
        song[MpMusic.DATEVALUE] = time - (60*60*24*i)# each song is one day older
        song[MpMusic.DATESTAMP] = DateTime.formatDateTime(song[MusicContainer.DATEVALUE])
        song[MpMusic.COMMENT]   = ""
        song[MpMusic.RATING]    = i%6   # in 30 songs, 5 of each rating value
        song[MpMusic.LENGTH]    = 15*i
        song[MpMusic.SONGINDEX] = 0
        song[MpMusic.PLAYCOUNT] = i
        song[MpMusic.SKIPCOUNT] = i
        song[MpMusic.FILESIZE]  = 0
        song[MpMusic.FREQUENCY] = 2*i
        song[MpMusic.BITRATE]   = 0
        song[MpMusic.SPECIAL]   = False
        song[MpMusic.SELECTED]  = False
        
        song.update()

        library.append(song)
    return library;
Пример #4
0
def setSearchTime():
    dt = DateTime()
    date = dt.currentDate()

    MpGlobal.RecentEpochTime = dt.getEpochTime(
        date + " 00:00")  # return seconds at start of this day
    MpGlobal.LaunchEpochTime = MpGlobal.RecentEpochTime - (
        14 * 24 * 60 * 60)  # date of two weeks ago
def musicBackup(path, songList, format=0, force=False):
    """
        save a copy of the current library to ./backup/
        only save if one has not been made today,
        delete old backups
        
        adding new music, deleting music, are good reasons to force backup
    """
    #path = os.path.join(MpGlobal.installPath,'backup')
    #songList = MpGlobal.Player.library

    if not os.path.exists(path):
        os.mkdir(path)
        print "backup directory created"

    dt = DateTime()
    # create a new date time object
    date = dt.currentDate()
    hourmin = dt.currentTime()
    date = date.replace('/', '-').replace('\\', '-')

    name = 'music_backup-'
    fullname = name + date + '.libz'
    h, m = hourmin.split(':')

    #if (atoi(h) > 12) or force:  # save backups in the afternoon only

    R = []
    dir = os.listdir(path)
    for file in dir:
        if file.startswith(name) and fileGetExt(file) == "libz":
            R.append(file)

    newestbu = ""

    R.sort(reverse=True)

    if len(R) > 0:

        #remove old backups
        # while there are more than 6,
        # and one has not been saved today
        while len(R) > 6 and R[0] != fullname:
            delfile = R.pop()
            print "Deleting %s" % delfile
            os.remove(os.path.join(path, delfile))

        # record name of most recent backup, one backup per day unless forced
        newestbu = R[0]

    # save a new backup
    if force or newestbu != fullname:
        print "Saving %s" % fullname
        newbu = os.path.join(path, fullname)
        musicSave_LIBZ(newbu, songList, format)
Пример #6
0
 def updateTimeDisplay(self,time):
     if self.CurrentSong != None:
         a = DateTime.formatTimeDelta(time)
         b = DateTime.formatTimeDelta(self.CurrentSong[MpMusic.LENGTH])
         c = DateTime.formatTimeDelta(self.CurrentSong[MpMusic.LENGTH] - time)
         if time > self.CurrentSong[MpMusic.LENGTH] :
             MpGlobal.Window.emit(SIGNAL("UPDATE_TIMEINFO"),"%s/%s"%(a,b)) 
         else:
             MpGlobal.Window.emit(SIGNAL("UPDATE_TIMEINFO"),"%s/%s - %s"%(a,b,c))    
     else:
         MpGlobal.Window.emit(SIGNAL("UPDATE_TIMEINFO"),"") 
def musicBackup(path,songList,format=0,force = False):
    """
        save a copy of the current library to ./backup/
        only save if one has not been made today,
        delete old backups
        
        adding new music, deleting music, are good reasons to force backup
    """
    #path = os.path.join(MpGlobal.installPath,'backup')
    #songList = MpGlobal.Player.library
    
    if not os.path.exists(path):
        os.mkdir(path)
        print "backup directory created"
        
    dt = DateTime(); # create a new date time object
    date = dt.currentDate();
    hourmin = dt.currentTime();
    date = date.replace('/','-').replace('\\','-')
    
    name = 'music_backup-'
    fullname = name+date+'.libz'
    h,m = hourmin.split(':')
        
    #if (atoi(h) > 12) or force:  # save backups in the afternoon only
    
    R = []
    dir = os.listdir(path)
    for file in dir:
        if file.startswith(name) and fileGetExt(file) == "libz":
            R.append(file);
            
    newestbu = ""

    R.sort(reverse=True)
    
    if len(R) > 0:

        #remove old backups
        # while there are more than 6, 
        # and one has not been saved today
        while len(R) > 6 and R[0] != fullname: 
            delfile = R.pop()
            print "Deleting %s"%delfile
            os.remove(os.path.join(path,delfile))
            
        # record name of most recent backup, one backup per day unless forced    
        newestbu = R[0]
        
    # save a new backup 
    if force or newestbu != fullname:
        print "Saving %s"%fullname
        newbu = os.path.join(path,fullname)  
        musicSave_LIBZ(newbu,songList,format);
Пример #8
0
 def format_datefield(self,FMT,string_index,num_index):
     """
         format a date string, using FMT to format
         the integer value comes from num_index
         the formated string value is stored in string_index
     """
     ds = ""
     try:
         dt = DateTime(FMT)
         if self[num_index]:
             ds = dt.formatDateTime(self[num_index])
     except Exception as e:
         print e
     finally:
         self[string_index] = ds
Пример #9
0
def getSelection(unselect = True):
    # return an array of all selected elements, and unselect by default
    # these elements
    if MpGlobal.Player.selCount == 0 :
        return []
    R = [[]]*MpGlobal.Player.selCount
    i = 0;
    time = DateTime.now() - 60*60*24
    for song in MpGlobal.Player.library:
        if song[MpMusic.SELECTED] and not song.banish :
        
            if MpGlobal.PLAYLIST_SKIP_RECENT and song[MpMusic.DATEVALUE] >= time:
                # if skip recent is enabled remove them from the selection.
                    song[MpMusic.SELECTED] = False
                    MpGlobal.Player.selCount -= 1
            else:    
                R[i] = song
                i += 1

                if unselect :
                    song[MpMusic.SELECTED] = False
                    MpGlobal.Player.selCount -= 1
                
    MpGlobal.Window.emit(SIGNAL("UPDATE_STATUSBAR"),0,MpGlobal.Player.selCount)
    
    MpGlobal.PLAYLIST_SKIP_RECENT = False
    
    return R[:i]
Пример #10
0
def info_UpdateDisplay(song):
    obj = MpGlobal.Window.dsp_info
    if song == None:
        obj.text_time = ""
        obj.text_playcount = ""
        obj.text_artist = ""
        obj.text_title = "Select a Song to Play"
        obj.text_album = "Drag and Drop music to Load"
        obj.text_index = "-/-"
        obj.text_date = ""
        obj.int_rating = 0
        obj.int_freq = 0
        obj.stopScrolling()
        obj.update()
    else:
        obj.text_playcount = str(song[MpMusic.PLAYCOUNT])
        obj.text_artist = song[MpMusic.ARTIST]
        obj.text_title = song[MpMusic.TITLE]
        obj.text_album = song[MpMusic.ALBUM]
        obj.int_rating = song[MpMusic.RATING]
        obj.int_freq = song[MpMusic.FREQUENCY]
        obj.text_date = song[MpMusic.DATESTAMP]
        obj.text_index = "%d/%d" % (MpGlobal.Player.CurrentIndex + 1,
                                    len(MpGlobal.Player.playList))
        obj.setScrolling()
        obj.update()

        d = DateTime().daysElapsed(song[MpMusic.DATESTAMP])
        if (d > 0):
            obj.text_date += " {%d}" % (d)
Пример #11
0
def getSelection(unselect=True):
    # return an array of all selected elements, and unselect by default
    # these elements
    if MpGlobal.Player.selCount == 0:
        return []
    R = [[]] * MpGlobal.Player.selCount
    i = 0
    time = DateTime.now() - 60 * 60 * 24
    for song in MpGlobal.Player.library:
        if song[MpMusic.SELECTED] and not song.banish:

            if MpGlobal.PLAYLIST_SKIP_RECENT and song[
                    MpMusic.DATEVALUE] >= time:
                # if skip recent is enabled remove them from the selection.
                song[MpMusic.SELECTED] = False
                MpGlobal.Player.selCount -= 1
            else:
                R[i] = song
                i += 1

                if unselect:
                    song[MpMusic.SELECTED] = False
                    MpGlobal.Player.selCount -= 1

    MpGlobal.Window.emit(SIGNAL("UPDATE_STATUSBAR"), 0,
                         MpGlobal.Player.selCount)

    MpGlobal.PLAYLIST_SKIP_RECENT = False

    return R[:i]
def playList_Load_M3U(filepath, library):
    """
        load an M3U playlist, the file paths in the the meu file will be converted
        to a list of Song objects
        
        filepath - path to the file to load
        library - a list of songs already in memory
    """
    dt = DateTime()
    dt.timer_start()

    if not os.path.exists(filepath):
        return []

    try:
        rf = codecs.open(filepath, "r", encoding='utf-8')
    except:
        print "cannot open m3u file:\n   %s" % filepath
        return []

    bsearch = SongPath_Lookup(library)

    playlist = []

    line = rf.readline()

    count = 0

    while line:

        try:

            line = line.strip()

            if line[0] == '#':
                line = rf.readline()  # load the next line ( a file path?)
                continue

            song = bsearch.find(line)  #path_to_song(line,library)

            if song != None:
                playlist.append(song)

        except Exception as e:
            print "\n\n\nerror\n\n\n"
            print e
        finally:

            line = rf.readline()
            count += 1

    rf.close()

    dt.timer_end()
    print "Loaded %d songs from m3u container in %s" % (
        len(playlist), DateTime.formatTimeDeltams(dt.timedelta))

    return playlist
Пример #13
0
 def setSingleData(self,data):
     #print self.editList[0]
     self.editList[self.art][1].addItem(data[0][MpMusic.ARTIST])
     self.editList[self.cmp][1].addItem(data[0][MpMusic.COMPOSER])
     self.editList[self.ttl][1].addItem(data[0][MpMusic.TITLE])
     self.editList[self.abm][1].addItem(data[0][MpMusic.ALBUM])
     self.editList[self.gen][1].addItem(data[0][MpMusic.GENRE])
     self.editList[self.lng][1].addItem(data[0][MpMusic.LANG])
     self.editList[self.com][1].addItem(data[0][MpMusic.COMMENT])
     self.editList[self.rte][1].setValue(data[0][MpMusic.RATING])
     self.editList[self.pct][1].setValue(data[0][MpMusic.PLAYCOUNT])
     self.editList[self.sct][1].setValue(data[0][MpMusic.SKIPCOUNT])
     self.editList[self.frq][1].setValue(data[0][MpMusic.FREQUENCY])
     self.editList[self.ind][1].setValue(data[0][MpMusic.SONGINDEX])
     self.editList[self.yer][1].setValue(data[0][MpMusic.YEAR])
     
     self.editList[self.pth][1].setText(data[0][MpMusic.PATH])
     self.editList[self.pth][1].setCursorPosition(0)
     
     self.editList[self.dte][1].setDateTime( DateTime.fmtToQDateTime(data[0][MpMusic.DATESTAMP] ) )
     self.editList[self.add][1].setDateTime( DateTime.fmtToQDateTime(data[0][MpMusic.DATEADDEDS]) )
Пример #14
0
def id3_createSongFromPath(path):
    """ attempt to read the id3 data from the song
        if the songs format is not supported, return a blank song
        with the path set.
    """

    #check the extension and build a new song array from that type

    fext = fileGetExt(path).lower()

    song = Song(path)

    try:
        if fext in ext_mp3:
            id3_mp3_createSongFromPath(song)
        if fext in ext_mp4:
            id3_mp4_createSongFromPath(song)
        if fext in ext_asf:
            id3_asf_createSongFromPath(song)
        if fext in ext_flac:
            id3_flac_createSongFromPath(song)
    except Exception as e:
        print traceback.format_exc()
        print " *** Error [%s] Reading Tags for Type: %s" % (song, fext)
        for i in e:
            print "%s" % str(i)

    song[EnumSong.FILESIZE] = fileGetSize(path)
    song[EnumSong.DATEADDED] = DateTime.now()
    song[EnumSong.DATEADDEDS] = DateTime().currentDateTime()

    if song[EnumSong.
            LENGTH] > 2000:  # 2k seconds = 32 minutes. is that a good break point?
        song[
            EnumSong.
            LENGTH] /= 1000  # assume that th time measured was in milliseconds

    song.update()

    return song  # return the blank song instead
Пример #15
0
    def calcBaseScore(self):
        """
        s=1000
        t=255
        MpGlobal.Hist = [0]*(s+1)
        MpGlobal.Histpcnt = [0]*(t+1)

        for song in MpGlobal.Player.library:
            delta = DateTime().daysElapsedUTC(song[EnumSong.DATEADDED],DateTime.now())
            song[EnumSong.SPECIAL]  = int((s)*(float(song[EnumSong.PLAYCOUNT])/delta))

            MpGlobal.Hist    [ min(s,song[ EnumSong.SPECIAL   ] )] += 1
            MpGlobal.Histpcnt[ min(t,song[ EnumSong.PLAYCOUNT ] )] += 1

        l = len(MpGlobal.Player.library)

        for song in MpGlobal.Player.library:
            m = min(s,song[ EnumSong.SPECIAL   ] );
            n = min(t,song[ EnumSong.PLAYCOUNT ] );

            _m = float(sum(MpGlobal.Hist    [:m]));
            _n = float(sum(MpGlobal.Histpcnt[:n]));
         
            _d = int( 1000*(_m/l) )
            _p = int( 1000*(_n/l) )
            
            song[ EnumSong.SCORE ] = int(.25*_p+.75*_d)

        """
        MAX_SCORE = 9999
        delta = DateTime().daysElapsedUTC(self[EnumSong.DATEADDED],DateTime.now())
        p = int(MAX_SCORE*(float(self[EnumSong.PLAYCOUNT])/delta))
        _f = float(9999 if self[EnumSong.FREQUENCY] == 0 else self[EnumSong.FREQUENCY])
        f = int( MAX_SCORE*(1/_f)*7 ) # 7 scales such that once a week is really good
        
        self.basescore = (min(MAX_SCORE,f) + min(MAX_SCORE,p)) / 2
        self[EnumSong.SPECIAL]   = self.basescore
        
        return self.basescore
Пример #16
0
    def setSingleData(self, data):
        #print self.editList[0]
        self.editList[self.art][1].addItem(data[0][MpMusic.ARTIST])
        self.editList[self.cmp][1].addItem(data[0][MpMusic.COMPOSER])
        self.editList[self.ttl][1].addItem(data[0][MpMusic.TITLE])
        self.editList[self.abm][1].addItem(data[0][MpMusic.ALBUM])
        self.editList[self.gen][1].addItem(data[0][MpMusic.GENRE])
        self.editList[self.lng][1].addItem(data[0][MpMusic.LANG])
        self.editList[self.com][1].addItem(data[0][MpMusic.COMMENT])
        self.editList[self.rte][1].setValue(data[0][MpMusic.RATING])
        self.editList[self.pct][1].setValue(data[0][MpMusic.PLAYCOUNT])
        self.editList[self.sct][1].setValue(data[0][MpMusic.SKIPCOUNT])
        self.editList[self.frq][1].setValue(data[0][MpMusic.FREQUENCY])
        self.editList[self.ind][1].setValue(data[0][MpMusic.SONGINDEX])
        self.editList[self.yer][1].setValue(data[0][MpMusic.YEAR])

        self.editList[self.pth][1].setText(data[0][MpMusic.PATH])
        self.editList[self.pth][1].setCursorPosition(0)

        self.editList[self.dte][1].setDateTime(
            DateTime.fmtToQDateTime(data[0][MpMusic.DATESTAMP]))
        self.editList[self.add][1].setDateTime(
            DateTime.fmtToQDateTime(data[0][MpMusic.DATEADDEDS]))
Пример #17
0
def getStatistics():
    c_ply=0 # total play count
    c_len=0 # total play time
    c_frq=0
    count = len(MpGlobal.Player.library);
    
    for song in MpGlobal.Player.library:    
        c_ply += song[MpMusic.PLAYCOUNT]
        c_len += song[MpMusic.LENGTH]*song[MpMusic.PLAYCOUNT]
        c_frq += song[MpMusic.FREQUENCY]
    c_frq /= count; 
    debug( "Song Count        : %d"%count)
    debug( "Play Time         : %s"%DateTime.formatTimeDelta(c_len))   
    debug( "Play Count        : %d"%c_ply)
    debug( "Play Count (AVG)  : %s"%(c_ply/count))
    debug( "Frequency         : %d"%(c_frq))
Пример #18
0
def getStatistics():
    c_ply = 0  # total play count
    c_len = 0  # total play time
    c_frq = 0
    count = len(MpGlobal.Player.library)

    for song in MpGlobal.Player.library:
        c_ply += song[MpMusic.PLAYCOUNT]
        c_len += song[MpMusic.LENGTH] * song[MpMusic.PLAYCOUNT]
        c_frq += song[MpMusic.FREQUENCY]
    c_frq /= count
    debug("Song Count        : %d" % count)
    debug("Play Time         : %s" % DateTime.formatTimeDelta(c_len))
    debug("Play Count        : %d" % c_ply)
    debug("Play Count (AVG)  : %s" % (c_ply / count))
    debug("Frequency         : %d" % (c_frq))
Пример #19
0
 def playlist_PlayTime(self):
     """
         return a formatted string containing the play time
         for the current play list
         
         
         
         so far, only operations are 
             \.playlist\.append
             \.playlist\.pop
             \.playlist\s=
         this function must be called when ever the playList is changed
         
         UpdateStatusWidget(1,MpGlobal.Player.playL    istPlayTime())
         
     """
     s = 0
     for song in self.playList:
         s += song[MpMusic.LENGTH]
         
     return DateTime.formatTimeDelta(s)
def id3_createSongFromPath(path):
    """ attempt to read the id3 data from the song
        if the songs format is not supported, return a blank song
        with the path set.
    """
    
    #check the extension and build a new song array from that type
    
    fext = fileGetExt(path).lower()
  
    song = Song(path)

    try :
        if fext in ext_mp3:
            id3_mp3_createSongFromPath(song)
        if fext in ext_mp4:
            id3_mp4_createSongFromPath(song)
        if fext in ext_asf:
            id3_asf_createSongFromPath(song)
        if fext in ext_flac:
            id3_flac_createSongFromPath(song)
    except Exception as e:
        print traceback.format_exc()
        print " *** Error [%s] Reading Tags for Type: %s"%(song, fext)
        for i in e:
            print "%s"%str(i)
                    
        
    song[EnumSong.FILESIZE] = fileGetSize(path)
    song[EnumSong.DATEADDED ] = DateTime.now()
    song[EnumSong.DATEADDEDS] = DateTime().currentDateTime() 

    
    if song[EnumSong.LENGTH] > 2000: # 2k seconds = 32 minutes. is that a good break point?
        song[EnumSong.LENGTH] /= 1000 # assume that th time measured was in milliseconds
        
    song.update();
    
    return song # return the blank song instead
def playList_Save_M3U(filepath, data, typ=0):

    driveList = systemDriveList()

    wf = codecs.open(filepath, "w", encoding='utf-8')

    dt = DateTime()
    dt.timer_start()

    for x in range(len(data)):

        path = data[x][EnumSong.PATH]

        if typ > 0:  #alternate save formats remove the drive
            path = stripDriveFromPath(driveList, path)

        wf.write("%s\n" % (unicode(path)))

    wf.close()

    dt.timer_end()
    print "Saved %d songs to m3u container in %s" % (
        len(data), DateTime.formatTimeDeltams(dt.timedelta))
Пример #22
0
    def getData(self):
        MULTIDATA = len(self.data) > 1
        OPERATION = self.cbox.currentIndex()

        for item in self.editList:
            if not item[2].isEnabled():
                item[2].setCheckState(Qt.Unchecked)
        for song in self.data:
            if self.editList[self.art][2].isChecked():
                song[MpMusic.ARTIST] = unicode(
                    self.editList[self.art][1].currentText())

            if self.editList[self.cmp][2].isChecked():
                print unicode(self.editList[self.cmp][1].currentText())
                print self.cmp, self.lng
                song[MpMusic.COMPOSER] = unicode(
                    self.editList[self.cmp][1].currentText())

            if self.editList[self.ttl][2].isChecked():
                song[MpMusic.TITLE] = unicode(
                    self.editList[self.ttl][1].currentText())

            if self.editList[self.abm][2].isChecked():
                song[MpMusic.ALBUM] = unicode(
                    self.editList[self.abm][1].currentText())

            if self.editList[self.gen][2].isChecked():
                song[MpMusic.GENRE] = unicode(
                    self.editList[self.gen][1].currentText())

            if self.editList[self.lng][2].isChecked():
                song[MpMusic.LANG] = unicode(
                    self.editList[self.lng][1].currentText())

            if self.editList[self.com][2].isChecked():
                song[MpMusic.COMMENT] = unicode(
                    self.editList[self.com][1].currentText())

            if self.editList[self.rte][2].isChecked():
                if MULTIDATA:
                    song[MpMusic.RATING] += self.editList[self.rte][1].value()
                else:
                    song[MpMusic.RATING] = self.editList[self.rte][1].value()

                if song[MpMusic.RATING] > MpMusic.MAX_RATING:
                    song[MpMusic.RATING] = MpMusic.MAX_RATING
                if song[MpMusic.RATING] < 0:
                    song[MpMusic.RATING] = 0

            if self.editList[self.pct][2].isChecked():
                if MULTIDATA:
                    song[MpMusic.PLAYCOUNT] += self.editList[
                        self.pct][1].value()
                else:
                    song[MpMusic.PLAYCOUNT] = self.editList[
                        self.pct][1].value()

                if song[MpMusic.PLAYCOUNT] < 0:
                    song[MpMusic.PLAYCOUNT] = 0

            if self.editList[self.sct][2].isChecked():
                if MULTIDATA:
                    song[MpMusic.SKIPCOUNT] += self.editList[
                        self.sct][1].value()
                else:
                    song[MpMusic.SKIPCOUNT] = self.editList[
                        self.sct][1].value()

                if song[MpMusic.SKIPCOUNT] < 0:
                    song[MpMusic.SKIPCOUNT] = 0

            if self.editList[self.frq][2].isChecked():
                if MULTIDATA:
                    song[MpMusic.FREQUENCY] += self.editList[
                        self.frq][1].value()
                else:
                    song[MpMusic.FREQUENCY] = self.editList[
                        self.frq][1].value()

                if song[MpMusic.FREQUENCY] < 0:
                    song[MpMusic.FREQUENCY] = 0

            if self.editList[self.ind][2].isChecked():
                song[MpMusic.SONGINDEX] = self.editList[self.ind][1].value()

            if self.editList[self.yer][2].isChecked():
                song[MpMusic.YEAR] = self.editList[self.yer][1].value()

            if self.editList[self.pth][2].isChecked():
                # auto strip any quotes around the path name
                s = unicode(self.editList[self.pth][1].text())
                if s[0] in "'\"" and s[0] == s[-1]:
                    s = s[1:-1]
                song[MpMusic.PATH] = s

            if self.editList[self.dte][2].isChecked():
                dt = DateTime.QDateTimeToFmt(
                    self.editList[self.dte][1].dateTime())

                song[MpMusic.DATESTAMP] = dt
                song[MpMusic.DATEVALUE] = DateTime().getEpochTime(dt)

            if self.editList[self.add][2].isChecked():
                dt = DateTime.QDateTimeToFmt(
                    self.editList[self.add][1].dateTime())
                song[MpMusic.DATEADDED] = DateTime().getEpochTime(dt)
                song[MpMusic.DATEADDEDS] = dt

            if OPERATION == 4:
                t = DateTime().getEpochTime(song[MpMusic.DATESTAMP])
                SECONDS_IN_DAY = 86400  #60*60*24
                t -= song[MpMusic.FREQUENCY] * SECONDS_IN_DAY
                song[MpMusic.DATESTAMP] = DateTime().formatDateTime(t)
                song[MpMusic.DATEVALUE] = t
                song[MpMusic.PLAYCOUNT] -= 1
                #song[MpMusic.FREQUENCY] = 0

            song.update()
Пример #23
0
    def compile(self,string):
        """
            Dot Words
            
            
            \\<table\\>
            \\<b\\>Dot Word\\</b\\> | \\<b\\>Field\\</b\\> | \\<b\\>Description\\</b\\>
            
            \\<b\\>Text Info\\</b\\>
            .alb .abm .album | Album | Search by album info.
            .art .artist     | Artist | Search by artist info.
            .comm .comment   | Comment | Search by user set comments.
            .gen .genre      | Genre | Search by the songs genre.
            .path            | Path  | Search by the file path.
            .ttl .tit .title | Title | Search by song title.
            
            \\<b\\>Numerical\\</b\\>
            .freq            | Frequency | Search by the average number of days between song plays.
            .pcnt .playcount | Play Count | Search by the playcount 
            .scnt .skipcount | Skip Count | Search by the skipcount 
            .size            | File Size | Search by file size, in KB.
            .rte .rating     | Rating | Search by the song rating, 0-5.
            \\</table\\>
            \\<table\\>
            \\<b\\>Advanced\\</b\\> | \\<b\\>Format\\</b\\> | \\<b\\>Description\\</b\\>
            .day        | number     | By number of days since last playing.
            .week       | number     | By number of weeks since last playing.
            .month      | number     | By number of months since last playing.
            .date       | YYYY/MM/DD | enter a specific date to search by. formatted by year-month-day
            .dateUS     | MM/DD/YYYY | see date. American date format
            .dateEU     | DD/MM/YYYY | see date. Sane people format.
            
            \\<b\\>Special\\</b\\>
            .sel | Selected | Display songs from the selection pool
            .preset # |  | This text is replaced with the text found in the given preset.
            .favorite | | Expands to a OR list of favorite artists. Set your favorite artists by right clicking their name in the Quick Selection tab
            \\</table\\>
            
        """
        # # 
        # #     given a unicode string formatted as a search string, parse, set the 3 tupples for this object
        # #     Parameters:
        # #         str: a user input str
        # # there are three types of searchs to perform
        # # "c" or contains    : target must contain any of these elements 
        # # "o" or boolean or  : target must contain at least one of these elements
        # # "n" or boolean not : target must contain none of these elements
        # # 
        # # format:
        # #   The following will be considered one search 'field':
        # # [.param] [.+!] [dir] term [ [.+!] [dir] term2 ...] [,;] ...
        # # where :
        # #   .param : search type, eg .date, defaults to .exif when not included
        # #   .+!    : AND,OR,NOT include the following term in search results
        # #   dir    : <=,<,=,>,=> can be used to specify comparison direction
        # #   term * : only mandatory string term, this will be compared against each song              
        # #   ,;     : these optionally end a field 
        # #            if multiply fields are wanted, they must be separated by a comma or semicolon
        # # 
        self._original = unicode(string) # create a copy of the string

        self._searchC = []
        self._searchO = []
        self._searchN = []
        self._searchX = [[]]
        
        self.termCount = 0;
                
        fflag = {
                '<' : SEARCH.LT,
                '=' : SEARCH.EQ,
                '>' : SEARCH.GT,
            }
                    
        ftype = {
                '.' : 0,
                '+' : SEARCH.OR,
                '!' : SEARCH.NT,
                '*' : SEARCH.IO,
            } 
        
        #expand preset modifiers into their expressions
        for i in range(10):
            string = self._expand_preset(string,i)
        # expand favorite modifier
        if string[1:].find("favorite") >= 0:
            result = ".art +"
            if string[0] == "*":
                result = ".art *"
            for art in SearchObject_Controller.getFavoriteArtistList():
                if len(art) > 0:
                    result += u" \"%s\""%(art)
            result += ';'
            string = string[1:].replace("favorite",result,1);
        
        # ########################################################
        # Begin Parsing User Input
         # quote first to protect anything the user wants protected.
        string = self.q.quote(string.lower())

        # split the user input string into frames
        R = stringSplit(string,",;")

        # for each field in the string break into terms
        for x in range(len(R)):
            field = R[x]            # the field is the entire string seperated by ;
            temp = field.split()
            if (len(temp) > 0):
                dword = temp[0]    # the dot word will be the first word prepended with a sigil
            else:
                continue;
            frame = field.replace(dword,"",1).strip()   # frame is everything but the dword
            key=""
            sigil = dword[0];
            sigil_type = ftype.get(sigil,0) # integer translation of the sigil
            
            if not dword[0].isalpha():
                key   = dword[1:]       #the dword with the sigil removed
           
            flag_type = EnumSong.EXIF
            
      
            if key == "sel":
                term = SearchTerm(dword,EnumSong.SELECTED,0,None,None,self._compareSongElement) 
                self.addTerm(sigil_type,term)
                continue
            elif key == "spec":
                term = SearchTerm(dword,EnumSong.SPECIAL,0,None,None,self._compareSongElement)
                self.addTerm(sigil_type,term)
                continue
            elif key == "ban" or key == 'banish':
                term = SearchTerm(dword,EnumSong.BANISH,0,None,None,self._compareSongElement)
                self.addTerm(sigil_type,term)
                continue
            elif key[:4] == "freq" and key[4:5] in "<=>" and key[4:5] != "": # a slice never throws an exception, but can return empty
                # allow $freqX , where X is <=>,
                fdict = {
                    '<' : EnumSong.SPEC_FREQ_L,
                    '=' : EnumSong.SPEC_FREQ_E,
                    '>' : EnumSong.SPEC_FREQ_G,
                }
                flag = fflag.get(key[4],0)|sigil_type          
                term = SearchTerm(key,fdict[key[4]],flag,DateTime.now(),None,self._compareSongElement)
                self.addTerm(sigil_type,term)
                continue
            else: # get key or return the default value
                flag_type = SearchObject_Controller.getSearchDictionary().get(key,flag_type)
                
            #print flag_type,frame
            if flag_type == EnumSong.EXIF:
                self._parseFrame(flag_type,field)
            else:
                self._parseFrame(flag_type,frame)
            #self._addTerms(flag_type,frame,S)

        self.termCount = len(self._searchC)+len(self._searchO)+len(self._searchN)
        for lst in self._searchX:
            self.termCount += len(lst)
def musicSave_LIBZ(filepath, songList, typ=1, block_size=128):
    """
        save a new file, but first compress it using LZMA.
        
        file is saved as a binary file.
       
        HEADER:
            several 8 byte frames in a 4:4 byte pattern
            4 bytes describing the value in format 'LXXX'
            4 byte integer
         
            the header ends when the first string 'SIZE' is found
            
        Frame
            8 byte header, followed by SIZE bytes corresponding to X LZMA compressed song representations.
            Frame Header:
                4 bytes - the word 'SIZE'
                4 bytes - unsigned integer, size of frame, excluding frame header
            Frame Body:
                SIZE bytes compressed using pyLZMA.compress()
            
            
        each frame will compress
        
        HEADERS:
        LVER - VERSION    :outlines if any changes to reading will be needed (future proofing)
        LTYP - TYPE       : bitwise or combination of save settings
                          :  1 - no compression
                          :  2 - remove drie list from start of path ( multi os mode )
        LBLK - BLOCK SIZE : maximum number of songs per block, after decompression 
        LCNT - COUNT      : count of all songs saved to the file        
        LFMT - SNG FORMAT : number of lines per song record     
        
        Based off of the following two docstrings. there is no reason to store the parameters used for saving.
        
        compress(string, 
             dictionary=23, 
             fastBytes=128, 
             literalContextBits=3, 
             literalPosBits=0, 
             posBits=2, 
             algorithm=2, 
             eos=1, 
             multithreading=1, 
             matchfinder='bt4') 

            Compress the data in string using the given parameters, returning a string containing 
            the compressed data.


        decompress(data[, maxlength]) 
            Decompress the data, returning a string containing the decompressed data. 
            If the string has been compressed without an EOS marker,
            you must provide the maximum length as keyword parameter.


        decompress(data, bufsize[, maxlength])
            Decompress the data using an initial output buffer of size bufsize.
            If the string has been compressed without an EOS marker, 
            you must provide the maximum length as keyword parameter.
    """

    dt = DateTime()
    dt.timer_start()

    with open(filepath, "wb") as FILE:
        FILE.write(struct.pack("4sI", "LVER", 1))
        #
        FILE.write(struct.pack("4sI", "LTYP", typ | 1))
        #
        FILE.write(struct.pack("4sI", "LBLK", block_size))
        # number of songs in each block
        FILE.write(struct.pack("4sI", "LCNT", len(songList)))
        #
        FILE.write(struct.pack("4sI", "LFMT", Song.repr_length()))
        LIBZ_write_songList(FILE, songList, typ, block_size)

    dt.timer_end()
    print "Saved %d songs to libz container in %s" % (
        len(songList), DateTime.formatTimeDeltams(dt.timedelta))
Пример #25
0
    def _compileTerm(self,flag_type,flag,ostr):
        """
            flag_type: either EXIF, ARTIST,PLAYCOUNT ETC
            flag     : OR combination of SEARCH dir and mod. < <= >= > = and . + ! *
            ostr     : relevant string term for a search of flag_type
        """
        if ostr == "":
            return None
        ostr = unicode(ostr) 
        cf = ostr[:]
        rf = None;
        fptr = None;
        
        if flag_type < EnumSong.STRINGTERM:
            fptr = self._compareTerm_String
        
        if   (flag_type == EnumSong.SPEC_DATESTD ) :
            dt = DateTime(flag_type&0xF)
            cf = dt.getEpochTime(dt.repairDateTime(cf))
            rf = cf + 24*60*60
            if cf == 0:
                return None
            dt = DateTime(flag_type&0xF)
            ostr = dt.repairDateTime(ostr)
            
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT
                
            flag_type = EnumSong.DATESTAMP # change type to standard date format
            fptr = self._compareSongElement
        elif (flag_type == EnumSong.SPEC_DATEEU ) :
            dt = DateTime(flag_type&0xF) # set which format to use for dates, for help check the definition for SPEC_DATESTD, and the enumeration in DateTime
            cf = dt.getEpochTime(dt.repairDateTime(cf)) # autocomplete the entered date then convert to seconds
            rf = cf + 24*60*60
            if cf == 0:
                return None
            dt = DateTime(flag_type&0xF)
            ostr = dt.repairDateTime(ostr)
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT
            flag_type = EnumSong.DATESTAMP # change type to standard date format   
            fptr = self._compareSongElement
        elif (flag_type == EnumSong.SPEC_DATEUS ) :
            dt = DateTime(flag_type&0xF)
            cf = dt.getEpochTime(dt.repairDateTime(cf))
            rf = cf + 24*60*60
            if cf == 0:
                return None
            dt = DateTime(flag_type&0xF)
            ostr = dt.repairDateTime(ostr)
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT
            flag_type = EnumSong.DATESTAMP # change type to standard date format
            fptr = self._compareSongElement
        elif (flag_type == EnumSong.SPEC_MONTH ) :
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT
            flag_type = EnumSong.DATESTAMP
            cf = DateTime.now()
            try :
                cf -= 30*int(ostr)*24*60*60
                rf = cf + 28*24*60*60
                ostr = "month: %s"%ostr
            except:
                pass 
            fptr = self._compareSongElement            
        elif (flag_type == EnumSong.SPEC_WEEK ) :
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT
            flag_type = EnumSong.DATESTAMP
            cf = DateTime.now()
            try :
                cf -= 7*int(ostr)*24*60*60
                rf = cf + 7*24*60*60
                ostr = "week: %s"%ostr
            except:
                pass 
            fptr = self._compareSongElement
        elif (flag_type == EnumSong.DATESTAMP) :
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT
            cf = DateTime.now()
            try :
                cf -= int(ostr)*24*60*60
                rf = cf + 24*60*60
                ostr = "day: %s"%ostr
            except:
                pass
            fptr = self._compareSongElement
        elif (flag_type == EnumSong.DATEADDED) :
            dt = DateTime(EnumSong.SPEC_DATESTD&0xF)
            cf = dt.getEpochTime(dt.repairDateTime(cf))
            rf = cf + 24*60*60
            if cf == 0:
                return None
            dt = DateTime(EnumSong.SPEC_DATESTD&0xF)
            ostr = dt.repairDateTime(ostr)
            
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.GT   
            fptr = self._compareSongElement            
        elif (flag_type == EnumSong.PATH ) :
            if cf == u"":
                return None
            rf = None
            fptr = self._compareSongElement
        elif flag_type >= EnumSong.STRINGTERM and flag_type < EnumSong.NUMTERM :
            if flag&SEARCH.DIR == 0:# if no DIR flags set, set EQ flag
                flag = flag|SEARCH.EQ
            try:
                cf = int(cf)
            except:
                cf = 0
                return None
            rf = None
            # set the function to do the compare
            if flag_type == EnumSong.FREQUENCY:
                fptr = self._compareTerm_Frequency
            else:
                fptr = self._compareTerm_Number
                
            if flag_type == EnumSong.LENGTH:
                cf = DateTime.parseTimeDelta(ostr)  
        
        term = SearchTerm(ostr,flag_type,flag,cf,rf,fptr)

        self.addTerm(flag&SEARCH.MOD,term)
def musicLoad_LIBZ(filepath):
    """
        load the specified .libz file and return an array of songs.
        
        #todo : read 8 bytes
        # read in : LVERABCD
        # if A== 0x3D == '=' then file is ascii format
        
        # when saving a non binary version save version as '=001' or 3D 30 30 31
        # increment the version count for new ascii file formats
        # for binary formats:
        #   LVERABCD, where A,B,C,D are a little endian 32 bit integer with A=0x00
    """

    srclib = fileGetName(filepath)
    if not os.path.exists(filepath):
        return []

    R = []
    drivelist = []
    cnt = 0

    dt = DateTime()
    dt.timer_start()
    with open(filepath, "rb") as FILE:
        # ##################################
        # read the header
        header = {}
        bin = FILE.read(8)
        key, val = struct.unpack("4sI", bin)
        while key != "SIZE" and bin:
            header[key] = val
            bin = FILE.read(8)
            if bin:
                key, val = struct.unpack("4sI", bin)

        # ##################################
        # process the header dictionary
        typ = header.get("LTYP", 0)  # needed for restoring file paths
        blk = header.get("LBLK", 128)  # not really needed
        fmt = header.get(
            "LFMT", Song.repr_length())  # needed to restore each song record.
        cnt = header.get("LCNT", 0)

        if typ & 2 == 2:
            drivelist = systemDriveList()

        # ##################################
        # now  read the data from the file.
        bin = FILE.read(val)
        while bin:

            if typ & 1 == 0 and pylzma != None:  #compression is only used when typ&1 == 0.
                bin = pylzma.decompress(bin)

            R += LIBZ_process_block(bin, typ, fmt, drivelist, srclib)

            bin = FILE.read(8)
            if bin:
                key, size = struct.unpack("4sI", bin)
                bin = FILE.read(size)
                # read val bytes from the frame

    dt.timer_end()
    print "Loaded %d/%d songs from libz container in %s" % (
        len(R), cnt, DateTime.formatTimeDeltams(dt.timedelta))
    return R
Пример #27
0
 def initColumns(self):
     self.columns.append( TableColumn(self,EnumSong.PLAYCOUNT,"Play Count") )
     self.columns[-1].setShortName("#")
     self.columns[-1].setWidthByCharCount(3)
     self.columns[-1].setMinWidthByCharCount(2)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns.append( EditColumn(self,EnumSong.ARTIST   ,"Artist") )
     self.columns[-1].setWidthByCharCount(30)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( EditColumn(self,EnumSong.TITLE    ,"Title") )
     self.columns[-1].setWidthByCharCount(30)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( EditColumn(self,EnumSong.ALBUM    ,"Album") )
     self.columns[-1].setWidthByCharCount(20)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( TableColumn(self,EnumSong.LENGTH   ,"Length") )
     self.columns[-1].setWidthByCharCount(7)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns[-1].text_transform = lambda row_data,cell_item: DateTime.formatTimeDelta(cell_item);
     self.columns.append( TableColumn_Rating(self,EnumSong.RATING   ,"Rating") )
     self.columns[-1].setWidthByCharCount(10)
     self.columns[-1].setMinWidthByCharCount(7)
     self.columns[-1].setTextAlign(Qt.AlignCenter)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns.append( EditColumn(self,EnumSong.GENRE    ,"Genre") )
     self.columns[-1].setWidthByCharCount(15)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( TableColumn(self,EnumSong.FREQUENCY,"Frequency") )
     self.columns[-1].setShortName("Freq")
     self.columns[-1].setWidthByCharCount(4)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns.append( TableColumn_DateStamp(self,EnumSong.DATESTAMP,"Last Played") )
     self.columns[-1].setWidthByCharCount(16)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns.append( TableColumn(self,EnumSong.FILESIZE ,"File Size") )
     self.columns[-1].setWidthByCharCount(9)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns.append( TableColumn(self,EnumSong.SKIPCOUNT,"Skip Count") )
     self.columns[-1].setWidthByCharCount(10)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns[-1].setTextAlign(Qt.AlignCenter)
     self.columns.append( EditColumn(self,EnumSong.COMMENT  ,"Comment") )
     self.columns[-1].setWidthByCharCount(20)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( TableColumn(self,EnumSong.DATEADDED,"Date Added") )
     self.columns[-1].text_transform = lambda song,index: song[EnumSong.DATEADDEDS]
     self.columns[-1].setWidthByCharCount(16)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns.append( EditColumn(self,EnumSong.YEAR     ,"Year",int) )
     self.columns[-1].setWidthByCharCount(4)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( EditColumn(self,EnumSong.SONGINDEX,"Album Index",int) )
     self.columns[-1].setWidthByCharCount(11)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( TableColumn(self,EnumSong.SONGID   ,"ID#") )
     self.columns[-1].text_transform = lambda song,index: unicode(song.id)
     self.columns[-1].setWidthByCharCount(22)
     self.columns.append( EditColumn(self,EnumSong.PATH     ,"Path") )
     self.columns[-1].setWidthByCharCount(30)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( TableColumn(self,EnumSong.EQUILIZER,"Volume Eq") )
     self.columns[-1].setShortName("Eq")
     self.columns[-1].setWidthByCharCount(10)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns.append( TableColumn(self,EnumSong.SPECIAL,"Special") )
     self.columns[-1].setWidthByCharCount(7)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns.append( TableColumn_Score(self,EnumSong.SCORE,"Score") )
     self.columns[-1].setWidthByCharCount(7)
     self.columns[-1].setTextAlign(Qt.AlignRight)
     self.columns[-1].setDefaultSortReversed(True)
     self.columns.append( EditColumn(self,EnumSong.LANG    ,"Language") )
     self.columns[-1].setShortName("LANG")
     self.columns[-1].setWidthByCharCount(15)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( EditColumn(self,EnumSong.COMPOSER    ,"Composer") )
     self.columns[-1].setWidthByCharCount(15)
     self.columns[-1].cell_modified.connect(self.text_cell_modified)
     self.columns.append( TableColumn(self,EnumSong.SOURCELIB,"Source Library") )
     self.columns[-1].setShortName("Src")
     self.columns[-1].setWidthByCharCount(15)
     
     
     self.columns_setDefaultOrder( self.columns_getOrder() )
Пример #28
0
 def format(self,row_data,cell_item):
    if self.datefmt_out != "" and cell_item != "":
        return DateTime.reformatDateTime(self.datefmt_in,self.datefmt_out,cell_item)
    else:
         return cell_item
def musicSave_LIBZ(filepath,songList,typ=1,block_size=128):
    """
        save a new file, but first compress it using LZMA.
        
        file is saved as a binary file.
       
        HEADER:
            several 8 byte frames in a 4:4 byte pattern
            4 bytes describing the value in format 'LXXX'
            4 byte integer
         
            the header ends when the first string 'SIZE' is found
            
        Frame
            8 byte header, followed by SIZE bytes corresponding to X LZMA compressed song representations.
            Frame Header:
                4 bytes - the word 'SIZE'
                4 bytes - unsigned integer, size of frame, excluding frame header
            Frame Body:
                SIZE bytes compressed using pyLZMA.compress()
            
            
        each frame will compress
        
        HEADERS:
        LVER - VERSION    :outlines if any changes to reading will be needed (future proofing)
        LTYP - TYPE       : bitwise or combination of save settings
                          :  1 - no compression
                          :  2 - remove drie list from start of path ( multi os mode )
        LBLK - BLOCK SIZE : maximum number of songs per block, after decompression 
        LCNT - COUNT      : count of all songs saved to the file        
        LFMT - SNG FORMAT : number of lines per song record     
        
        Based off of the following two docstrings. there is no reason to store the parameters used for saving.
        
        compress(string, 
             dictionary=23, 
             fastBytes=128, 
             literalContextBits=3, 
             literalPosBits=0, 
             posBits=2, 
             algorithm=2, 
             eos=1, 
             multithreading=1, 
             matchfinder='bt4') 

            Compress the data in string using the given parameters, returning a string containing 
            the compressed data.


        decompress(data[, maxlength]) 
            Decompress the data, returning a string containing the decompressed data. 
            If the string has been compressed without an EOS marker,
            you must provide the maximum length as keyword parameter.


        decompress(data, bufsize[, maxlength])
            Decompress the data using an initial output buffer of size bufsize.
            If the string has been compressed without an EOS marker, 
            you must provide the maximum length as keyword parameter.
    """
    
    dt = DateTime();
    dt.timer_start()
    
    with open(filepath,"wb") as FILE:
        FILE.write( struct.pack("4sI","LVER",1) );             # 
        FILE.write( struct.pack("4sI","LTYP",typ|1) );           # 
        FILE.write( struct.pack("4sI","LBLK",block_size) );    # number of songs in each block
        FILE.write( struct.pack("4sI","LCNT",len(songList)) ); # 
        FILE.write( struct.pack("4sI","LFMT",Song.repr_length() ) );
        LIBZ_write_songList(FILE,songList,typ,block_size)
        
    dt.timer_end();
    print "Saved %d songs to libz container in %s"%( len(songList), DateTime.formatTimeDeltams(dt.timedelta))
Пример #30
0
    def _cpy_files(self):
        
        dt = DateTime();
        r = len(self.listc) - 1
        if r < 0:
            return True
        self.parent.emit(SIGNAL("SYNC_SET_RANGE"),self.parent,0,r)
        self.parent.emit(SIGNAL("SYNC_SET_VALUE"),self.parent,0)
        
        # ###########################################################
        # Copy Songs
        self.index = 0
        rTime = 0
        byteAvg = 0
        time_remaining=0
        stime = None
        dt.timer_start();
        while self.alive and self.index < len(self.listc):

            free = driveGetFreeSpace(self.dir)
            MBfree = free[2]
            if MBfree < 75:
                self.alive = False
                print " *** Out Of Free Space. Error."
                break;
            
            createDirStructure(self.listc[self.index][1])
            
            # ----------------------------------------------
            s = "Copying %d/%d - %s - %d MB free"
            p = (self.index,len(self.listc),DateTime.formatTimeDeltams(time_remaining),MBfree)
            self.parent.emit(SIGNAL("SYNC_SET_TEXT"),self.parent,s%p)
                        
            # ----------------------------------------------
            bytes=0
            try:
                src = self.listc[self.index][0]
                dst = self.listc[self.index][1]
                self.parent.debug("src:%s"%src);
                self.parent.debug("dst:%s"%dst);
                if os.path.exists(src) == False:    
                    self.parent.debug("Cannot Find Source File");
                elif os.path.exists(dst) == False:
                    #e32.file_copy(self.listc[self.index][0],self.listc[self.index][1])
                    bytes = os.path.getsize(self.listc[self.index][0])
                    
                    #MpTest.fcopy(src,dst)
                    PYCOPY (src, dst)
                    #copy(self.listc[self.index][0],self.listc[self.index][1])
            except:
                self.parent.debug( "*** ERROR: %s"%self.listc[self.index][1] )
                
            # get the end time right before the next update
            dt.timer_end();
            try:
                if bytes > 0:
                    delta = dt.usdelta
                    #print delta, float(delta)/bytes, bytes/delta
                    delta = float(delta)/float(bytes)
                    if rTime > 0: rTime = (rTime*9 + delta)/10
                    else:         rTime = delta
                    if byteAvg > 0: byteAvg = (byteAvg*9 + bytes)/10
                    else:           byteAvg = bytes
                    time_remaining = byteAvg*rTime #average microseconds per song
                    time_remaining *= (r-self.index) # times the total songs remaining
                    time_remaining /= 1000 # to milliseconds
            except:
                pass
            finally:
                dt.timer_start();
                
                
            self.parent.emit(SIGNAL("UPDATE_SYNC_DIALOG"),self.parent,self.index)
            # get the next start time immediatley after updating.
            
            
            self.index += 1  
            
        self.parent.emit(SIGNAL("SYNC_SET_TEXT"),self.parent,"Copying - Done")   
        return;
def musicLoad_LIBZ(filepath):
    """
        load the specified .libz file and return an array of songs.
        
        #todo : read 8 bytes
        # read in : LVERABCD
        # if A== 0x3D == '=' then file is ascii format
        
        # when saving a non binary version save version as '=001' or 3D 30 30 31
        # increment the version count for new ascii file formats
        # for binary formats:
        #   LVERABCD, where A,B,C,D are a little endian 32 bit integer with A=0x00
    """
    
    srclib = fileGetName(filepath)
    if not os.path.exists(filepath):
        return [];
    
    R=[];
    drivelist = [];
    cnt = 0
    
    dt = DateTime()
    dt.timer_start();
    with open(filepath,"rb") as FILE:
        # ##################################
        # read the header
        header={};
        bin = FILE.read(8);
        key,val = struct.unpack("4sI",bin)
        while key != "SIZE" and bin:
            header[key] = val;
            bin = FILE.read(8);
            if bin:
                key,val = struct.unpack("4sI",bin)
                
        # ##################################
        # process the header dictionary
        typ = header.get("LTYP",0)      # needed for restoring file paths
        blk = header.get("LBLK",128)    # not really needed
        fmt = header.get("LFMT",Song.repr_length()) # needed to restore each song record.
        cnt = header.get("LCNT",0)
        
        if typ&2 == 2: 
            drivelist=systemDriveList(); 
            
        # ##################################
        # now  read the data from the file.         
        bin = FILE.read(val);        
        while bin:
        
            if typ&1 == 0 and pylzma != None: #compression is only used when typ&1 == 0.
                bin = pylzma.decompress(bin);
            
            R += LIBZ_process_block( bin , typ, fmt, drivelist,srclib );

            bin = FILE.read(8);
            if bin:
                key,size = struct.unpack("4sI",bin)
                bin = FILE.read(size); # read val bytes from the frame  
   
    dt.timer_end();
    print "Loaded %d/%d songs from libz container in %s"%(len(R),cnt,DateTime.formatTimeDeltams(dt.timedelta))
    return R;
Пример #32
0
def setSearchTime(): 
    dt = DateTime()
    date = dt.currentDate();
    
    MpGlobal.RecentEpochTime = dt.getEpochTime(date+" 00:00") # return seconds at start of this day
    MpGlobal.LaunchEpochTime = MpGlobal.RecentEpochTime - (14*24*60*60) # date of two weeks ago