예제 #1
0
 def log_error(self, log):
     log.write(
         "%s: %s\nID: %s\n%s: %s\n%s: %s\n\n" %
         (_("Reason"),
          mtp_invalid_file_strings[mtpconnect.is_valid_track()],
          mtpconnect.get_item_id(), _("Title"), str(mtpconnect.get_title()),
          _("Artist"), str(mtpconnect.get_artist())))
예제 #2
0
파일: main.py 프로젝트: aurbn/mtp-lastfm
 def log_error(self, log):
     log.write("%s: %s\nID: %s\n%s: %s\n%s: %s\n\n" %
         (_("Reason"), mtp_invalid_file_strings[mtpconnect.is_valid_track()],
          mtpconnect.get_item_id(), _("Title"), str(mtpconnect.get_title()),
          _("Artist"), str(mtpconnect.get_artist())))
예제 #3
0
 def on_check_device_clicked(self, widget):
     #open dblog
     log = open(self.HOME_DIR + "db.log", "w")
     log.write(_("Tracks that recently failed a validity check:\n"))
     #disable button as a double click will cause a panic
     self.tree.get_widget("check_device").set_sensitive(False)
     self.write_info(_("Connecting to MTP device"))
     conn_status = mtpconnect.open_device()
     if conn_status != 0:
         self.write_info(mtp_error_strings[conn_status])
         self.tree.get_widget("check_device").set_sensitive(True)
         return
     self.tree.get_widget("send_comp_info").set_sensitive(True)
     self.stats = {
         "manufacturer": mtpconnect.get_manufacturer(),
         "model": mtpconnect.get_model(),
         "name": mtpconnect.get_friendly_name()
     }
     self.write_info(
         _("Successfully connected to %(name)s %(model)s" % self.stats))
     current_track = mtpconnect.get_tracks()
     track_count = mtpconnect.get_track_count()
     invalid_track_count = 0
     self.progress_bar.set_vars(max_value=track_count)
     self.write_info(
         _("%s items found on device, cross checking with local database..."
           % track_count))
     self.progress_bar.start()
     #reset song counter to 0 so we know how many new scrobbles were added this time
     #in case there were some pending already
     self.song_db.new_scrobble_count = 0
     while current_track is not None:
         if mtpconnect.is_valid_track() == 0:
             #build a songdic that matches old implementation
             song = {}
             song['artist'] = mtpconnect.get_artist()
             song['title'] = mtpconnect.get_title()
             song['rating'] = mtpconnect.get_rating()
             song['album'] = mtpconnect.get_album()
             for key, value in song.items():
                 try:
                     song[key] = unicode(value, 'utf-8')
                 except TypeError:
                     song[key] = ""
             song['id'] = mtpconnect.get_item_id()
             try:
                 song['tracknumber'] = int(mtpconnect.get_track_number())
             except TypeError:
                 song['tracknumber'] = 0
             song['duration'] = mtpconnect.get_duration()
             try:
                 song['usecount'] = int(mtpconnect.get_usecount())
             except TypeError:
                 song['usecount'] = 0
             self.song_db.add_new_data(song)
         else:
             invalid_track_count += 1
             self.log_error(log)
         current_track = mtpconnect.next_track()
         self.progress_bar.current_progress += 1
         if self.progress_bar.current_progress % 20 == 0 or self.progress_bar.current_progress > track_count - 20:
             self.progress_bar.progress_bar.set_text(song['artist'])
             self.tree.get_widget("cache_label").set_text(
                 "(%s)" % self.song_db.scrobble_counter)
         if self.progress_bar.current_progress == track_count:
             self.progress_bar.set_vars(pulse_mode=True,
                                        text=_("Closing device"))
         while gtk.events_pending():
             gtk.main_iteration()
     if track_count == 0:
         self.write_info(_("No tracks were found on your device."))
     if self.song_db.new_scrobble_count != 0:
         self.write_info(
             _("Found %s new tracks for scrobbling" %
               self.song_db.new_scrobble_count))
     mtpconnect.close_device()
     self.progress_bar.stop()
     if invalid_track_count > 0:
         self.create_log_button(invalid_track_count)
         self.tree.get_widget("log_menu").set_sensitive(True)
     else:
         self.tree.get_widget("log_menu").set_sensitive(False)
     log.close()
     self.song_db.reset_scrobble_counter()
     self.set_button_count()
     self.tree.get_widget("check_device").set_sensitive(True)
     if self.options.return_option("auto_scrobble") == True:
         self.on_scrobble_clicked(None)
     if not self.usersDB.has_asked_for_stats(self.username, self.stats):
         self.open_program_works_dialog(None)
         self.usersDB.asked_for_stats(self.username, self.stats)
예제 #4
0
파일: main.py 프로젝트: aurbn/mtp-lastfm
 def on_check_device_clicked(self, widget):
     #open dblog
     log = open(self.HOME_DIR + "db.log", "w")
     log.write(_("Tracks that recently failed a validity check:\n"))
     #disable button as a double click will cause a panic
     self.tree.get_widget("check_device").set_sensitive(False)
     self.write_info(_("Connecting to MTP device"))
     conn_status = mtpconnect.open_device()
     if conn_status != 0:
         self.write_info(mtp_error_strings[conn_status])
         self.tree.get_widget("check_device").set_sensitive(True)
         return
     self.tree.get_widget("send_comp_info").set_sensitive(True)
     self.stats = {"manufacturer" : mtpconnect.get_manufacturer(),
                  "model" : mtpconnect.get_model(),
                  "name" : mtpconnect.get_friendly_name()}
     self.write_info(_("Successfully connected to %(name)s %(model)s" % self.stats))
     current_track = mtpconnect.get_tracks()
     track_count = mtpconnect.get_track_count()
     invalid_track_count = 0
     self.progress_bar.set_vars(max_value=track_count)
     self.write_info(_("%s items found on device, cross checking with local database..." % track_count))
     self.progress_bar.start()
     #reset song counter to 0 so we know how many new scrobbles were added this time
     #in case there were some pending already
     self.song_db.new_scrobble_count = 0
     while current_track is not None:
         if mtpconnect.is_valid_track() == 0:
             #build a songdic that matches old implementation
             song = {}
             song['artist'] = mtpconnect.get_artist()
             song['title'] = mtpconnect.get_title()
             song['rating'] = mtpconnect.get_rating()
             song['album'] = mtpconnect.get_album()
             for key, value in song.items():
                 try:
                     song[key] = unicode(value, 'utf-8')
                 except TypeError:
                     song[key] = ""
             song['id'] = mtpconnect.get_item_id()
             try:
                 song['tracknumber'] = int(mtpconnect.get_track_number())
             except TypeError:
                 song['tracknumber'] = 0
             song['duration'] = mtpconnect.get_duration()
             try:
                 song['usecount'] = int(mtpconnect.get_usecount())
             except TypeError:
                 song['usecount'] = 0
             self.song_db.add_new_data(song)
         else:
             invalid_track_count += 1
             self.log_error(log)
         current_track = mtpconnect.next_track()
         self.progress_bar.current_progress += 1
         if self.progress_bar.current_progress % 20 == 0 or self.progress_bar.current_progress > track_count - 20:
             self.progress_bar.progress_bar.set_text(song['artist'])
             self.tree.get_widget("cache_label").set_text("(%s)" % self.song_db.scrobble_counter)            
         if self.progress_bar.current_progress == track_count:
             self.progress_bar.set_vars(pulse_mode=True, text=_("Closing device"))
         while gtk.events_pending():
             gtk.main_iteration()
     if track_count == 0:
         self.write_info(_("No tracks were found on your device."))
     if self.song_db.new_scrobble_count != 0:
         self.write_info(_("Found %s new tracks for scrobbling" % self.song_db.new_scrobble_count))
     mtpconnect.close_device()
     self.progress_bar.stop()
     if invalid_track_count > 0:
         self.create_log_button(invalid_track_count)
         self.tree.get_widget("log_menu").set_sensitive(True)
     else:
         self.tree.get_widget("log_menu").set_sensitive(False)
     log.close()
     self.song_db.reset_scrobble_counter()
     self.set_button_count()
     self.tree.get_widget("check_device").set_sensitive(True)
     if self.options.return_option("auto_scrobble") == True:
         self.on_scrobble_clicked(None)
     if not self.usersDB.has_asked_for_stats(self.username, self.stats):
         self.open_program_works_dialog(None)
         self.usersDB.asked_for_stats(self.username, self.stats)