示例#1
0
    def __init(self):        
        # Loaded theme file.
        self.loginfo("Loading application theme...")
        from widget.skin import app_theme        
        
        # Loaded configure.
        self.loginfo("Loading settings...")
        from config import config        
        config.load()
        
        self.__show_splash()

        # Loaded MediaDB.
        self.loginfo("Loading MediaDB...")
        from library import MediaDB
        MediaDB.connect("loaded", self.on_db_loaded)
        MediaDB.load()
        
        # Loaded Chinese to Pinyin DB.
        from pinyin import TransforDB        
        TransforDB.load()        
        
        # initialize Gui
        self.loginfo("Initialize Gui...")
        from widget.instance import DeepinMusic        
        self.app_instance = DeepinMusic()
        self.app_instance.connect("ready", self.on_ready_cb)

        if self.options.StartMinimized:
            self.app_instance.window.iconify()
示例#2
0
    def change_cover(self, song_or_name, new_cover):
        save_path = self.get_cover_path(song_or_name)
        if not os.path.exists(new_cover):
            return False

        try:
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                new_cover, COVER_SAVE_SIZE["x"], COVER_SAVE_SIZE["y"])
        except gobject.GError:
            return False
        else:
            str_pixbuf = pixbuf.get_pixels()
            if str_pixbuf.count(
                    "\x00") > len(str_pixbuf) / 2 or str_pixbuf.count(
                        "\xff") > len(str_pixbuf) / 2:
                return False
            else:
                if os.path.exists(save_path): os.unlink(save_path)
                pixbuf.save(save_path, "jpeg", {"quality": "85"})
                del pixbuf

                # Change property album to update UI
                if isinstance(song_or_name, Song):
                    Dispatcher.emit("album-changed", song_or_name)
                    MediaDB.set_property(song_or_name,
                                         {"album": song_or_name.get("album")})
                return True
示例#3
0
    def __on_db_loaded(self, db):
        if not MediaDB.get_playlists():
            MediaDB.create_playlist("local", _("Default List"))

        # From MediaDB loaded playlists.
        init_items = [ListTreeItem(pl) for pl in MediaDB.get_playlists()]
        self.category_list.add_items(init_items)

        # Init Category_list.
        self.category_list.set_highlight_item(
            self.get_categroy_item_by_index(self.get_save_item_index()))
        self.current_item = self.category_list.get_highlight_item()

        self.delete_source_id = self.current_item.song_view.connect(
            "delete-select-items", self.parser_delete_items)
        self.drag_source_id = self.current_item.song_view.connect(
            "drag-data-received", self.parser_drag_event)
        self.menu_source_id = self.current_item.song_view.connect(
            "right-press-items", self.popup_detail_menu)

        Player.set_source(self.current_item.song_view)
        self.right_box.add(self.current_item.get_list_widget())

        self.category_list.check_view_status()
        self.list_paned.show_all()
示例#4
0
 def __init__(self):
     uri =WinFile().run()
     if uri and common.file_is_supported(utils.get_path_from_uri(uri)):
         try:
             MediaDB.get_songs_by_uri(uri)
         except:    
             traceback.print_exc()
示例#5
0
    def __init__(self):
        gobject.GObject.__init__(self)
        self.__volumes = set()

        if dbus_imported:
            try:
                self.bus = dbus.SystemBus()
            except:
                self.bus = None

        if dbus_imported and self.bus and check_dbus(self.bus,
                                                     "org.freedesktop.UDisks"):
            self.dbus_udisks = True
            self.udisks_object = self.bus.get_object(
                "org.freedesktop.UDisks", "/org/freedesktop/UDisks")
            self.udisks_interface = dbus.Interface(self.udisks_object,
                                                   "org.freedesktop.UDisks")

            if MediaDB.isloaded():
                self.__connect_to_db()
            else:
                MediaDB.connect("loaded", self.__connect_to_db)
        else:
            self.dbus_udisks = False
            self.logdebug("No UDisks support")
示例#6
0
    def job(self):        
        dirs = self.dirs
        added = []
        db_uris = set(MediaDB.get_all_uris())
        alldirs = [ utils.get_path_from_uri(each_dir) for each_dir in dirs ]
        
        for mdir in alldirs:
            for dirpath, dirs, names in os.walk(mdir):
                [ dirs.remove(each_dir) for each_dir in dirs if each_dir[0] == "." ]
                for each_dir in dirs:
                    full_path_dir  = os.path.join(dirpath, each_dir)
                    if os.path.islink(full_path_dir):
                        alldirs.append(os.path.realpath(full_path_dir))

                valid_files = []    
                for name in names:    
                    full_path_file = os.path.join(dirpath, name)
                    if name[0] != "." and common.file_is_supported(full_path_file):
                        valid_files.append(full_path_file)
                    yield full_path_file    
                        
                valid_files = set(valid_files)    
                for each_file in valid_files:
                    real_file = os.path.realpath(each_file)
                    uri = utils.get_uri_from_path(real_file)
                    if real_file not in db_uris:
                        added.append(uri)
                    elif os.path.getctime(real_file) > MediaDB.get_song(uri).get("#ctime"):
                        added.append(uri)

        added = set(added)
        for uri in added:
            self.add_to_library(uri)
            yield utils.get_path_from_uri(uri)
 def __init__(self):
     
     TreeView.__init__(self, enable_drag_drop=False, enable_multiple_select=True)        
     targets = [("text/deepin-songs", gtk.TARGET_SAME_APP, 1), ("text/uri-list", 0, 2), ("text/plain", 0, 3)]        
     self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
                        targets, gtk.gdk.ACTION_COPY)
     self.pl = None
     self.add_song_cache = []
     sort_key = ["file", "album", "genre", "#track", "artist", "title", "#playcount", "#added"]
     self.sort_reverse = {key : False for key in sort_key }
     self.connect_after("drag-data-received", self.on_drag_data_received)
     self.connect("double-click-item", self.double_click_item_cb)
     self.connect("button-press-event", self.button_press_cb)
     self.connect("delete-select-items", self.try_emit_empty_signal)
     self.connect("motion-notify-item", self.on_motion_notify_item)
     self.connect("press-return", self.on_press_return)
     self.draw_area.connect("leave-notify-event", self.on_leave_notify_event)
     
     self.set_hide_columns([1])
     self.set_expand_column(None)        
     MediaDB.connect("removed", self.__remove_songs)
     MediaDB.connect("simple-changed", self.__songs_changed)
     
     self.song_notify = SongNotify()
     self.notify_timeout_id = None
     self.notify_timeout = 400 # ms
     self.delay_notify_item = None
     self.notify_offset_x = 5
     self.invaild_items = set()
    def __init__(self,
                 default_width=110,
                 gaussian_radious=2,
                 border_radious=1,
                 text_color="#FFFFFF"):
        super(PlayInfo, self).__init__()
        self.set_visible_window(False)

        self.default_height = 18
        self.set_size_request(default_width, self.default_height)
        self.default_width = default_width
        self.artist_label = _("Deepin Music")

        Player.connect("instant-new-song", self.__new_song)
        MediaDB.connect("simple-changed", self.__on_change)
        Player.bin.connect("buffering", self.__on_buffering)
        Player.connect("init-status", self.__on_player_init_status)
        Player.connect("fetch-start", self.on_player_fetch_start)
        Player.connect("fetch-end", self.on_player_fetch_end)

        self.connect("expose-event", self.on_expose_event)
        self.padding_x = 0
        self.gaussian_radious = gaussian_radious
        self.border_radious = border_radious
        self.text_color = text_color
        self.set_size_request(self.default_width, self.default_height)
        self.song = None
示例#9
0
    def __init(self):
        # Loading configure.
        self.loginfo("Loading settings...")
        from config import config
        config.load()

        # Show splash.
        self.__show_splash()

        # Loading theme file.
        self.loginfo("Loading application theme...")
        from widget.skin import app_theme

        # Loading MediaDB.
        self.loginfo("Loading MediaDB...")
        from library import MediaDB
        MediaDB.connect("loaded", self.on_db_loaded)
        MediaDB.load()

        # Loading WebcastDB
        from webcast_library import WebcastDB
        WebcastDB.load()

        # Loading Chinese to Pinyin DB.
        from pinyin import TransforDB
        TransforDB.load()

        # initialize Gui
        self.loginfo("Initialize Gui...")
        from widget.instance import DeepinMusic
        self.app_instance = DeepinMusic()
        self.app_instance.connect("ready", self.on_ready_cb)

        if self.options.StartMinimized:
            self.app_instance.window.iconify()
示例#10
0
    def cleanup_cover(self, song, old_path, path=None):
        if not path:
            path = old_path
        if not os.path.exists(old_path):
            return False

        try:
            pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                old_path, COVER_SAVE_SIZE["x"], COVER_SAVE_SIZE["y"])
        except gobject.GError:
            return False
        else:
            # Check cover is not a big black image
            str_pixbuf = pixbuf.get_pixels()
            if str_pixbuf.count(
                    "\x00") > len(str_pixbuf) / 2 or str_pixbuf.count(
                        "\xff") > len(str_pixbuf) / 2:
                return False
            else:
                if os.path.exists(path): os.unlink(path)
                pixbuf.save(path, "jpeg", {"quality": "85"})
                del pixbuf

                # Change property album to update UI
                MediaDB.set_property(song, {"album": song.get("album")})
                return True
 def __on_tick(self, bin, pos, duration):        
     if self.song:
         if self.song.get_type() == "webcast":
             return
         
     pos /= 1000
     duration /= 1000
     
     if not duration or duration <= 0:
         return
     else:
         if not self.song.get("#duration") or self.song.get("#duration") != duration * 1000:
             if self.song.get_type() != "cue":
                 MediaDB.set_property(self.song, {"#duration": duration * 1000})
                 
     if self.song.get_type() == "cue":            
         duration = self.song.get("#duration") / 1000
         pos = pos - self.song.get("seek", 0)
             
     self.perhap_report(pos, duration)        # todo
     crossfade = self.get_crossfade()
     if crossfade < 0:
         crossfade = 0
     remaining = duration - pos    
     if crossfade:
         if remaining < crossfade:
             if not self.__next_already_called and remaining > 0:
                 self.logdebug("request new song: on tick and play-end not emit")
                 self.emit("play-end")                    
                 self.next()
                 self.__next_already_called = True
 def __on_tag(self, bin, taglist):    
     ''' The playbin found the tag information'''
     if not self.song: return 
     if not self.song.get("title") and self.song.get_type() not in ["cue", "cdda", "webcast", "local"]:
         self.logdebug("tag found %s", taglist)
         IDS = {
             "title": "title",
             "genre": "genre",
             "artist": "artist",
             "album": "album",
             "bitrate": "#bitrate",
             'track-number':"#track"
         }
         mod = {}
         for key in taglist.keys():
             if IDS.has_key(key):
                 if key == "lenght":
                     value = int(taglist[key]) * 1000
                 elif key == "bitrate":    
                     value = int(taglist[key] / 100)
                 elif isinstance(taglist[key], long):
                     value = int(taglist[key])
                 else:    
                     value = fix_charset(taglist[key])
                 mod[IDS[key]] = value
         MediaDB.set_property(self.song, mod)        
示例#13
0
 def __init__(self):
     
     TreeView.__init__(self, enable_drag_drop=False, enable_multiple_select=True)        
     targets = [("text/deepin-songs", gtk.TARGET_SAME_APP, 1), ("text/uri-list", 0, 2), ("text/plain", 0, 3)]        
     self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_DROP,
                        targets, gtk.gdk.ACTION_COPY)
     self.pl = None
     self.add_song_cache = []
     sort_key = ["file", "album", "genre", "#track", "artist", "title", "#playcount", "#added"]
     self.sort_reverse = {key : False for key in sort_key }
     self.connect_after("drag-data-received", self.on_drag_data_received)
     self.connect("double-click-item", self.double_click_item_cb)
     self.connect("button-press-event", self.button_press_cb)
     self.connect("delete-select-items", self.try_emit_empty_signal)
     self.connect("motion-notify-item", self.on_motion_notify_item)
     self.connect("press-return", self.on_press_return)
     self.draw_area.connect("leave-notify-event", self.on_leave_notify_event)
     
     self.set_hide_columns([1])
     self.set_expand_column(None)        
     MediaDB.connect("removed", self.__remove_songs)
     MediaDB.connect("simple-changed", self.__songs_changed)
     
     self.song_notify = SongNotify()
     self.notify_timeout_id = None
     self.notify_timeout = 400 # ms
     self.delay_notify_item = None
     self.notify_offset_x = 5
     self.invaild_items = set()
 def __init__(self):
     gobject.GObject.__init__(self)
     
     # Init.
     self.song = None       
     self.fetch_song = None
     self.__source = None 
     self.__need_load_prefs = True 
     self.__current_stream_seeked = False 
     self.__next_already_called = False
     self.__emit_signal_new_song_id = None
     self.skip_error_song_flag = False
     
     self.stop_after_this_track = False
     
     self.__current_song_reported = False
     
     self.__current_duration = None
     
     self.play_thread_id = 0
     
     MediaDB.connect("simple-changed", self.__on_change_songs)
     
     self.bin = PlayerBin()
     self.bin.connect("eos",   self.__on_eos)
     self.bin.connect("error", self.__on_error)
     self.bin.connect("tags-found", self.__on_tag)
     self.bin.connect("tick", self.__on_tick)
     self.bin.connect("playing-stream", self.__on_playing)
 def update_skipcount(self):        
     '''update skipcount.'''
     # if not played until the end
     if not self.song: return
     if self.song.get_type() != "local": return 
     if not self.__current_song_reported and self.song:
         MediaDB.set_property(self.song, {"#skipcount":self.song.get("#skipcount", 0) + 1})
示例#16
0
 def __init__(self):
     uri = WinFile().run()
     if uri and common.file_is_supported(utils.get_path_from_uri(uri)):
         tags = {"uri": uri}
         try:
             MediaDB.get_or_create_song(tags, "local", read_from_file=True)
         except:
             traceback.print_exc()
示例#17
0
 def remove_songs(self, fully=False):
     if len(self.select_rows) > 0:
         songs = [ self.items[self.select_rows[index]].get_song() for index in range(0, len(self.select_rows))]
         MediaDB.remove(songs)    
         if fully:
             [ utils.move_to_trash(song.get("uri")) for song in songs if song.get_type() != "cue" ]
         self.delete_select_items()            
     return True    
示例#18
0
 def real_remove_item(self, item, fully=False):    
     songs = self.get_item_songs(item)
     MediaDB.remove(songs)
     
     if fully:
         try:
             [ utils.move_to_trash(song.get("uri")) for song in songs if song.get_type() != "cue" ]
         except: pass    
 def remove_songs(self, fully=False):
     if len(self.select_rows) > 0:
         songs = [ self.items[self.select_rows[index]].get_song() for index in range(0, len(self.select_rows))]
         MediaDB.remove(songs)    
         if fully:
             [ utils.move_to_trash(song.get("uri")) for song in songs if song.get_type() != "cue" ]
         self.delete_select_items()            
     return True    
 def real_remove_item(self, item, fully=False):    
     songs = self.get_item_songs(item)
     MediaDB.remove(songs)
     
     if fully:
         try:
             [ utils.move_to_trash(song.get("uri")) for song in songs if song.get_type() != "cue" ]
         except: pass    
示例#21
0
 def job(self):
     songs = MediaDB.get_songs("local")
     total = len(songs)
     i = 0
     for song in songs:
         i += 1
         if not song.exists():
             MediaDB.remove(song)
         yield "Check deleted files %d/%s" % (i,total), float(i)/float(total), False
 def remove_cover(self, song, emit=False):
     image_path = self.get_cover_path(song)
     if os.path.exists(image_path):    
         try:
             os.unlink(image_path)
         except:    
             pass
     if emit:    
         MediaDB.set_property(song, {"album" : song.get("album")})
示例#23
0
 def perhap_report(self, pos=None, duration=None):
     '''report song'''
     if not duration:
         duration = self.get_length()
     if not pos:    
         pos = self.get_position()
     if self.song and not self.__current_stream_seeked and not self.__next_already_called and not self.__current_song_reported and duration > 10 and pos and pos >= min(duration / 2, 240 * 1000):    
         MediaDB.set_property(self.song, {"#playcount": self.song.get("#playcount", 0) + 1})
         MediaDB.set_property(self.song, {"#lastplayed":time()})
         self.__current_song_reported = True
示例#24
0
 def job(self):
     songs = MediaDB.get_songs("local")
     total = len(songs)
     i = 0
     for song in songs:
         i += 1
         if not song.exists():
             MediaDB.remove(song)
         yield "Check deleted files %d/%s" % (
             i, total), float(i) / float(total), False
示例#25
0
 def remove_cover(self, song, emit=False):
     image_path = self.get_cover_path(song)
     if os.path.exists(image_path):
         try:
             os.unlink(image_path)
         except:
             pass
     if emit:
         Dispatcher.emit("album-changed", song)
         MediaDB.set_property(song, {"album": song.get("album")})
示例#26
0
 def __idle_quit(self, *args):    
     self.loginfo("Exiting...")
     Player.stop()
     self.mmkeys.release()
     self.playlist_ui.save_to_library()
     MediaDB.save()
     config.write()
     global_hotkeys.stop()
     self.window.destroy()        
     gtk.main_quit()
     self.loginfo("Exit successful.")
示例#27
0
 def save_to_library(self):    
     if self.search_flag:
         self.reset_search_entry()
               
     MediaDB.full_erase_playlists()
     for item in self.category_list.get_items():
         if item.udi is not None:
             continue
         songs = item.get_songs()
         name = item.get_title()
         MediaDB.create_playlist("local", name, songs)
示例#28
0
    def save_to_library(self):
        if self.search_flag:
            self.reset_search_entry()

        MediaDB.full_erase_playlists()
        for item in self.category_list.get_items():
            if item.udi is not None:
                continue
            songs = item.get_songs()
            name = item.get_title()
            MediaDB.create_playlist("local", name, songs)
示例#29
0
    def job(self):
        '''job'''
        dirs = self.dirs
        added = []
        db_uris = set(MediaDB.get_all_uris())
        alldirs = [utils.get_path_from_uri(each_dir) for each_dir in dirs]

        for mdir in alldirs:
            for dirpath, dirs, names in os.walk(mdir):
                [
                    dirs.remove(each_dir) for each_dir in dirs
                    if each_dir[0] == "."
                ]
                for each_dir in dirs:
                    full_path_dir = os.path.join(dirpath, each_dir)
                    if os.path.islink(full_path_dir):
                        alldirs.append(os.path.realpath(full_path_dir))

                valid_files = []
                for name in names:
                    full_path_file = os.path.join(dirpath, name)
                    if name[0] != "." and common.file_is_supported(
                            full_path_file):
                        valid_files.append(full_path_file)
                    yield full_path_file

                valid_files = set(valid_files)
                for each_file in valid_files:
                    real_file = os.path.realpath(each_file)
                    uri = utils.get_uri_from_path(real_file)
                    if real_file not in db_uris:
                        added.append(uri)
                    elif os.path.getctime(real_file) > MediaDB.get_song(
                            uri).get("#ctime"):
                        added.append(uri)

        added = set(added)
        # for uri in added:
        # self.__get_or_create_song(uri)
        # end = time.time()
        # if (end - start) * 1000 > 1000:
        #     self.callback(self.add_song_cache, self.pos, self.sort)
        #     self.pos += len(self.add_song_cache)
        #     del self.add_song_cache[:]
        #     start = time.time()
        # else:
        #     end = time.time()

        # yield utils.get_path_from_uri(uri)

        # if self.add_song_cache:
        if added:
            gobject.idle_add(self.callback, added, self.pos, self.sort)
示例#30
0
 def get_length(self):
     '''get lenght'''
     if self.song is not None:
         duration = self.bin.xfade_get_duration()
         if duration != -1:
             # if current song_dict not have '#duration' and set it
             if not self.song.get("#duration"):
                 MediaDB.set_property(self.song, {"#duration": duration * 1000})
             return duration    
         elif self.song.get("#duration"):
             return self.song.get("#duration") / 1000
     return 0    
示例#31
0
    def __idle_quit(self, *args):
        self.loginfo("Exiting...")
        Player.stop()
        self.mmkeys.release()
        Dispatcher.emit("being-quit")
        playlist_ui.save_to_library()
        MediaDB.save()
        WebcastDB.save()
        config.write()
        global_hotkeys.stop_bind()

        self.app_destroy()
        gtk.main_quit()
        self.loginfo("Exit successful.")
示例#32
0
 def move_to_trash(self):
     flag = False
     if len(self.select_rows) > 0:
         songs = [ self.items[self.select_rows[index]].get_song() for index in range(0, len(self.select_rows))]
         if self.highlight_item and self.highlight_item.get_song() in songs:
             Player.stop()
             self.highlight_item = None
             flag = True
         MediaDB.remove(songs)    
         [ utils.move_to_trash(song.get("uri")) for song in songs if song.get_type() != "cue"]
         self.delete_select_items()            
         if flag:
             Player.next()
     return True    
示例#33
0
 def job(self):
     songs = MediaDB.get_songs_by_type("local")
     total = len(songs)
     i = 0
     for song in songs:
         i += 1
         if not song.exists():
             MediaDB.remove(song)
         else:
             try: MediaDB.reload_song_from_file(song)
             except:
                 traceback.print_exc()
                 
         yield "%s %d/%s" % (_("Reload database"),i,total)
示例#34
0
    def __idle_quit(self, *args):    
        self.loginfo("Exiting...")
        Player.stop()
        self.mmkeys.release()
        Dispatcher.emit("being-quit")
        playlist_ui.save_to_library()
        MediaDB.save()
        WebcastDB.save()
        config.write()
        global_hotkeys.stop_bind()

        self.app_destroy()
        gtk.main_quit()
        self.loginfo("Exit successful.")
 def move_to_trash(self):
     flag = False
     if len(self.select_rows) > 0:
         songs = [ self.items[self.select_rows[index]].get_song() for index in range(0, len(self.select_rows))]
         if self.highlight_item and self.highlight_item.get_song() in songs:
             Player.stop()
             self.highlight_item = None
             flag = True
         MediaDB.remove(songs)    
         [ utils.move_to_trash(song.get("uri")) for song in songs if song.get_type() != "cue"]
         self.delete_select_items()            
         if flag:
             Player.next()
     return True    
示例#36
0
    def __init__(self, songs, init_index=0):
        super(SongEditor, self).__init__(_("Properties"),
                                         500,
                                         400,
                                         mask_type=DIALOG_MASK_TAB_PAGE)
        self.set_position(gtk.WIN_POS_CENTER)

        close_button = Button(_("Close"))
        close_button.connect("clicked", self.click_close_button)

        previous_button = Button(_("Previous"))
        previous_button.connect("clicked",
                                lambda w: self.update_previous_song())
        next_button = Button(_("Next"))
        next_button.connect("clicked", lambda w: self.update_next_song())

        self.record_label = Label("0/0")

        action_box = gtk.HBox(spacing=5)
        action_box.pack_start(previous_button, False, False)
        action_box.pack_start(self.record_label, False, False)
        action_box.pack_start(next_button, False, False)

        MediaDB.connect("simple-changed", self.db_simple_changed)

        # action_box.
        if len(songs) <= 1:
            action_box.set_no_show_all(True)
        else:
            self.record_label.set_text("%d/%d" % (init_index + 1, len(songs)))

        # tabs
        self.song_info = SongInfo(songs[init_index])
        self.info_setting = InfoSetting(songs[init_index])
        self.cover_setting = CoverSetting(songs[init_index])

        self.tab_box = TabBox()
        self.tab_box.add_items([(_("Track Infomation"), self.song_info),
                                (_("Tag Settings"), self.info_setting),
                                (_("Cover Settings"), self.cover_setting)])

        # DialogBox code, simple, ah? :)
        self.left_button_box.set_buttons([action_box])
        self.right_button_box.set_buttons([close_button])
        self.body_box.pack_start(self.tab_box, True, True)

        # Constants.
        self.current_index = init_index
        self.songs = songs
示例#37
0
    def job(self):
        songs = MediaDB.get_songs_by_type("local")
        total = len(songs)
        i = 0
        for song in songs:
            i += 1
            if not song.exists():
                MediaDB.remove(song)
            else:
                try:
                    MediaDB.reload_song_from_file(song)
                except:
                    traceback.print_exc()

            yield "%s %d/%s" % (_("Reload database"), i, total)
示例#38
0
    def job(self):        
        '''job'''
        dirs = self.dirs
        added = []
        db_uris = set(MediaDB.get_all_uris())
        alldirs = [ utils.get_path_from_uri(each_dir) for each_dir in dirs ]
        
        for mdir in alldirs:
            for dirpath, dirs, names in os.walk(mdir):
                [ dirs.remove(each_dir) for each_dir in dirs if each_dir[0] == "." ]
                for each_dir in dirs:
                    full_path_dir  = os.path.join(dirpath, each_dir)
                    if os.path.islink(full_path_dir):
                        alldirs.append(os.path.realpath(full_path_dir))

                valid_files = []    
                for name in names:    
                    full_path_file = os.path.join(dirpath, name)
                    if name[0] != "." and common.file_is_supported(full_path_file):
                        valid_files.append(full_path_file)
                    yield full_path_file    
                        
                valid_files = set(valid_files)    
                for each_file in valid_files:
                    real_file = os.path.realpath(each_file)
                    uri = utils.get_uri_from_path(real_file)
                    if real_file not in db_uris:
                        added.append(uri)
                    elif os.path.getctime(real_file) > MediaDB.get_song(uri).get("#ctime"):
                        added.append(uri)
        
        added = set(added)
        # for uri in added:
            # self.__get_or_create_song(uri)
            # end = time.time()
            # if (end - start) * 1000 > 1000:
            #     self.callback(self.add_song_cache, self.pos, self.sort)
            #     self.pos += len(self.add_song_cache)
            #     del self.add_song_cache[:]
            #     start = time.time()
            # else:    
            #     end = time.time()
               
            # yield utils.get_path_from_uri(uri)
 
        # if self.add_song_cache:            
        if added:
            gobject.idle_add(self.callback, added, self.pos, self.sort)
示例#39
0
    def load_taginfo(self, uris, pos=None, sort=True):
        start = time.time()
        if pos is None:
            pos = len(self.items)
        for uri in uris:
            songs = MediaDB.get_songs_by_uri(uri)
            if not songs:
                continue
            self.add_song_cache.extend(songs)
            end = time.time()
            if end - start > 0.2:
                self.render_song(self.add_song_cache, pos, sort)
                pos += len(self.add_song_cache)
                del self.add_song_cache[:]
                start = time.time()

        if self.add_song_cache:
            self.render_song(self.add_song_cache, pos, sort)
            del self.add_song_cache[:]

            # save playlists
            try:
                self.category_view.save_to_library()
            except:
                pass
示例#40
0
    def __init__(self):
        super(CoverButton, self).__init__()
        
        self.current_cover_pixbuf = CoverManager.get_default_cover(COVER_SIZE["x"], COVER_SIZE["y"])
        self.cover_side_pixbuf = app_theme.get_pixbuf("cover/side.png").get_pixbuf()
        self.set_size_request(self.cover_side_pixbuf.get_width(), self.cover_side_pixbuf.get_height())

        self.connect("expose-event", self.expose_button_cb)
        MediaDB.connect("simple-changed", self.update_cover)
        self.current_song = None
        self.next_cover_to_download = None
        
        self.condition = threading.Condition()
        self.thread = threading.Thread(target=self.func_thread)
        self.thread.setDaemon(True)
        self.thread.start()
 def get_combo_all_cover(self, key="album"):
     cover_cache_dir = get_cache_dir("cover")
     if not os.path.isdir(cover_cache_dir):
         return None
     
     if len(MediaDB.get_all_uris()) < 4:
         return None
    
     if key == "album":
         if self.album_all_cover != None:
             return self.album_all_cover
         cache_files = [f for f in os.listdir(cover_cache_dir) if "-" in f]        
     elif key == "artist":    
         if self.artist_all_cover != None:
             return self.artist_all_cover
         cache_files = [f for f in os.listdir(cover_cache_dir) if "-" not in f] 
     else:    
         return None
     
     if len(cache_files) < 4:
         return None
     
     random.shuffle(cache_files)
     
     combo_image  = composite_images([os.path.join(cover_cache_dir, f) for f in cache_files[:4]],
                                     84,  84,
                                     get_cache_file("%s_all_cover.png" % key))
     if combo_image:
         if key == "album":
             self.album_all_cover = gtk.gdk.pixbuf_new_from_file(combo_image)
             return self.album_all_cover
         else:
             self.artist_all_cover = gtk.gdk.pixbuf_new_from_file(combo_image)
             return self.artist_all_cover
     return None
示例#42
0
 def get_previous_song(self):
     del self.select_rows[:]
     self.queue_draw()
     self.reset_error_items()
     
     if self.is_empty():
         if config.get("setting", "empty_random") == "true":
             return MediaDB.get_random_song("local")
     else:    
         valid_items = self.get_valid_items()
         if not valid_items: return None
         
         if config.get("setting", "loop_mode") == "random_mode":
             return self.get_random_song()
         
         if self.highlight_item != None:
             if self.highlight_item in valid_items:
                 current_index = valid_items.index(self.highlight_item)
                 prev_index = current_index - 1
                 if prev_index < 0:
                     prev_index = len(valid_items) - 1
                 highlight_item = valid_items[prev_index]    
         else:        
             highlight_item = valid_items[0]
         self.set_highlight(highlight_item)    
         return highlight_item.get_song()
    def __init__(self):
        FetchManager.__init__(self, DBQuery("local"))

        if MediaDB.isloaded():
            self.__on_db_loaded(MediaDB)
        else:
            self.autoconnect(MediaDB, "loaded", self.__on_db_loaded)
示例#44
0
 def load(self):
     '''load configure'''
     if not self.__need_load_prefs:
         return
     
     # get uri
     uri = config.get("player", "uri")
     
     # get seek
     seek = int(config.get("player", "seek"))
     
     # get state 
     state = config.get("player", "state")
     
     # Init player state
     play = False
     self.logdebug("player load %s in state %s at %d", uri, state, seek)
     if config.getboolean("player", "play_on_startup") and state == "playing":
         play = True
         
     # load uri
     if uri:    
         song = MediaDB.get_song(uri)
         if song and song.exists():
             if not config.getboolean("player", "resume_last_progress") or not play:
                 seek = None
             self.set_song(song, play, self.get_crossfade() * 2, seek)
     self.emit("loaded")        
示例#45
0
 def __init__(self):
     Browser.__init__(self, DBQuery(self._type))
     
     if MediaDB.isloaded():
         self.__on_db_loaded(MediaDB)
     else:    
         self.autoconnect(MediaDB, "loaded", self.__on_db_loaded)
示例#46
0
 def get_next_song(self, manual=False):
     del self.select_rows[:]
     self.queue_draw()
     self.reset_error_items()
     
     if self.is_empty():
         if config.getboolean("setting", "empty_random"):
             return MediaDB.get_random_song("local")
     else:    
         if manual:
             if config.get("setting", "loop_mode") != "random_mode":
                 return self.get_manual_song()
             else:
                 return self.get_random_song()
         
         elif config.get("setting", "loop_mode") == "list_mode":
             return self.get_manual_song()
         
         elif config.get("setting", "loop_mode") == "order_mode":            
             return self.get_order_song()
         
         elif config.get("setting", "loop_mode") == "single_mode":
             if self.highlight_item != None:
                 return self.highlight_item.get_song()
             
         elif config.get("setting", "loop_mode") == "random_mode":    
             return self.get_random_song()
    def load_taginfo(self, uris, pos=None, sort=True):
        start = time.time()
        if pos is None:
            pos = len(self.items)
        for uri in uris:    
            songs = MediaDB.get_songs_by_uri(uri)
            if not songs:
                continue
            self.add_song_cache.extend(songs)
            end = time.time()
            if end - start > 0.2:
                self.render_song(self.add_song_cache, pos, sort)
                pos += len(self.add_song_cache)
                del self.add_song_cache[:]
                start = time.time()

        if self.add_song_cache:
            self.render_song(self.add_song_cache, pos, sort)
            del self.add_song_cache[:]
            
            # save playlists
            try:
                self.category_view.save_to_library()
            except:    
                pass
示例#48
0
 def __get_or_create_song(self, uri):
     tags = {"uri": uri}
     try:
         song = MediaDB.get_or_create_song(tags, "local", read_from_file=True)
         self.add_song_cache.append(song)
     except:
         self.logerror("Failed load %s", uri)
 def __init__(self):
     FetchManager.__init__(self, DBQuery("local"))
     
     if MediaDB.isloaded():
         self.__on_db_loaded(MediaDB)
     else:    
         self.autoconnect(MediaDB, "loaded", self.__on_db_loaded)
示例#50
0
    def get_search_songs(self, keyword):
        self.clear()
        all_songs = MediaDB.get_songs_by_type("local")
        result_songs = filter(
            lambda song: keyword.lower().replace(" ", "") in song.get(
                "search", ""), all_songs)

        return result_songs
示例#51
0
 def leading_in_list(self):    
     uri = WindowLoadPlaylist().run()
     try:
         p_name = utils.get_filename(uri)
         pl = MediaDB.create_playlist("local", p_name, [])
         new_item = ListTreeItem(pl)
         self.category_list.add_items([new_item])
         new_item.song_view.async_add_uris(uri)
     except:    
         pass
示例#52
0
 def play_uris(self, uris, pos=None, sort=True):
     # self.get_toplevel().window.set_cursor(None)
     songs = []
     for uri in uris:
         db_songs = MediaDB.get_songs_by_uri(uri)
         if db_songs:
             songs.extend(db_songs)
     if not songs:
         return
     if sort: songs.sort()
     self.add_songs(songs, pos, sort, True)
示例#53
0
    def __songs_changed(self, db, infos):
        indexs = []
        view_songs = self.get_songs()
        for each_song in infos:
            if each_song in view_songs:
                indexs.append(view_songs.index(each_song))

        if indexs:
            for index in indexs:
                item = self.items[index]
                item.update(MediaDB.get_song(item.get_song().get("uri")), True)
示例#54
0
    def job(self):
        dirs = self.dirs
        added = []
        db_uris = set(MediaDB.get_all_uris())
        alldirs = [utils.get_path_from_uri(each_dir) for each_dir in dirs]

        for mdir in alldirs:
            for dirpath, dirs, names in os.walk(mdir):
                [
                    dirs.remove(each_dir) for each_dir in dirs
                    if each_dir[0] == "."
                ]
                for each_dir in dirs:
                    full_path_dir = os.path.join(dirpath, each_dir)
                    if os.path.islink(full_path_dir):
                        alldirs.append(os.path.realpath(full_path_dir))

                valid_files = []
                for name in names:
                    full_path_file = os.path.join(dirpath, name)
                    if name[0] != "." and common.file_is_supported(
                            full_path_file):
                        valid_files.append(full_path_file)
                    yield full_path_file

                valid_files = set(valid_files)
                for each_file in valid_files:
                    real_file = os.path.realpath(each_file)
                    uri = utils.get_uri_from_path(real_file)
                    if real_file not in db_uris:
                        added.append(uri)
                    elif os.path.getctime(real_file) > MediaDB.get_song(
                            uri).get("#ctime"):
                        added.append(uri)

        added = set(added)
        for uri in added:
            self.add_to_library(uri)
            yield utils.get_path_from_uri(uri)
示例#55
0
    def add_file(self, filename=None, play=False):
        if filename is None:
            uri = WinFile().run()
        else:
            uri = utils.get_uri_from_path(filename)

        if uri and common.file_is_supported(utils.get_path_from_uri(uri)):
            try:
                songs = MediaDB.get_songs_by_uri(uri)
            except:
                pass
            else:
                self.add_songs(songs, play=play)
示例#56
0
 def finish_job(self):            
     self.emit("end")
     self.__set_status_icon("success")
     self.set_progress_ratio(1.0)
     try:
         gobject.source_remove(self.__updater_id)
     except: pass
     
     if self.trans_data["to_playlist"]:
         tags = {"uri" : utils.get_uri_from_path(self.output_path)}
         song = MediaDB.get_or_create_song(tags, "local", read_from_file=True)
         if song:
             Dispatcher.add_songs([song])
示例#57
0
    def save_taginfo(self, widget):
        tags_modifiable = {}
        new_title = self.title_entry.get_text()
        new_artist = self.artist_entry.get_text()
        new_album = self.album_entry.get_text()
        new_genre = self.genre_entry.get_text()
        new_date = self.date_entry.get_text()

        db_song = MediaDB.get_song(self.song.get("uri"))

        if new_title != db_song.get_str("title"):
            tags_modifiable.update({"title": new_title})
        if new_artist != db_song.get_str("artist"):
            tags_modifiable.update({"artist": new_artist})
        if new_album != db_song.get_str("album"):
            tags_modifiable.update({"album": new_album})
        if new_genre != db_song.get_str("genre"):
            tags_modifiable.update({"genre": new_genre})
        if new_date != db_song.get_str("date"):
            tags_modifiable.update({"date": new_date})

        if tags_modifiable:
            MediaDB.set_property(db_song, tags_modifiable, write_to_file=True)
示例#58
0
    def load_taginfo(self, uris, pos=None, sort=True):
        start = time.time()
        if pos is None:
            pos = len(self.items)
        for uri in uris:    
            songs = MediaDB.get_songs_by_uri(uri)
            if not songs:
                continue
            self.add_song_cache.extend(songs)
            end = time.time()
            if end - start > 0.2:
                self.render_song(self.add_song_cache, pos, sort)
                pos += len(self.add_song_cache)
                del self.add_song_cache[:]
                start = time.time()

        if self.add_song_cache:
            self.render_song(self.add_song_cache, pos, sort)
            del self.add_song_cache[:]
示例#59
0
    def get_combo_all_cover(self, key="album"):
        cover_cache_dir = get_cache_dir("cover")
        if not os.path.isdir(cover_cache_dir):
            return None

        if len(MediaDB.get_all_uris()) < 4:
            return None

        if key == "album":
            if self.album_all_cover != None:
                return self.album_all_cover
            cache_files = [f for f in os.listdir(cover_cache_dir) if "-" in f]
        elif key == "artist":
            if self.artist_all_cover != None:
                return self.artist_all_cover
            cache_files = [
                f for f in os.listdir(cover_cache_dir) if "-" not in f
            ]
        else:
            return None

        if len(cache_files) < 4:
            return None

        random.shuffle(cache_files)

        combo_image = composite_images(
            [os.path.join(cover_cache_dir, f) for f in cache_files[:4]], 84,
            84, get_cache_file("%s_all_cover.png" % key))
        if combo_image:
            if key == "album":
                self.album_all_cover = gtk.gdk.pixbuf_new_from_file(
                    combo_image)
                return self.album_all_cover
            else:
                self.artist_all_cover = gtk.gdk.pixbuf_new_from_file(
                    combo_image)
                return self.artist_all_cover
        return None
示例#60
0
 def restore_status(self):        
     uri = config.get("player", "uri")
     seek = int(config.get("player", "seek"))
     state = config.get("player", "state")
     play = False
     
     if config.getboolean("player", "play_on_startup") and state == "playing":
         play = True
         
     if uri and self.current_item:    
         song = MediaDB.get_song(uri)
         if song.get_type() == "cue":
             seek = seek + song.get("seek", 0)
             
         if song and song.exists():
             if not config.getboolean("player", "resume_last_progress") or not play:
                 if song.get_type() == "cue":
                     seek = song.get("seek", 0)
                 else:    
                     seek = None
                     
             self.current_item.song_view.play_song(song, play, seek)