def __init__(self): App.__init__(self) self.appdir = os.path.abspath(os.path.dirname(__file__)) ApplicationInfo.single().last_run = datetime.now() session.commit() self.kv_files = [os.path.join(self.appdir,'views',f) for f in ['global.kv', 'player.kv', 'rightpane.kv', 'playlist.kv', 'mediaart.kv', 'loading.kv']] self.root_kv_file = os.path.join(self.appdir,'views','root.kv')
def scan(): _proceed = 0 _found = 0 _errors = 0 _max_errors = 10 _total = Track.query.count() for track in Track.query.order_by(Track.code): _proceed+= 1 media_dir = get_media_dir(track.mediano) splited_code = track.code.split('-') if len(splited_code) == 2: db_code, db_subcode = splited_code else: db_code, db_subcode = splited_code[0], '1' db_code, db_subcode = int(db_code), int(db_subcode) # start searching for the directory which contains the music files for d in os.listdir(media_dir): fullpath = os.path.join(media_dir,d) if os.path.isdir(fullpath): m = re.match('^(?P<code>\d{1,4})\s?-', d) if not m: continue else: if db_code != int(m.groupdict()['code']): continue #Directory found, searching for files: for f in os.listdir(fullpath): filename = os.path.join(fullpath,f) if os.path.isfile(filename): m = re.match('^\s?(?P<code>\d{1,4})\s*[-_\.]*\s*(?P<subcode>\d{1,4})?', f) if not m: continue else: code , subcode = int(m.groupdict()['code']), int(1 if not m.groupdict()['subcode'] else m.groupdict()['subcode']) if code == db_code and subcode == db_subcode: # Track found exactly new_filename = os.path.abspath(os.path.join(fullpath,f)) if track.filename != new_filename: track.filename = os.path.relpath(new_filename,args.path) session.commit() _found += 1 else: pass persent = _proceed * 100 / _total v = _proceed * 20 / _total print('Progress(%s%% == %s/%s errors: %s): %s'% (persent, _found,_proceed,_errors,v * '#'))
def main(): if args.inputfile: file = open(args.inputfile) else: file = sys.stdin try: for _id, title, realname, tags in tsv.read(file): print(_id, title, realname, tags) artist = Lyricist.query.filter(Lyricist.title == title.strip()).first() artist.realname = realname artist.tags = ",".join(tags) session.commit() finally: if file != sys.stdin: file.close() return 0