def amend_genre_info(self, current_genre, new_genre, icon_name):
        root = ET.parse(open(self._user_popups)).getroot()
        base = self._sprite_name + '/alt/alt'

        found = False

        if current_genre != "":
            for elem in root.xpath(base):
                if RB.search_fold(elem.text) == RB.search_fold(current_genre):
                    found = True
                    del self.genre_alternate[GenreType(name=elem.text, genre_type=self.GENRE_USER)]
                    break

        else:
            elem = ET.SubElement(root.xpath(self._sprite_name + '/alt')[0], "alt")
            if elem != None:
                found = True

        if found:
            elem.text = rb3compat.unicodestr(new_genre, 'utf-8')
            elem.attrib['genre'] = icon_name

            tree = ET.ElementTree(root)
            tree.write(self._user_popups, pretty_print=True, xml_declaration=True)
            self.genre_alternate[GenreType(name=elem.text, genre_type=self.GENRE_USER)] = icon_name
            return GenreType(name=elem.text, genre_type=self.GENRE_USER)
        else:
            print("nothing found to amend")
            return None
    def amend_genre_info(self, current_genre, new_genre, icon_name):
        root = ET.parse(open(self._user_popups)).getroot()
        base = self._sprite_name + '/alt/alt'

        found = False

        if current_genre != "":
            for elem in root.xpath(base):
                if RB.search_fold(elem.text) == RB.search_fold(current_genre):
                    found = True
                    del self.genre_alternate[GenreType(
                        name=elem.text, genre_type=self.GENRE_USER)]
                    break

        else:
            elem = ET.SubElement(
                root.xpath(self._sprite_name + '/alt')[0], "alt")
            if elem != None:
                found = True

        if found:
            elem.text = rb3compat.unicodestr(new_genre, 'utf-8')
            elem.attrib['genre'] = icon_name

            tree = ET.ElementTree(root)
            tree.write(self._user_popups,
                       pretty_print=True,
                       xml_declaration=True)
            self.genre_alternate[GenreType(
                name=elem.text, genre_type=self.GENRE_USER)] = icon_name
            return GenreType(name=elem.text, genre_type=self.GENRE_USER)
        else:
            print("nothing found to amend")
            return None
Example #3
0
    def set_save_sensitivity(self, _):
        '''
        action to toggle the state of the save button depending
        upon the values entered in the genre edit fields
        '''
        entry_value = self.genre_entry.get_text()
        treeiter = self.genre_combobox.get_active_iter()

        entry_value = rb3compat.unicodestr(entry_value, 'utf-8')
        enable = False
        try:
            test = self._iters[(entry_value, self.GENRE_LIST)]
            if RB.search_fold(
                    self.current_genre) == RB.search_fold(entry_value):
                # if the current entry is the same then could save
                enable = True
        except:
            # reach here if this is a brand new entry
            enable = True

        if treeiter == None or entry_value == None or entry_value == "":
            # no icon chosen, or no entry value then nothing to save
            enable = False

        self.save_button.set_sensitive(enable)
 def similar_info_cb(self, data, _):
             
     if not data:
         print ("nothing to do")
         self._clear_next()
         return
         
     similar = json.loads(data.decode('utf-8'))
     
     # loop through the response and find all titles for the artists returned
     self.artist = {}
     
     if 'songs' not in similar['response']:
         print ("No matching data returned from EchoNest")
         self._clear_next()
         return
     for song in similar['response']['songs']:
         name = RB.search_fold(song['artist_name'])
         if name not in self.artist:
             self.artist[name] = []
             
         self.artist[name].append(RB.search_fold(song['title']))
         
     if len(self.artist) == 0:
         print ("no artists returned")
         self._clear_next()
         return
         
     # loop through every track - see if the track contains the artist & title
     # if yes then this is a candidate similar track to remember
     
     query_model = self.shell.props.library_source.props.base_query_model
     
     self._load_albums(iter(query_model), albums={}, model=query_model,
         total=len(query_model), progress=0.)
Example #5
0
    def _find_alternates(self, test_genre):
        # the following genre checks are required
        # 1. if we have user defined genres
        # 2. then check locale specific system genres
        # 3. then check local specific alternates
        # 4. then check if we system genres

        # where necessary check if any of the genres are a substring
        # of test_genre - check in reverse order so that we
        # test largest strings first (prevents spurious matches with
        # short strings)
        # N.B. we use RB.search_fold since the strings can be
        # in a mixture of cases, both unicode (normalized or not) and str
        # and as usual python cannot mix and match these types.

        test_genre = RB.search_fold(test_genre)

        ret, sprite = self._match_genres(test_genre,
                                         self._spritesheet.GENRE_USER)
        if ret:
            return sprite

        for genre in sorted(self._spritesheet.locale_names,
                            key=lambda b: (-len(b), b)):
            if RB.search_fold(genre) in test_genre:
                return self._spritesheet[self._spritesheet.locale_names[genre]]

        # next check locale alternates
        ret, sprite = self._match_genres(test_genre,
                                         self._spritesheet.GENRE_LOCALE)
        if ret:
            return sprite

        ret, sprite = self._match_genres(test_genre,
                                         self._spritesheet.GENRE_SYSTEM)
        if ret:
            return sprite

        # check if any of the default genres are a substring
        # of test_genre - check in reverse order so that we
        # test largest strings first (prevents spurious matches with
        # short strings)
        for genre in sorted(self._spritesheet.names,
                            key=lambda b: (-len(b), b)):
            if RB.search_fold(genre) in test_genre:
                return self._spritesheet[genre]

        # if no matches then default to unrecognised image
        return self._unrecognised_image
    def _compare(self, model, row1, row2, user_data):

        if not model.iter_has_child(row1) or \
                not model.iter_has_child(row2):
            return 0

        sort_column = 0
        value1 = RB.search_fold(model.get_value(row1, sort_column))
        value2 = RB.search_fold(model.get_value(row2, sort_column))
        if value1 < value2:
            return -1
        elif value1 == value2:
            return 0
        else:
            return 1
Example #7
0
 def _compare(self, model, row1, row2, user_data):
     
     if not model.iter_has_child(row1) or \
         not model.iter_has_child(row2):
             return 0
             
     sort_column = 0
     value1 = RB.search_fold(model.get_value(row1, sort_column))
     value2 = RB.search_fold(model.get_value(row2, sort_column))
     if value1 < value2:
         return -1
     elif value1 == value2:
         return 0
     else:
         return 1
        def process_track(album, track):
            self.album_manager.progress = self._track_count / total
            self._track_count = self._track_count + 1

            key = album.create_ext_db_key()
            finalPath = rb3compat.unquote(track.location)[7:]
            album_name = RB.search_fold(album.name)
            
            if use_album_name:
                folder_store = final_folder_store + '/' + album_name
            else:
                folder_store = final_folder_store
                
            try:
                if not os.path.exists(folder_store):
                    os.makedirs(folder_store)
                
                if convert:
                    self.convert_to_mp3(finalPath, folder_store, bitrate)
                    finalPath = self._calc_mp3_filename(finalPath, folder_store)
                    print(finalPath)
                else:
                    shutil.copy(finalPath, folder_store)
            except IOError as err:
                print(err.args[0])
                return False

            dest = os.path.join(folder_store, os.path.basename(finalPath))
            desturi = 'file://' + rb3compat.pathname2url(dest)
            
            return search_tracks.embed(desturi, key, resize)
        def process_track(album, track):
            self.album_manager.progress = self._track_count / total
            self._track_count = self._track_count + 1

            key = album.create_ext_db_key()
            finalPath = rb3compat.unquote(track.location)[7:]
            album_name = RB.search_fold(album.name)

            if use_album_name:
                folder_store = final_folder_store + '/' + album_name
            else:
                folder_store = final_folder_store

            try:
                if not os.path.exists(folder_store):
                    os.makedirs(folder_store)

                if convert:
                    self.convert_to_mp3(finalPath, folder_store, bitrate)
                    finalPath = self._calc_mp3_filename(finalPath, folder_store)
                    print(finalPath)
                else:
                    shutil.copy(finalPath, folder_store)
            except IOError as err:
                print(err.args[0])
                return False

            dest = os.path.join(folder_store, os.path.basename(finalPath))
            desturi = 'file://' + rb3compat.pathname2url(dest)

            return search_tracks.embed(desturi, key, resize)
    def _find_alternates(self, test_genre):
        # the following genre checks are required
        # 1. if we have user defined genres
        # 2. then check locale specific system genres
        # 3. then check local specific alternates
        # 4. then check if we system genres

        # where necessary check if any of the genres are a substring
        # of test_genre - check in reverse order so that we
        # test largest strings first (prevents spurious matches with
        # short strings)
        # N.B. we use RB.search_fold since the strings can be
        # in a mixture of cases, both unicode (normalized or not) and str
        # and as usual python cannot mix and match these types.

        
        test_genre = RB.search_fold(test_genre)
        
        ret, sprite = self._match_genres(test_genre, self._spritesheet.GENRE_USER)
        if ret:
            return sprite
                
        for genre in sorted(self._spritesheet.locale_names,
            key=lambda b: (-len(b), b)):
            if RB.search_fold(genre) in test_genre:
                return self._spritesheet[self._spritesheet.locale_names[genre]]

        # next check locale alternates
        ret, sprite = self._match_genres(test_genre, self._spritesheet.GENRE_LOCALE)
        if ret:
            return sprite

        ret, sprite = self._match_genres(test_genre, self._spritesheet.GENRE_SYSTEM)
        if ret:
            return sprite
        
        # check if any of the default genres are a substring
        # of test_genre - check in reverse order so that we
        # test largest strings first (prevents spurious matches with
        # short strings)
        for genre in sorted(self._spritesheet.names,
            key=lambda b: (-len(b), b)):
            if RB.search_fold(genre) in test_genre:
                return self._spritesheet[genre]
                
        # if no matches then default to unrecognised image
        return self._unrecognised_image
    def delete_genre(self, current_genre):
        root = ET.parse(open(self._user_popups)).getroot()
        base = self._sprite_name + '/alt/alt'

        found = False

        for elem in root.xpath(base):
            if RB.search_fold(elem.text) == RB.search_fold(current_genre):
                found = True
                break

        if found:
            elem.getparent().remove(elem)
            tree = ET.ElementTree(root)
            tree.write(self._user_popups, pretty_print=True, xml_declaration=True)
        else:
            print("not found to delete")
    def delete_genre(self, current_genre):
        root = ET.parse(open(self._user_popups)).getroot()
        base = self._sprite_name + '/alt/alt'

        found = False

        for elem in root.xpath(base):
            if RB.search_fold(elem.text) == RB.search_fold(current_genre):
                found = True
                break

        if found:
            elem.getparent().remove(elem)
            tree = ET.ElementTree(root)
            tree.write(self._user_popups,
                       pretty_print=True,
                       xml_declaration=True)
        else:
            print("not found to delete")
Example #13
0
    def similar_info_cb(self, data, _):

        if not data:
            print("nothing to do")
            self._clear_next()
            return

        similar = json.loads(data.decode('utf-8'))

        # loop through the response and find all titles for the artists returned
        self.artist = {}

        if 'songs' not in similar['response']:
            print("No matching data returned from EchoNest")
            self._clear_next()
            return
        for song in similar['response']['songs']:
            name = RB.search_fold(song['artist_name'])
            if name not in self.artist:
                self.artist[name] = []

            self.artist[name].append(RB.search_fold(song['title']))

        if len(self.artist) == 0:
            print("no artists returned")
            self._clear_next()
            return

        # loop through every track - see if the track contains the artist & title
        # if yes then this is a candidate similar track to remember

        query_model = self.shell.props.library_source.props.base_query_model

        self._load_albums(iter(query_model),
                          albums={},
                          model=query_model,
                          total=len(query_model),
                          progress=0.)
    def set_save_sensitivity(self, _):
        '''
        action to toggle the state of the save button depending
        upon the values entered in the genre edit fields
        '''
        entry_value = self.genre_entry.get_text()
        treeiter = self.genre_combobox.get_active_iter()

        entry_value = rb3compat.unicodestr(entry_value, 'utf-8')
        enable = False
        try:
            test = self._iters[(entry_value, self.GENRE_LIST)]
            if RB.search_fold(self.current_genre) == RB.search_fold(entry_value):
                #if the current entry is the same then could save
                enable = True
        except:
            # reach here if this is a brand new entry
            enable = True

        if treeiter == None or entry_value == None or entry_value == "":
            # no icon chosen, or no entry value then nothing to save
            enable = False

        self.save_button.set_sensitive(enable)
 def actual_key_case(self, k):
     return self._s.get(RB.search_fold(k))
 def __getitem__(self, k):
     return self._d[self._s[RB.search_fold(k)]]
 def __getitem__(self, k):
     return self._d[self._s[RB.search_fold(k)]]
 def __init__(self, d):
     self._d = d
     self._s = dict((RB.search_fold(k), k) for k in d)
 def __contains__(self, k):
     return RB.search_fold(k) in self._s
 def __init__(self, d):
     self._d = d
     self._s = dict((RB.search_fold(k), k) for k in d)
 def actual_key_case(self, k):
     return self._s.get(RB.search_fold(k))
 def __contains__(self, k):
     return RB.search_fold(k) in self._s