Пример #1
0
def get_songs_play(ids, full=False):
	ids = list(map(int, ids.split(',')))
	res_files = []
	covers = []
	titles = []
	artists = []
	for id in ids:
		song = Song.query.filter(Song.id == id).first()
		if song is None:
			return jsonify({'status': False})
		fn = get_song_filename(song)
		link = ''
		for key in ['file_flac', 'file']:
			mfn = song.__dict__[key]
			if mfn:
				link = files.get_link(mfn, fn + '.' + get_ext(mfn, ''), 86400)
				break
		res_files.append(link)
		album = Album.query.filter(Album.id == song.album_id).one()
		if len(album.cover_files):
			covers.append(files.get_link(album.cover_files[0], 'cover.jpg'))
		else:
			covers.append('')
		if full:
			titles.append(song.title)
			artists.append(song.artist)
	res = {'files': res_files, 'covers': covers}
	if full:
		res['titles'] = titles
		res['artists'] = artists
	return jsonify({'status': True, 'data': res})
Пример #2
0
def add_file(tmp_path):
    hs = hashlib.sha512()
    with open(tmp_path, 'rb') as f:
        while True:
            t = f.read(131072)
            if t == b'':
                break
            hs.update(t)
    sha512 = hs.digest()
    hexhs = binascii.hexlify(sha512).decode()
    db_lock.acquire()
    file = File.query.filter(File.sha512 == sha512).first()
    if file is None:
        db.session.add(File(sha512=sha512, count=1))
        db.session.commit()
        db_lock.release()
        fo = config.STORAGE_PATH + '/' + hexhs[:2]
        fn = fo + '/' + hexhs[2:]
        if not os.path.exists(fo):
            os.mkdir(fo)
        shutil.copy(tmp_path, fn)
    else:
        file.count += 1
        db.session.commit()
        db_lock.release()
    return hexhs + '.' + get_ext(tmp_path, '')
Пример #3
0
def get_song_link(id):
	id = int(id)
	song = Song.query.filter(Song.id == id).first()
	if song is None:
		return jsonify({'status': False})
	fn = get_song_filename(song)
	data = {}
	for key in ['file', 'file_flac']:
		mfn = song.__dict__[key]
		data[key] = files.get_link(mfn, fn + '.' + get_ext(mfn, ''), 86400) if mfn else ''
	return jsonify({'status': True, 'data': data})
Пример #4
0
def album_upload_remote():
	url = request.json['url']
	u = urlparse(url)
	if u.scheme not in ['http', 'https']:
		return jsonify({'status': False, 'msg': 'Invalid URL scheme'})
	if '127.0.0.1' in u.netloc:
		return jsonify({'status': False, 'msg': 'URL can\'t be local'})
	fn = u.path[u.path.rfind('/') + 1:] or 'index.html'
	if get_ext(fn) not in config.TRUSTED_EXTENSIONS:
		return jsonify({'status': False, 'msg': 'Invalid extension'})
	nfn = str(int(time.time() * 1000)) + '%06x' % random.randint(0, 2 ** 24 - 1) + purify_filename(fn)
	fp = config.TEMP_PATH.rstrip('\\').rstrip('/') + '/upload/' + nfn
	add_file_task({'type': 'new_album_remote', 'path': url, 'filename': fn, 'npath': fp})
	return jsonify({'status': True, 'msg': 'Added to queue'})
Пример #5
0
def album_upload():
	if 'file' not in request.files:
		return jsonify({'status': False, 'msg': 'File not found'})
	file = request.files['file']
	if file.filename == '':
		return jsonify({'status': False, 'msg': 'Filename cannot be empty'})
	if get_ext(file.filename) not in config.TRUSTED_EXTENSIONS:
		return jsonify({'status': False, 'msg': 'Invalid extension'})
	ofn = file.filename
	fn = str(int(time.time() * 1000)) + '%06x' % random.randint(0, 2 ** 24 - 1) + purify_filename(ofn)
	fp = config.TEMP_PATH.rstrip('\\').rstrip('/') + '/upload/' + fn
	file.save(fp)
	add_file_task({'type': 'new_album', 'path': fp, 'filename': ofn})
	return jsonify({'status': True, 'msg': 'Added to queue'})
Пример #6
0
def album_upload_files(id, tp):
	id = int(id)
	album = Album.query.filter(Album.id == id).first()
	if album is None:
		return jsonify({'status': False, 'msg': 'Invalid album id'})
	if tp not in ['scan', 'log', 'other', 'cover']:
		return jsonify({'status': False, 'msg': 'Upload type error'})
	if 'file' not in request.files:
		return jsonify({'status': False, 'msg': 'File not found'})
	file = request.files['file']
	if file.filename == '':
		return jsonify({'status': False, 'msg': 'Filename cannot be empty'})
	if get_ext(file.filename) not in config.TRUSTED_EXTENSIONS:
		return jsonify({'status': False, 'msg': 'Invalid extension'})
	ofn = file.filename
	fn = str(int(time.time() * 1000)) + '%06x' % random.randint(0, 2 ** 24 - 1) + purify_filename(ofn)
	fp = config.TEMP_PATH.rstrip('\\').rstrip('/') + '/upload/' + fn
	file.save(fp)
	add_file_task({'type': 'album_' + tp, 'album_id': id, 'path': fp, 'filename': ofn})
	return jsonify({'status': True, 'msg': 'Added to queue'})
Пример #7
0
def get_hash_by_link(link):
    s = link.split('?')[0].split('/')
    return s[2] + '.' + get_ext(s[3])