def on_drag_data_received(self, widget, context, x, y, selection, info, timestamp): root_y = widget.allocation.y + y try: pos = self.get_coordinate_row(root_y) except: pos = None if pos == None: pos = len(self.items) if selection.target in [ "text/uri-list", "text/plain", "text/deepin-songs" ]: if selection.target == "text/deepin-songs" and selection.data: self.add_uris(selection.data.splitlines(), pos, False) elif selection.target == "text/uri-list": selected_uris = selection.get_uris() if len(selected_uris) == 1 and os.path.isdir( utils.get_path_from_uri(selected_uris[0])): self.recursion_add_dir( utils.get_path_from_uri(selected_uris[0])) else: utils.async_parse_uris(selection.get_uris(), True, False, self.add_uris, pos) elif selection.target == "text/plain": raw_path = selection.data path = eval("u" + repr(raw_path).replace("\\\\", "\\")) utils.async_get_uris_from_plain_text(path, self.add_uris, pos)
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 get_path(self): try: if self.get_type() == "cue": return utils.get_path_from_uri(self.get("real_uri")) elif self.get_type() == "local": return utils.get_path_from_uri(self.get("uri")) elif self.get_type() == "cdda": uri = self.get("uri") return utils.unquote(uri[uri.find("#") + 1:]) else: return utils.unquote(self.get("uri")) except: return ""
def get_songs_by_uri(self, uri): if not uri: return songs = [] uri_scheme = utils.get_scheme(uri) if uri_scheme == "file": path = utils.get_path_from_uri(uri) prefix = os.path.splitext(path)[0] cue_file = "%s.%s" % (prefix, "cue") if os.path.exists(cue_file): try: cuesheet = read_cuesheet(path, cue_file) except CueException, e: print e song = self.get_or_create_song({"uri": uri}, "local", read_from_file=True) if song: return [song] else: return [] else: for tag in cuesheet.get_tags(): s = self.get_or_create_song(tag, "cue", read_from_file=False) songs.append(s) return songs song = self.get_or_create_song({"uri": uri}, "local", read_from_file=True) if song: return [song] else: return []
def get_songs_by_uri(self, uri): if not uri: return songs = [] uri_scheme = utils.get_scheme(uri) if uri_scheme == "file": path = utils.get_path_from_uri(uri) prefix = os.path.splitext(path)[0] cue_file = "%s.%s" % (prefix, "cue") if os.path.exists(cue_file): try: cuesheet = read_cuesheet(path, cue_file) except CueException, e: print e song = self.get_or_create_song({"uri":uri}, "local", read_from_file=True) if song: return [song] else: return [] else: for tag in cuesheet.get_tags(): s = self.get_or_create_song(tag, "cue", read_from_file=False) songs.append(s) return songs song = self.get_or_create_song({"uri":uri}, "local", read_from_file=True) if song: return [ song ] else: return []
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()
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()
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()
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)
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 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)
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)): tags = {"uri": uri} try: song = MediaDB.get_or_create_song(tags, "local", read_from_file=True) except: pass else: self.add_songs(song, play=play)
def on_drag_data_received(self, widget, context, x, y, selection, info, timestamp): root_y = widget.allocation.y + y try: pos = self.get_coordinate_row(root_y) except: pos = None if pos == None: pos = len(self.items) if selection.target in ["text/uri-list", "text/plain", "text/deepin-songs"]: if selection.target == "text/deepin-songs" and selection.data: self.add_uris(selection.data.splitlines(), pos, False) elif selection.target == "text/uri-list": selected_uris = selection.get_uris() if len(selected_uris) == 1 and os.path.isdir(utils.get_path_from_uri(selected_uris[0])): self.recursion_add_dir(utils.get_path_from_uri(selected_uris[0])) else: utils.async_parse_uris(selection.get_uris(), True, False, self.add_uris, pos) elif selection.target == "text/plain": raw_path = selection.data path = eval("u" + repr(raw_path).replace("\\\\", "\\")) utils.async_get_uris_from_plain_text(path, self.add_uris, pos)
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)
def save_all_list(self): uri = WinDir().run() if uri: try: save_name_dict = {} dir_name = utils.get_path_from_uri(uri) for item in self.category_list.get_items(): item_name = item.get_title() save_name_dict[item_name] = save_name_dict.get(item_name, -1) + 1 if save_name_dict.get(item_name) > 0: filename = "%s%d.%s" % (os.path.join(dir_name, item_name), save_name_dict.get(item_name), "m3u") else: filename = "%s.%s" % (os.path.join(dir_name, item_name), "m3u") utils.export_playlist(item.get_songs(), filename, "m3u") except: pass
def get_path(self): try: return utils.get_path_from_uri(self.get("uri")) except: return ""