コード例 #1
0
 def render(self, musicentries):
     retlist = []
     for entry in musicentries:
         if entry.compact:
             #compact
             retlist.append({
                 'type': 'compact',
                 'urlpath': entry.path,
                 'label': entry.repr
             })
         elif entry.dir:
             #dir
             simplename = pathprovider.filename(entry.path)
             retlist.append({
                 'type': 'dir',
                 'path': entry.path,
                 'label': simplename
             })
         else:
             #file
             simplename = pathprovider.filename(entry.path)
             urlpath = quote(('/serve/' + entry.path).encode('utf8'))
             retlist.append({
                 'type': 'file',
                 'urlpath': urlpath,
                 'path': entry.path,
                 'label': simplename
             })
     return json.dumps(retlist)
コード例 #2
0
ファイル: cherrymodel.py プロジェクト: mikeder/cherrymusic
 def to_dict(self):
     if self.compact:
         #compact
         return {
             'type': 'compact',
             'urlpath': self.path,
             'label': self.repr
         }
     elif self.dir:
         #dir
         simplename = pathprovider.filename(self.path)
         return {
             'type': 'dir',
             'path': self.path,
             'label': simplename,
             'foldercount': self.subdircount,
             'filescount': self.subfilescount,
             'filescountestimate': self.subfilesestimate
         }
     else:
         #file
         simplename = pathprovider.filename(self.path)
         urlpath = quote(self.path.encode('utf8'))
         return {
             'type': 'file',
             'urlpath': urlpath,
             'path': self.path,
             'label': simplename
         }
コード例 #3
0
 def sortFiles(self, files, fullpath=''):
     upper_case_filename = lambda x: pathprovider.filename(x).upper()
     #sort alphabetically (case insensitive)
     sortedfiles = sorted(files, key=upper_case_filename)
     if fullpath:
         #sort directories up
         isfile = lambda x: os.path.isfile(os.path.join(fullpath, x))
         sortedfiles = sorted(sortedfiles, key=isfile)
     return sortedfiles
コード例 #4
0
ファイル: cherrymodel.py プロジェクト: cshimmin/cherrymusic
 def sortFiles(self, files, fullpath=''):
     upper_case_filename = lambda x: pathprovider.filename(x).upper()
     #sort alphabetically (case insensitive)
     sortedfiles = sorted(files, key=upper_case_filename)
     if fullpath:
         #sort directories up
         isfile = lambda x: os.path.isfile(os.path.join(fullpath, x))
         sortedfiles = sorted(sortedfiles, key=isfile)
     return sortedfiles
コード例 #5
0
 def fileSortFunc(cls, filepath):
     upper = pathprovider.filename(filepath).upper()
     if ' ' in upper:
         part_part = upper[:upper.index(' ')]
         # make sure that numbers are sorted correctly by evening out
         # the number in the filename 0-padding to 5 digits.
         if part_part.isdigit():
             return '0'*(5 - len(part_part)) + upper
     return upper
コード例 #6
0
ファイル: cherrymodel.py プロジェクト: Blisse/cherrymusic
 def sortFiles(self, files, fullpath=''):
     upper_case_filename = lambda x: pathprovider.filename(x).upper()
     # sort alphabetically (case insensitive, make sure numbers are
     # sorted correctly)
     sortedfiles = sorted(files, key=CherryModel.fileSortFunc)
     if fullpath:
         #sort directories up
         isfile = lambda x: os.path.isfile(os.path.join(fullpath, x))
         sortedfiles = sorted(sortedfiles, key=isfile)
     return sortedfiles
コード例 #7
0
 def to_dict(self):
     if self.compact:
         #compact
         return {'type': 'compact',
                 'urlpath': self.path,
                 'label': self.repr}
     elif self.dir:
         #dir
         simplename = pathprovider.filename(self.path)
         return {'type': 'dir',
                 'path': self.path,
                 'label': simplename}
     else:
         #file
         simplename = pathprovider.filename(self.path)
         urlpath = quote(self.path.encode('utf8'))
         return {'type': 'file',
                 'urlpath': urlpath,
                 'path': self.path,
                 'label': simplename}
コード例 #8
0
 def render(self, musicentries):
     retlist = []
     for entry in musicentries:
         if entry.compact:
             #compact
             retlist.append({'type':'compact', 'urlpath':entry.path,'label':entry.repr})
         elif entry.dir:
             #dir
             simplename = pathprovider.filename(entry.path)
             retlist.append({'type':'dir',
                             'path':entry.path,
                             'label':simplename
                             })
         else:
             #file
             simplename = pathprovider.filename(entry.path)
             urlpath = quote(('serve/' + entry.path).encode('utf8'));
             retlist.append({'type':'file',
                             'urlpath':urlpath,
                             'path':entry.path,
                             'label':simplename})
     return json.dumps(retlist)
コード例 #9
0
    def __call__(self, element):
        file = element.path
        isdir = element.dir
        fullpath = file.lower()
        filename = pathprovider.filename(file).lower()
        filename_words = filename.split(' ')

        bias = 0
        occurences_bias = 0
        perfect_match_bias = 0
        partial_perfect_match_bias = 0
        folder_bias = 0
        starts_with_bias = 0
        starts_with_no_track_number_bias = 0

        #count occurences of searchwords
        occurences = 0
        for searchword in self.searchwords:
            if searchword in fullpath:
                occurences_bias += self.word_in_file_path_bonus
            else:
                occurences_bias += self.word_not_in_file_path_penalty
            if searchword in filename:
                occurences_bias += self.word_in_file_name_bonus
            else:
                occurences_bias += self.word_not_in_file_name_penalty

        #perfect match?
        if filename == self.fullsearchterm or self.noThe(
                filename) == self.fullsearchterm:
            perfect_match_bias += self.perfect_match_bonus

        filename = pathprovider.stripext(filename)
        #partial perfect match?
        for searchword in self.searchwords:
            if searchword in filename_words:
                partial_perfect_match_bias += self.partial_perfect_match_bonus
        if isdir:
            folder_bias += self.folder_bonus

        #file starts with match?
        for searchword in self.searchwords:
            if filename.startswith(searchword):
                starts_with_bias += self.starts_with_bonus

        #remove possible track number
        while len(filename) > 0 and '0' <= filename[0] <= '9':
            filename = filename[1:]
        filename = filename.strip()
        for searchword in self.searchwords:
            if filename == searchword:
                starts_with_no_track_number_bias += self.starts_with_bonus

        bias = occurences_bias + perfect_match_bias + partial_perfect_match_bias + folder_bias + starts_with_bias + starts_with_no_track_number_bias

        if self.debug:
            element.debugOutputSort = '''
fullsearchterm: %s
searchwords: %s
filename: %s
filepath: %s
occurences_bias                  %d
perfect_match_bias               %d
partial_perfect_match_bias       %d
folder_bias                      %d
starts_with_bias                 %d
starts_with_no_track_number_bias %d
------------------------------------
total bias                       %d
            ''' % (self.fullsearchterm, self.searchwords, filename, fullpath,
                   occurences_bias, perfect_match_bias,
                   partial_perfect_match_bias, folder_bias, starts_with_bias,
                   starts_with_no_track_number_bias, bias)

        return bias
コード例 #10
0
ファイル: resultorder.py プロジェクト: Blisse/cherrymusic
    def __call__(self,element):
        file = element.path
        isdir = element.dir
        fullpath = file.lower()
        filename = pathprovider.filename(file).lower()
        filename_words = filename.split(' ')
        
        bias = 0
        occurences_bias = 0
        perfect_match_bias = 0
        partial_perfect_match_bias = 0
        folder_bias = 0
        starts_with_bias = 0
        starts_with_no_track_number_bias = 0
        
        #count occurences of searchwords
        occurences=0
        for searchword in self.searchwords:
            if searchword in fullpath:
                occurences_bias += self.word_in_file_path_bonus
            else:
                occurences_bias += self.word_not_in_file_path_penalty
            if searchword in filename:
                occurences_bias += self.word_in_file_name_bonus
            else:
                occurences_bias += self.word_not_in_file_name_penalty

        #perfect match?
        if filename == self.fullsearchterm or self.noThe(filename) == self.fullsearchterm:
            perfect_match_bias += self.perfect_match_bonus

        filename = pathprovider.stripext(filename)
        #partial perfect match?
        for searchword in self.searchwords:
            if searchword in filename_words:
                partial_perfect_match_bias += self.partial_perfect_match_bonus
        if isdir:
            folder_bias += self.folder_bonus

        #file starts with match?
        for searchword in self.searchwords:
            if filename.startswith(searchword):
                starts_with_bias += self.starts_with_bonus

        #remove possible track number
        while len(filename)>0 and '0' <= filename[0] <= '9':
            filename = filename[1:]
        filename = filename.strip()
        for searchword in self.searchwords:
            if filename == searchword:
                starts_with_no_track_number_bias += self.starts_with_bonus

        bias = occurences_bias + perfect_match_bias + partial_perfect_match_bias + folder_bias + starts_with_bias + starts_with_no_track_number_bias

        if self.debug:
            element.debugOutputSort = '''
fullsearchterm: %s
searchwords: %s
filename: %s
filepath: %s
occurences_bias                  %d
perfect_match_bias               %d
partial_perfect_match_bias       %d
folder_bias                      %d
starts_with_bias                 %d
starts_with_no_track_number_bias %d
------------------------------------
total bias                       %d
            ''' % (
        self.fullsearchterm,
        self.searchwords,
        filename,
        fullpath, 
        occurences_bias,
        perfect_match_bias,
        partial_perfect_match_bias,
        folder_bias,
        starts_with_bias,
        starts_with_no_track_number_bias,
        bias)

        return bias
コード例 #11
0
ファイル: cherrymodel.py プロジェクト: mikeder/cherrymusic
 def fileSortFunc(cls, filepath):
     upper = pathprovider.filename(filepath).upper().strip()
     return upper
コード例 #12
0
 def fileSortFunc(cls, filepath):
     upper = pathprovider.filename(filepath).upper().strip()
     return upper