Example #1
0
 def on_btn_play_clicked(self, btn_play):
     """
     Get the seletect tracks on the tree and play them with the defined
     mp3 player (default 'totem')        
     """
     title = _("Music player")
     try:
         self.log.info("Play selected tracks")
         selected_track_list = self.mp3_tree.get_selected_mp3_files()
         selected_tracks = ''
         if len(selected_track_list) > 0:
             selected_tracks = '"' + '" "'.join(selected_track_list) + '"'        
         play_command = "%s %s" % (self.config['music']['player'],
                                     selected_tracks)
                                     
         process = subprocess.Popen(play_command,
                                    shell = True,
                                    stdout = subprocess.PIPE,
                                    stderr = subprocess.PIPE)
                                    
         # Wait a bit to kwnon if the process failed inmediatily
         time.sleep(0.2)
         returncode = process.poll()
         if returncode:                
             error_message = _("Cannot open music player:\n\n")
             stdout = ''.join(process.stdout.readlines()).replace("&","&")
             stderr = ''.join(process.stderr.readlines()).replace("&","&")
             error_message = "%s%s%s" % (error_message, stdout, stderr)
             message.error(title, error_message, self.GMusicTagger)
     except:
         self.log.exception("Error running music player")
         exception_message = _("Error running music player")
         message.exception(title, exception_message, self.GMusicTagger)
Example #2
0
 def on_btn_test_music_player_program_clicked (self, btn_test_music_player_program):
     """
     """
     play_command = self.entry_music_player_program.get_text()
     
     process = subprocess.Popen(play_command,
                                shell = True,
                                stdout = subprocess.PIPE,
                                stderr = subprocess.PIPE)
                                
     # Wait a bit to kwnon if the process failed inmediatily
     time.sleep(0.2)
     returncode = process.poll()
     title = _("Music player test")
     if returncode:
         error_message = _("Cannot open music player:\n\n")
         stdout = ''.join(process.stdout.readlines()).replace("&","&")
         stderr = ''.join(process.stderr.readlines()).replace("&","&")
         error_message = "%s%s%s" % (error_message, stdout, stderr)
         message.error(title, error_message, self.dialog_settings)
     else:
         ok_message = _("The player '%s' works!") % play_command 
         message.info(title, ok_message, self.dialog_settings)
Example #3
0
    def on_btn_test_music_player_program_clicked(
            self, btn_test_music_player_program):
        """
        """
        play_command = self.entry_music_player_program.get_text()

        process = subprocess.Popen(play_command,
                                   shell=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)

        # Wait a bit to kwnon if the process failed inmediatily
        time.sleep(0.2)
        returncode = process.poll()
        title = _("Music player test")
        if returncode:
            error_message = _("Cannot open music player:\n\n")
            stdout = ''.join(process.stdout.readlines()).replace("&", "&")
            stderr = ''.join(process.stderr.readlines()).replace("&", "&")
            error_message = "%s%s%s" % (error_message, stdout, stderr)
            message.error(title, error_message, self.dialog_settings)
        else:
            ok_message = _("The player '%s' works!") % play_command
            message.info(title, ok_message, self.dialog_settings)
Example #4
0
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
###############################################################################

import core.env as env
from core.env import _
import ui.message as message


def show_notification(title, message):
    print "%s -> %s" % (title, message)


try:
    import pynotify

    if pynotify.init(env.APP_NAME):

        def show_notification(title, message):
            notification = pynotify.Notification(title, message)
            notification.set_icon_from_pixbuf(env.GMUSICTAGGER_BUF)
            notification.set_urgency(pynotify.URGENCY_LOW)
            notification.show()


except ImportError:
    error_title = _("GMusicTagger: Notifier module")
    error_message = _("Cannot start notification module.\n") + _("Try installing 'python-notify' package")
    message.error(error_title, error_message)
Example #5
0
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
###############################################################################

import core.env as env
from core.env import _
import ui.message as message


def show_notification(title, message):
    print "%s -> %s" % (title, message)


try:
    import pynotify

    if pynotify.init(env.APP_NAME):

        def show_notification(title, message):
            notification = pynotify.Notification(title, message)
            notification.set_icon_from_pixbuf(env.GMUSICTAGGER_BUF)
            notification.set_urgency(pynotify.URGENCY_LOW)
            notification.show()
except ImportError:
    error_title = _("GMusicTagger: Notifier module")
    error_message = _("Cannot start notification module.\n") + \
                    _("Try installing 'python-notify' package")
    message.error(error_title, error_message)
Example #6
0
    def update_selected_iters(self):
        """
        Retrieve all the mp3 paths selected with changes pending to update 
        and update them tags. Rename the files if File column have changes.
        """
        APPLOG.info("Update selected mp3 paths with pending changes")
        
        # Initialize updates counter
        total_files_updated = 0        
        
        # Gets the mp3 paths to update        
        selected_mp3_paths = self.get_selected_mp3_files()
        mp3_paths_to_update = self.mp3_store.pending_files_to_update(selected_mp3_paths)
        
        if mp3_paths_to_update:                   
            # Initialize the progressbar
            self.progressbarbox.set_property('visible',True)
            self.progressbarbox.set_new_bar(len(mp3_paths_to_update))
                    
            for mp3 in mp3_paths_to_update:
                # Check if the action is not cancelled            
                if not self.progressbarbox.cancel_action:
                    # Refresh the progressbar
                    self.progressbarbox.next(_("Updating %s...") % mp3)                 
                
                    # Update Mp3 tag and rename the filename
                    is_updated = self.mp3_store.update(mp3)
                    
                    # Rename Mp3 file
                    is_renamed = False
                    new_mp3 = self.mp3_store.rename(mp3)
                    if new_mp3:
                        is_renamed = True
                        if mp3 != new_mp3:                        
                            self.update_mp3_path(mp3,new_mp3)
                            mp3 = new_mp3
                                                            
                    if is_updated and is_renamed:
                        self.mp3_store.remove_for_update(mp3)
                        APPLOG.info("'%s' successfully saved" % mp3)                        
                        total_files_updated += 1                                                
                    elif not is_updated:
                        APPLOG.info("'%s' not saved" % mp3)
                        message.error(_("Save Mp3 changes"),
                                      _("Error while saving Mp3 %s metadata") % mp3,
                                      self.get_toplevel())
                    elif not is_renamed:
                        APPLOG.info("'%s' not renamed" % mp3)
                        message.error(_("Save Mp3 changes"),
                                      _("Error while renaming Mp3 %s") % mp3,
                                      self.get_toplevel())
                else:
                    APPLOG.warning("Save process cancelled")
                    self.progressbarbox.cancel_message()
                    time.sleep(CANCEL_ACTION_SLEEP)
                    break           
                
            # Hide the progressbar
            self.progressbarbox.set_property('visible',False)                                                              
        else:
            APPLOG.info("No changes pending on the selected mp3 files")
            message.info(_("Update Mp3 files"),
                         _("No changes pending on the selected Mp3 Files."),
                         self.get_toplevel())

        return total_files_updated
Example #7
0
    def add_iters(self,mp3_files):
        """ Insert the new mp3 files in the Tree ListStore """
        APPLOG.info("Add new iters on the Mp3 Tree")
        
        # Initialize addition counter
        total_files_added = 0
        
        # Initialize the progressbar
        self.progressbarbox.set_property('visible',True)
        self.progressbarbox.set_new_bar(len(mp3_files))
                                     
        # Append the files in the Tree ListStore
        for mp3 in mp3_files:
            # Check if the action is not cancelled            
            if not self.progressbarbox.cancel_action:
                # Refresh the progressbar
                self.progressbarbox.next(_("Loading %s...") % mp3)
            
                # Add Mp3 File in the storage Core and read it
                added_mp3 = self.mp3_store.add_item(mp3)
                if added_mp3:
                    if added_mp3 < 2:
                        try:
                            mp3_audio_file = self.mp3_store.get_metadata(mp3)
                            mp3_tag = mp3_audio_file.getTag() 
                            
                            # Gets Filename by the path basename and without ext
                            filename = os.path.basename(mp3)
                            i = filename.rindex('.')
                            filename = filename[:i]
                            
                            # Retrieve the complex tags (Genre and Comments)
                            try:
                                genre = mp3_tag.getGenre()
                                if genre:
                                    genre_name = genre.getName()
                                else:
                                    genre_name = u''
                            except eyeD3.tag.GenreException:
                                genre_name = ''
                                                
                            comments = mp3_tag.getComments()
                            if len(comments) > 0:
                                comment_string = comments[0].comment
                            else:
                                comment_string = u''                         
                            
                            
                            # Retrieve all text fields of the MP3 tag
                            # and sets the tree fields
                            col_selec      = self.config['misc']['auto-select-when-added']
                            col_file       = filename
                            col_num        = self.getTrackNumString(mp3_tag.getTrackNum())
                            col_title      = mp3_tag.getTitle()
                            col_artist     = mp3_tag.getArtist('TPE1')
                            col_band       = mp3_tag.getArtist('TPE2')
                            col_performer  = mp3_tag.getArtist('TPE3')
                            col_remix      = mp3_tag.getArtist('TPE4')
                            col_compositor = mp3_tag.getArtist('TCOM')
                            col_album      = mp3_tag.getAlbum()
                            col_year       = mp3_tag.getYear()
                            col_genre      = genre_name
                            col_comments   = comment_string
                            col_duration   = mp3_audio_file.getPlayTimeString()
                            col_bitrate    = mp3_audio_file.getBitRateString()
                            col_path       = mp3
                            
                            iter_tuple_values = (col_selec, col_file, col_num, col_title,
                                                 col_artist, col_band, col_performer,
                                                 col_remix, col_compositor, col_album,
                                                 col_year, col_genre, self.genre_model,
                                                 col_comments, col_duration, col_bitrate,
                                                 col_path)                                     

                            self.model.append(iter_tuple_values)
                            total_files_added += 1
                        except:
                            APPLOG.exception("Reading Tag from %s" % mp3)
                            message.exception(_("Reading Mp3 tags"),
                                              _("Error reading Mp3 Tag from '%s'\n")
                                              % os.path.basename(mp3).replace("&","&amp;"),
                                              self.get_toplevel())
                            self.mp3_store.remove_items([mp3])                        
                else:          
                    message.error(_("Initialize Mp3 Tag"),
                                  _("Error adding Mp3 File '%s'.\nCheck the app log.")
                                  % os.path.basename(mp3).replace("&","&amp;"),
                                  self.get_toplevel())  
            else:
                APPLOG.warning("Load process cancelled")
                self.progressbarbox.cancel_message()
                time.sleep(CANCEL_ACTION_SLEEP)
                break
                        
        # Hide the progressbar
        self.progressbarbox.set_property('visible',False)
                                              
        return total_files_added