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): 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 choose_file_and_convert(self): filename = WinFile(False).run() if filename and common.file_is_supported(filename): tags = {"uri" : utils.get_uri_from_path(filename)} s = Song() s.init_from_dict(tags) s.read_from_file() AttributesUI([s]).show_window()
def choose_file_and_convert(self): filename = WinFile(False).run() if filename and common.file_is_supported(filename): tags = {"uri": utils.get_uri_from_path(filename)} s = Song() s.init_from_dict(tags) s.set_type("local") s.read_from_file() AttributesUI([s]).show_window()
def read_from_file(self): ''' Read song infomation for file. ''' if self.get_scheme() == "file" and not self.exists(): ret = False if self.get_scheme() == "file" and common.file_is_supported(self.get_path()): ret = self.__read_from_local_file() else: ret = self.__read_from_remote_file() return ret
def parse_uris(uris, follow_folder=True, follow_playlist=True, callback=None, *args_cb, **kwargs_cb): ''' Receive a list of uris ,expand it and check if exist. if directory recursive add all uri in directory if playlist read all uri in playlist return all supported file found. ''' if not uris: return [] valid_uris = [] for uri in uris: #check file exists only is file is local to speed parsing of shared/remote file if not uri: continue if isinstance(uri, unicode): uri = uri.encode("utf-8") uri = unquote(uri) if uri and uri.strip() != "" and exists(uri): ext = get_ext(uri) try: mime_type = get_mime_type(uri) except: logger.logexception("falied to read file info from %s", uri) continue is_pls = False is_m3u = False is_xspf = False try: is_pls = (mime_type == "audio/x-scpls") is_m3u = (mime_type == "audio/x-mpegurl" or mime_type == "audio/mpegurl" or mime_type == "audio/m3u") is_xspf = (mime_type == "application/xspf+xml") except: pass is_pls = is_pls or (ext == ".pls") is_m3u = is_m3u or (ext == ".m3u") is_xspf = is_xspf or (ext == ".xspf") if is_local_dir(uri) and follow_folder: valid_uris.extend(parse_uris(parse_folder(uri), follow_folder, follow_playlist)) elif follow_playlist and is_pls: valid_uris.extend(parse_uris(get_uris_from_pls(uri), follow_folder, follow_playlist)) elif follow_playlist and is_m3u: valid_uris.extend(parse_uris(get_uris_from_m3u(uri), follow_folder, follow_playlist)) elif follow_playlist and is_xspf: valid_uris.extend(parse_uris(get_uris_from_xspf(uri), follow_folder, follow_playlist)) elif get_scheme(uri) != "file" or common.file_is_supported(get_path_from_uri(uri)): valid_uris.append(uri) logger.loginfo("parse uris found %s uris", len(valid_uris)) if callback: def launch_callback(callback, uris, args, kwargs): callback(uris, *args, **kwargs) gobject.idle_add(launch_callback, callback, list(valid_uris), args_cb, kwargs_cb) else: return valid_uris
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 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 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 parse_uris(uris, follow_folder=True, follow_playlist=True, callback=None, *args_cb, **kwargs_cb): ''' Receive a list of uris ,expand it and check if exist. if directory recursive add all uri in directory if playlist read all uri in playlist return all supported file found. ''' if not uris: return [] valid_uris = [] for uri in uris: #check file exists only is file is local to speed parsing of shared/remote file if not uri: continue if isinstance(uri, unicode): uri = uri.encode("utf-8") uri = unquote(uri) if uri and uri.strip() != "" and exists(uri): ext = get_ext(uri) try: mime_type = get_mime_type(uri) except: logger.logexception("falied to read file info from %s", uri) continue is_pls = False is_m3u = False is_xspf = False try: is_pls = (mime_type == "audio/x-scpls") is_m3u = (mime_type == "audio/x-mpegurl" or mime_type == "audio/mpegurl" or mime_type == "audio/m3u") is_xspf = (mime_type == "application/xspf+xml") except: pass is_pls = is_pls or (ext == ".pls") is_m3u = is_m3u or (ext == ".m3u") is_xspf = is_xspf or (ext == ".xspf") if is_local_dir(uri) and follow_folder: valid_uris.extend( parse_uris(parse_folder(uri), follow_folder, follow_playlist)) elif follow_playlist and is_pls: valid_uris.extend( parse_uris(get_uris_from_pls(uri), follow_folder, follow_playlist)) elif follow_playlist and is_m3u: valid_uris.extend( parse_uris(get_uris_from_m3u(uri), follow_folder, follow_playlist)) elif follow_playlist and is_xspf: valid_uris.extend( parse_uris(get_uris_from_xspf(uri), follow_folder, follow_playlist)) elif get_scheme(uri) != "file" or common.file_is_supported( get_path_from_uri(uri)): valid_uris.append(uri) logger.loginfo("parse uris found %s uris", len(valid_uris)) if callback: def launch_callback(callback, uris, args, kwargs): callback(uris, *args, **kwargs) gobject.idle_add(launch_callback, callback, list(valid_uris), args_cb, kwargs_cb) else: return valid_uris