mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2025-12-14 08:06:23 +08:00
Add a new feature
- Add support for specifying the songs of which only the `beyond` chart should be served #60
This commit is contained in:
@@ -27,6 +27,7 @@ class Constant:
|
||||
|
||||
WORLD_MAP_FOLDER_PATH = './database/map/'
|
||||
SONG_FILE_FOLDER_PATH = './database/songs/'
|
||||
SONGLIST_FILE_PATH = './database/songs/songlist'
|
||||
SQLITE_DATABASE_PATH = './database/arcaea_database.db'
|
||||
|
||||
DOWNLOAD_TIMES_LIMIT = Config.DOWNLOAD_TIMES_LIMIT
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from functools import lru_cache
|
||||
from json import loads
|
||||
from time import time
|
||||
|
||||
from .constant import Constant
|
||||
@@ -25,6 +26,22 @@ def initialize_songfile():
|
||||
del x
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_only_3_song_ids():
|
||||
'''初始化只能下载byd相关的歌曲id'''
|
||||
if not os.path.isfile(Constant.SONGLIST_FILE_PATH):
|
||||
return []
|
||||
only_3_song_ids = []
|
||||
data = []
|
||||
with open(Constant.SONGLIST_FILE_PATH, 'r', encoding='utf-8') as f:
|
||||
data = loads(f.read())['songs']
|
||||
for x in data:
|
||||
if 'remote_dl' not in x or 'remote_dl' in x and not x['remote_dl']:
|
||||
if any(i['ratingClass'] == 3 for i in x['difficulties']):
|
||||
only_3_song_ids.append(x['id'])
|
||||
return only_3_song_ids
|
||||
|
||||
|
||||
class UserDownload:
|
||||
'''
|
||||
用户下载类\
|
||||
@@ -137,6 +154,8 @@ class DownloadList(UserDownload):
|
||||
re = {}
|
||||
for i in dir_list:
|
||||
if os.path.isfile(os.path.join(Constant.SONG_FILE_FOLDER_PATH, song_id, i)) and i in ['0.aff', '1.aff', '2.aff', '3.aff', 'base.ogg', '3.ogg', 'video.mp4', 'video_audio.ogg']:
|
||||
if song_id in get_only_3_song_ids() and i not in ['3.aff', '3.ogg']:
|
||||
continue
|
||||
x = UserDownload(self.c, self.user)
|
||||
# self.downloads.append(x) # 这实际上没有用
|
||||
x.song_id = song_id
|
||||
|
||||
12
latest version/database/songs/songlist
Normal file
12
latest version/database/songs/songlist
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"songs": [
|
||||
{
|
||||
"id": "dement",
|
||||
"difficulties": [
|
||||
{
|
||||
"ratingClass": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import server.init
|
||||
import web.index
|
||||
import web.login
|
||||
from core.constant import Constant
|
||||
from core.download import UserDownload, initialize_songfile
|
||||
from core.download import UserDownload, initialize_songfile, get_only_3_song_ids
|
||||
from core.error import ArcError
|
||||
from core.sql import Connect
|
||||
from server.func import error_return
|
||||
@@ -135,6 +135,7 @@ def main():
|
||||
app.logger.info("Start to initialize song data...")
|
||||
try:
|
||||
initialize_songfile()
|
||||
get_only_3_song_ids()
|
||||
app.logger.info('Complete!')
|
||||
except:
|
||||
app.logger.warning('Initialization error!')
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import time
|
||||
|
||||
import server.arcscore
|
||||
from core.download import initialize_songfile
|
||||
from core.download import initialize_songfile, get_only_3_song_ids
|
||||
from core.rank import RankList
|
||||
from core.sql import Connect
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
@@ -288,6 +288,8 @@ def update_database():
|
||||
def update_song_hash():
|
||||
# 更新数据库内谱面文件hash值
|
||||
try:
|
||||
get_only_3_song_ids.cache_clear()
|
||||
get_only_3_song_ids()
|
||||
initialize_songfile()
|
||||
flash('数据刷新成功 Success refresh data.')
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user