feat:新增fastapi-login,数据库表
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3c96772a56
commit
3d73f1ad10
226
api.py
226
api.py
@ -1,11 +1,16 @@
|
||||
import fastapi
|
||||
import os
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from fastapi_login.exceptions import InvalidCredentialsException
|
||||
from datetime import timedelta
|
||||
import requests
|
||||
import uvicorn
|
||||
from fastapi import Depends
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from service.userservice import *
|
||||
from service.rank_data import *
|
||||
from fastapi_login import LoginManager
|
||||
from server.user_server import *
|
||||
from server.rank_data import *
|
||||
from server.music_server import *
|
||||
|
||||
env = os.environ
|
||||
app = FastAPI()
|
||||
@ -19,58 +24,135 @@ app.add_middleware(
|
||||
allow_headers=["*"], # 允许所有请求头
|
||||
)
|
||||
|
||||
SECRET = os.urandom(24).hex()
|
||||
manager = LoginManager(SECRET, token_url='/auth/token', use_cookie=False)
|
||||
|
||||
try:
|
||||
# mysql数据配置
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password, port=mysql_port,
|
||||
charset="utf8", database=mysql_database)
|
||||
# cursor = con.cursor()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("数据库连接失败")
|
||||
|
||||
|
||||
@manager.user_loader()
|
||||
def load_user(username: int):
|
||||
"""
|
||||
获取用户信息
|
||||
:param username:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
with con.cursor() as cursor:
|
||||
cursor.execute("SELECT * FROM User WHERE username = %s", (username,))
|
||||
user = cursor.fetchone()
|
||||
|
||||
if user:
|
||||
user_dict = dict(username=user[1], password=user[3])
|
||||
return user_dict
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
|
||||
# @app.get('/auth/cookie')
|
||||
# def auth(response: Response, user=Depends(manager)):
|
||||
# """
|
||||
# 通过cookie验证用户
|
||||
# :param response:
|
||||
# :param user:
|
||||
# :return:
|
||||
# """
|
||||
# # 查询用户信息
|
||||
# cursor.execute("SELECT * FROM User WHERE email = %s", (user['sub'],))
|
||||
# user = cursor.fetchone()
|
||||
# # 生成token
|
||||
# token = manager.create_access_token(
|
||||
# data=dict(sub=user[2])
|
||||
# )
|
||||
# manager.set_cookie(response, token)
|
||||
# return response
|
||||
|
||||
|
||||
@app.post('/auth/get_token')
|
||||
def get_token(data: OAuth2PasswordRequestForm = Depends()):
|
||||
username = data.username
|
||||
password = md5(data.password)
|
||||
|
||||
user = load_user(username) # we are using the same function to retrieve the user
|
||||
if not user:
|
||||
raise InvalidCredentialsException # you can also use your own HTTPException
|
||||
elif password != user['password']:
|
||||
raise InvalidCredentialsException
|
||||
|
||||
access_token = manager.create_access_token(
|
||||
data=dict(sub=username),
|
||||
expires=timedelta(hours=12)
|
||||
)
|
||||
return {'access_token': access_token, 'token_type': 'bearer'}
|
||||
|
||||
|
||||
# 验证Token
|
||||
@app.get('/token/verify_user')
|
||||
def get_current_user(current_user=Depends(manager.get_current_user)):
|
||||
if current_user:
|
||||
return {"status":200 ,"success": True, "message": "Validated successfully"}
|
||||
else:
|
||||
return {"status":400 ,"success": False, "message": "Invalid token"}
|
||||
|
||||
# @app.get('/protected')
|
||||
# def protected_route(user=Depends(manager)):
|
||||
# return "验证通过"
|
||||
|
||||
|
||||
# 注册
|
||||
@app.post("/register")
|
||||
async def register(username: str = fastapi.Form(..., description="用户名"),
|
||||
password: str = fastapi.Form(..., description="密码")):
|
||||
@app.post("/user/register")
|
||||
async def user_register(
|
||||
username: str = fastapi.Query(..., description="用户名"),
|
||||
password: str = fastapi.Query(..., description="密码"),
|
||||
email: str = fastapi.Query(None, description="邮箱")):
|
||||
"""
|
||||
注册新用户
|
||||
:param username: 用户名
|
||||
:param password: 密码
|
||||
:return: 注册结果
|
||||
注册
|
||||
:param username:
|
||||
:param password:
|
||||
:param email:
|
||||
:return:
|
||||
"""
|
||||
# 读取现有的用户信息
|
||||
existing_users = read_users()
|
||||
|
||||
# 检查用户名是否已存在
|
||||
if username in existing_users:
|
||||
return {"success": False, "message": "用户名已存在"}
|
||||
|
||||
# 添加新用户信息
|
||||
new_user = {"username": username, "password": password}
|
||||
existing_users[username] = new_user
|
||||
|
||||
# 将用户信息保存到CSV文件
|
||||
save_users(existing_users)
|
||||
|
||||
return {"success": True, "message": "注册成功"}
|
||||
create_user(username, password)
|
||||
# 获取Token
|
||||
token_info = get_token(OAuth2PasswordRequestForm(username=username, password=password))
|
||||
return {"success": True, "message": "注册成功", "token": token_info}
|
||||
|
||||
|
||||
# 登陆
|
||||
@app.post("/login")
|
||||
async def login(username: str = fastapi.Form(..., description="用户名"),
|
||||
password: str = fastapi.Form(..., description="密码")):
|
||||
@app.post("/user/login")
|
||||
async def user_login(
|
||||
username: str = fastapi.Query(..., description="用户名"),
|
||||
password: str = fastapi.Query(..., description="密码")):
|
||||
"""
|
||||
用户登录
|
||||
:param username: 用户名
|
||||
:param password: 密码
|
||||
:return: 登录结果
|
||||
登陆并获取Token
|
||||
:param username:
|
||||
:param password:
|
||||
:return:
|
||||
"""
|
||||
# 读取用户信息
|
||||
existing_users = read_users()
|
||||
|
||||
# 验证用户名和密码
|
||||
user = existing_users.get(username)
|
||||
if user and user["password"] == password:
|
||||
return {"success": True, "message": "登录成功"}
|
||||
return {"success": False, "message": "用户名或密码错误"}
|
||||
# 请求auth/token接口获取token
|
||||
token_info = get_token(OAuth2PasswordRequestForm(username=username, password=password))
|
||||
login_info = user_login(username, password)
|
||||
if login_info:
|
||||
return {"success": True, "message": "登陆成功", "token": token_info}
|
||||
else:
|
||||
return {"success": False, "message": "登陆失败"}
|
||||
|
||||
|
||||
# 榜单获取
|
||||
@app.get("/get_rank")
|
||||
async def get_rank(
|
||||
rank_id: str = fastapi.Query(..., description="榜单类型")):
|
||||
rank_id: str = fastapi.Query(..., description="榜单类型"),
|
||||
current_user=Depends(manager.get_current_user)):
|
||||
"""
|
||||
:param rank_id:
|
||||
19723756 云音乐飙升榜
|
||||
@ -82,7 +164,7 @@ async def get_rank(
|
||||
headers = {
|
||||
"Referer": "https://music.163.com/",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
||||
" AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36"
|
||||
" AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36"
|
||||
}
|
||||
url = f"https://music.163.com/api/playlist/detail?id={rank_id}"
|
||||
|
||||
@ -90,57 +172,26 @@ async def get_rank(
|
||||
response = requests.get(url, headers=headers)
|
||||
# 如果请求code为-447 那么继续返回json
|
||||
if response.status_code == -447:
|
||||
return {"message": "请求code为-447传入本地JSON数据", "data": response.json()}
|
||||
return {"message": "response code is -447, local json data", "data": response.json()}
|
||||
else:
|
||||
# 检测是否含有带rank_id的缓存文件
|
||||
cached_data = read_cache(rank_id)
|
||||
if cached_data:
|
||||
return {"message": "本地JSON数据", "data": cached_data}
|
||||
return {"message": "local json data", "data": cached_data}
|
||||
|
||||
|
||||
# 将榜单数据写入缓存文件
|
||||
write_cache(rank_id, response.json())
|
||||
print(response.json())
|
||||
data = response.json()
|
||||
|
||||
return {"message": "请求网易云并缓存本地JSON成功", "data": data}
|
||||
return {"message": "Request Netease Cloud And Local Cache JSON Success", "data": data}
|
||||
|
||||
|
||||
# @app.get("/get_rank")
|
||||
# async def get_rank(rank_id: str = fastapi.Query(..., description="榜单类型")):
|
||||
# """
|
||||
# 获取音乐榜单数据
|
||||
# :param rank_id: 榜单ID
|
||||
# 19723756 云音乐飙升榜
|
||||
# 3779629 云音乐新歌榜
|
||||
# 3778678 云音乐热歌榜
|
||||
# 2884035 云音乐原创榜
|
||||
# :return: 榜单数据
|
||||
# """
|
||||
# # 检查是否有缓存数据
|
||||
# cached_data = read_cache(rank_id)
|
||||
# if cached_data:
|
||||
# return {"message": "success", "data": cached_data}
|
||||
#
|
||||
# headers = {
|
||||
# "Referer": "https://music.163.com/",
|
||||
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
||||
# " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36"
|
||||
# }
|
||||
# # 缓存数据不存在,从网络获取榜单数据
|
||||
# url = f"https://music.163.com/api/playlist/detail?id={rank_id}"
|
||||
# response = requests.get(url, headers=headers)
|
||||
# data = response.json()
|
||||
#
|
||||
# # 将数据写入缓存文件
|
||||
# write_cache(rank_id, data)
|
||||
#
|
||||
# return {"message": "success", "data": data}
|
||||
|
||||
|
||||
# 根据歌曲名称搜索歌曲
|
||||
@app.get("/search_song_by_name")
|
||||
async def search_song_by_name(
|
||||
name: str = fastapi.Query(..., description="歌曲名称")):
|
||||
name: str = fastapi.Query(..., description="歌曲名称"),
|
||||
# current_user=Depends(manager.get_current_user)
|
||||
):
|
||||
payload = {
|
||||
"input": name,
|
||||
"filter": "name",
|
||||
@ -187,9 +238,11 @@ async def search_song_by_name(
|
||||
# 根据歌曲id搜索歌曲
|
||||
@app.get("/search_song_by_id")
|
||||
async def search_song_by_id(
|
||||
id: str = fastapi.Query(..., description="歌曲id")):
|
||||
music_id: str = fastapi.Query(..., description="歌曲id"),
|
||||
# current_user=Depends(manager.get_current_user)
|
||||
):
|
||||
payload = {
|
||||
"input": id,
|
||||
"input": music_id,
|
||||
"filter": "id",
|
||||
"type": "netease", # netease, tencent, kugou, xiami, baidu
|
||||
"page": 1
|
||||
@ -219,13 +272,20 @@ async def search_song_by_id(
|
||||
if response.status_code == 200:
|
||||
# Parse the response JSON data
|
||||
data = response.json()
|
||||
print(data)
|
||||
try:
|
||||
save_search_music(data)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return {"message": "success", "data": data}
|
||||
else:
|
||||
print(f"Failed to get data. Status code: {response.status_code}")
|
||||
return {"message": "failed", "data": []}
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
host = env.get("HOST") if env.get("HOST") is not None else "0.0.0.0"
|
||||
port = int(env.get("PORT")) if env.get("PORT") is not None else 7788
|
||||
port = int(env.get("PORT")) if env.get("PORT") is not None else 7888
|
||||
uvicorn.run(app='api:app', host=host, port=port, reload=True)
|
||||
|
@ -1,4 +0,0 @@
|
||||
username,password
|
||||
user1,password1
|
||||
user2,password2
|
||||
username1,123456
|
|
291
requirements.txt
291
requirements.txt
@ -1,35 +1,306 @@
|
||||
aiofiles==23.1.0
|
||||
aiohttp==3.8.5
|
||||
aiosignal==1.3.1
|
||||
altair==5.0.1
|
||||
annotated-types==0.5.0
|
||||
anyio==3.7.1
|
||||
appdirs==1.4.4
|
||||
async-generator==1.10
|
||||
async-timeout==4.0.2
|
||||
attrs==23.1.0
|
||||
Babel==2.12.1
|
||||
bce-python-sdk==0.8.87
|
||||
bcrypt==4.0.1
|
||||
beautifulsoup4==4.12.2
|
||||
blinker==1.6.2
|
||||
bs4==0.0.1
|
||||
certifi==2023.7.22
|
||||
charset-normalizer==3.2.0
|
||||
click==8.1.6
|
||||
certifi==2023.5.7
|
||||
charset-normalizer==3.1.0
|
||||
click==8.1.3
|
||||
cloudscraper==1.2.71
|
||||
colorama==0.4.6
|
||||
colorlog==6.7.0
|
||||
comtypes==1.2.0
|
||||
contourpy==1.1.0
|
||||
cssselect==1.2.0
|
||||
exceptiongroup==1.1.2
|
||||
cycler==0.11.0
|
||||
databases==0.7.0
|
||||
datasets==2.14.0
|
||||
dill==0.3.4
|
||||
docopt==0.6.2
|
||||
easydict==1.10
|
||||
et-xmlfile==1.1.0
|
||||
exceptiongroup==1.1.1
|
||||
fake-useragent==1.1.3
|
||||
fastapi==0.100.0
|
||||
fastapi-login==1.9.1
|
||||
ffmpy==0.3.1
|
||||
filelock==3.12.2
|
||||
fire==0.5.0
|
||||
Flask==2.3.2
|
||||
Flask-Babel==2.0.0
|
||||
fonttools==4.41.0
|
||||
frozenlist==1.4.0
|
||||
fsspec==2023.6.0
|
||||
future==0.18.3
|
||||
gevent==22.10.2
|
||||
gradio==3.39.0
|
||||
gradio_client==0.3.0
|
||||
greenlet==2.0.2
|
||||
gunicorn==21.2.0
|
||||
h11==0.14.0
|
||||
httpcore==0.17.3
|
||||
httpx==0.24.1
|
||||
huggingface-hub==0.16.4
|
||||
idna==3.4
|
||||
importlib-metadata==6.8.0
|
||||
lxml==4.9.3
|
||||
importlib-resources==6.0.0
|
||||
itsdangerous==2.1.2
|
||||
jieba==0.42.1
|
||||
Jinja2==3.1.2
|
||||
joblib==1.3.1
|
||||
jsonschema==4.18.4
|
||||
jsonschema-specifications==2023.7.1
|
||||
kenlm==0.1
|
||||
kiwisolver==1.4.4
|
||||
libretranslatepy==2.1.1
|
||||
linkify-it-py==2.0.2
|
||||
loguru==0.7.0
|
||||
lxml==4.9.2
|
||||
markdown-it-py==2.2.0
|
||||
MarkupSafe==2.1.3
|
||||
matplotlib==3.7.2
|
||||
mdit-py-plugins==0.3.3
|
||||
mdurl==0.1.2
|
||||
multidict==6.0.4
|
||||
multiprocess==0.70.12.2
|
||||
numpy==1.25.0
|
||||
opencv-python==4.8.0.74
|
||||
openpyxl==3.1.2
|
||||
orjson==3.9.2
|
||||
outcome==1.2.0
|
||||
packaging==23.1
|
||||
paddle2onnx==1.0.5
|
||||
paddlefsl==1.1.0
|
||||
paddlehub==2.3.1
|
||||
paddlenlp==2.5.2
|
||||
pandas==1.3.5
|
||||
parse==1.19.1
|
||||
pydantic==2.1.1
|
||||
pydantic_core==2.4.0
|
||||
passlib==1.7.4
|
||||
pdf2docx==0.5.6
|
||||
pdf2image==1.16.3
|
||||
Pillow==9.5.0
|
||||
pipreqs==0.4.13
|
||||
playsound==1.3.0
|
||||
protobuf==4.23.4
|
||||
pyarrow==12.0.1
|
||||
PyAudio==0.2.13
|
||||
pycorrector==0.5.0
|
||||
pycryptodome==3.18.0
|
||||
pydantic==2.0.3
|
||||
pydantic_core==2.3.0
|
||||
pydub==0.25.1
|
||||
pyee==8.2.2
|
||||
pygame==2.5.0
|
||||
Pygments==2.15.1
|
||||
PyJWT==2.8.0
|
||||
PyMuPDF==1.22.5
|
||||
PyMySQL==1.1.0
|
||||
pyobjc==9.2
|
||||
pyobjc-core==9.2
|
||||
pyobjc-framework-Accounts==9.2
|
||||
pyobjc-framework-AddressBook==9.2
|
||||
pyobjc-framework-AdSupport==9.2
|
||||
pyobjc-framework-AppleScriptKit==9.2
|
||||
pyobjc-framework-AppleScriptObjC==9.2
|
||||
pyobjc-framework-ApplicationServices==9.2
|
||||
pyobjc-framework-AudioVideoBridging==9.2
|
||||
pyobjc-framework-AuthenticationServices==9.2
|
||||
pyobjc-framework-AutomaticAssessmentConfiguration==9.2
|
||||
pyobjc-framework-Automator==9.2
|
||||
pyobjc-framework-AVFoundation==9.2
|
||||
pyobjc-framework-AVKit==9.2
|
||||
pyobjc-framework-BusinessChat==9.2
|
||||
pyobjc-framework-CalendarStore==9.2
|
||||
pyobjc-framework-CFNetwork==9.2
|
||||
pyobjc-framework-CloudKit==9.2
|
||||
pyobjc-framework-Cocoa==9.2
|
||||
pyobjc-framework-Collaboration==9.2
|
||||
pyobjc-framework-ColorSync==9.2
|
||||
pyobjc-framework-Contacts==9.2
|
||||
pyobjc-framework-ContactsUI==9.2
|
||||
pyobjc-framework-CoreAudio==9.2
|
||||
pyobjc-framework-CoreAudioKit==9.2
|
||||
pyobjc-framework-CoreBluetooth==9.2
|
||||
pyobjc-framework-CoreData==9.2
|
||||
pyobjc-framework-CoreHaptics==9.2
|
||||
pyobjc-framework-CoreLocation==9.2
|
||||
pyobjc-framework-CoreMedia==9.2
|
||||
pyobjc-framework-CoreMediaIO==9.2
|
||||
pyobjc-framework-CoreMIDI==9.2
|
||||
pyobjc-framework-CoreML==9.2
|
||||
pyobjc-framework-CoreMotion==9.2
|
||||
pyobjc-framework-CoreServices==9.2
|
||||
pyobjc-framework-CoreSpotlight==9.2
|
||||
pyobjc-framework-CoreText==9.2
|
||||
pyobjc-framework-CoreWLAN==9.2
|
||||
pyobjc-framework-CryptoTokenKit==9.2
|
||||
pyobjc-framework-DeviceCheck==9.2
|
||||
pyobjc-framework-DictionaryServices==9.2
|
||||
pyobjc-framework-DiscRecording==9.2
|
||||
pyobjc-framework-DiscRecordingUI==9.2
|
||||
pyobjc-framework-DiskArbitration==9.2
|
||||
pyobjc-framework-DVDPlayback==9.2
|
||||
pyobjc-framework-EventKit==9.2
|
||||
pyobjc-framework-ExceptionHandling==9.2
|
||||
pyobjc-framework-ExecutionPolicy==9.2
|
||||
pyobjc-framework-ExternalAccessory==9.2
|
||||
pyobjc-framework-FileProvider==9.2
|
||||
pyobjc-framework-FileProviderUI==9.2
|
||||
pyobjc-framework-FinderSync==9.2
|
||||
pyobjc-framework-FSEvents==9.2
|
||||
pyobjc-framework-GameCenter==9.2
|
||||
pyobjc-framework-GameController==9.2
|
||||
pyobjc-framework-GameKit==9.2
|
||||
pyobjc-framework-GameplayKit==9.2
|
||||
pyobjc-framework-ImageCaptureCore==9.2
|
||||
pyobjc-framework-IMServicePlugIn==9.2
|
||||
pyobjc-framework-InputMethodKit==9.2
|
||||
pyobjc-framework-InstallerPlugins==9.2
|
||||
pyobjc-framework-InstantMessage==9.2
|
||||
pyobjc-framework-Intents==9.2
|
||||
pyobjc-framework-IOBluetooth==9.2
|
||||
pyobjc-framework-IOBluetoothUI==9.2
|
||||
pyobjc-framework-IOSurface==9.2
|
||||
pyobjc-framework-iTunesLibrary==9.2
|
||||
pyobjc-framework-LatentSemanticMapping==9.2
|
||||
pyobjc-framework-LaunchServices==9.2
|
||||
pyobjc-framework-libdispatch==9.2
|
||||
pyobjc-framework-libxpc==9.2
|
||||
pyobjc-framework-LinkPresentation==9.2
|
||||
pyobjc-framework-LocalAuthentication==9.2
|
||||
pyobjc-framework-MapKit==9.2
|
||||
pyobjc-framework-MediaAccessibility==9.2
|
||||
pyobjc-framework-MediaLibrary==9.2
|
||||
pyobjc-framework-MediaPlayer==9.2
|
||||
pyobjc-framework-MediaToolbox==9.2
|
||||
pyobjc-framework-Metal==9.2
|
||||
pyobjc-framework-MetalKit==9.2
|
||||
pyobjc-framework-MetalPerformanceShaders==9.2
|
||||
pyobjc-framework-ModelIO==9.2
|
||||
pyobjc-framework-MultipeerConnectivity==9.2
|
||||
pyobjc-framework-NaturalLanguage==9.2
|
||||
pyobjc-framework-NetFS==9.2
|
||||
pyobjc-framework-Network==9.2
|
||||
pyobjc-framework-NetworkExtension==9.2
|
||||
pyobjc-framework-NotificationCenter==9.2
|
||||
pyobjc-framework-OpenDirectory==9.2
|
||||
pyobjc-framework-OSAKit==9.2
|
||||
pyobjc-framework-OSLog==9.2
|
||||
pyobjc-framework-PencilKit==9.2
|
||||
pyobjc-framework-Photos==9.2
|
||||
pyobjc-framework-PhotosUI==9.2
|
||||
pyobjc-framework-PreferencePanes==9.2
|
||||
pyobjc-framework-PushKit==9.2
|
||||
pyobjc-framework-Quartz==9.2
|
||||
pyobjc-framework-QuickLookThumbnailing==9.2
|
||||
pyobjc-framework-SafariServices==9.2
|
||||
pyobjc-framework-SceneKit==9.2
|
||||
pyobjc-framework-ScreenSaver==9.2
|
||||
pyobjc-framework-ScriptingBridge==9.2
|
||||
pyobjc-framework-SearchKit==9.2
|
||||
pyobjc-framework-Security==9.2
|
||||
pyobjc-framework-SecurityFoundation==9.2
|
||||
pyobjc-framework-SecurityInterface==9.2
|
||||
pyobjc-framework-ServiceManagement==9.2
|
||||
pyobjc-framework-Social==9.2
|
||||
pyobjc-framework-SoundAnalysis==9.2
|
||||
pyobjc-framework-Speech==9.2
|
||||
pyobjc-framework-SpriteKit==9.2
|
||||
pyobjc-framework-StoreKit==9.2
|
||||
pyobjc-framework-SyncServices==9.2
|
||||
pyobjc-framework-SystemConfiguration==9.2
|
||||
pyobjc-framework-SystemExtensions==9.2
|
||||
pyobjc-framework-UserNotifications==9.2
|
||||
pyobjc-framework-VideoSubscriberAccount==9.2
|
||||
pyobjc-framework-VideoToolbox==9.2
|
||||
pyobjc-framework-Vision==9.2
|
||||
pyobjc-framework-WebKit==9.2
|
||||
pyparsing==3.0.9
|
||||
PyPDF2==3.0.1
|
||||
pypinyin==0.49.0
|
||||
pyppeteer==1.0.2
|
||||
pyproject==1.3.1
|
||||
PyQt5==5.15.4
|
||||
pyqt5-plugins==5.15.4.2.2
|
||||
PyQt5-Qt5==5.15.2
|
||||
PyQt5-sip==12.12.1
|
||||
pyqt5-tools==5.15.4.3.2
|
||||
pyquery==2.0.0
|
||||
PySide2==5.15.2.1
|
||||
PySocks==1.7.1
|
||||
pytesseract==0.3.10
|
||||
python-dateutil==2.8.2
|
||||
python-docx==0.8.11
|
||||
python-dotenv==1.0.0
|
||||
python-multipart==0.0.6
|
||||
python-pptx==0.6.21
|
||||
pyttsx3==2.90
|
||||
pytz==2023.3
|
||||
PyYAML==6.0.1
|
||||
pyzmq==25.1.0
|
||||
qt5-applications==5.15.2.2.3
|
||||
qt5-tools==5.15.2.1.3
|
||||
rarfile==4.0
|
||||
referencing==0.30.0
|
||||
regex==2023.6.3
|
||||
reportlab==4.0.4
|
||||
requests==2.31.0
|
||||
requests-html==0.10.0
|
||||
requests-toolbelt==1.0.0
|
||||
rich==13.4.2
|
||||
rpds-py==0.9.2
|
||||
safetensors==0.3.1
|
||||
scikit-learn==1.3.0
|
||||
scipy==1.11.1
|
||||
selenium==4.10.0
|
||||
semantic-version==2.10.0
|
||||
sentencepiece==0.1.99
|
||||
seqeval==1.2.2
|
||||
shiboken2==5.15.2.1
|
||||
six==1.16.0
|
||||
sniffio==1.3.0
|
||||
sortedcontainers==2.4.0
|
||||
soupsieve==2.4.1
|
||||
SQLAlchemy==1.4.49
|
||||
starlette==0.27.0
|
||||
termcolor==2.3.0
|
||||
threadpoolctl==3.2.0
|
||||
tokenizers==0.13.3
|
||||
toolz==0.12.0
|
||||
tqdm==4.65.0
|
||||
transformers==4.31.0
|
||||
translate==3.6.1
|
||||
trio==0.21.0
|
||||
trio-websocket==0.10.3
|
||||
typer==0.9.0
|
||||
typing_extensions==4.7.1
|
||||
uc-micro-py==1.0.2
|
||||
urllib3==1.26.16
|
||||
uvicorn==0.20.0
|
||||
uvicorn @ file:///private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_d80hhx7s7h/croot/uvicorn-split_1678090080474/work
|
||||
visualdl==2.4.2
|
||||
w3lib==2.1.1
|
||||
websocket==0.2.1
|
||||
websocket-client==0.57.0
|
||||
websockets==10.4
|
||||
zipp==3.16.2
|
||||
python-multipart==0.0.6
|
||||
Werkzeug==2.3.6
|
||||
wsproto==1.2.0
|
||||
wxPython==4.2.1
|
||||
xlrd==2.0.1
|
||||
XlsxWriter==3.1.2
|
||||
xxhash==3.2.0
|
||||
yarg==0.1.9
|
||||
yarl==1.9.2
|
||||
zipp==3.16.0
|
||||
zope.event==5.0
|
||||
zope.interface==6.0
|
||||
|
146
server/music_server.py
Normal file
146
server/music_server.py
Normal file
@ -0,0 +1,146 @@
|
||||
import pymysql
|
||||
import untils
|
||||
import hashlib
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password, port=mysql_port, charset="utf8",
|
||||
database=mysql_database)
|
||||
|
||||
def save_search_music(music_id_json):
|
||||
music_info_all = music_id_json['data'][0]
|
||||
|
||||
for music_info in music_info_all:
|
||||
try:
|
||||
with con.cursor() as cursor:
|
||||
# Create a new record
|
||||
sql = "INSERT INTO Music(type, link, songid, title, author, lrc, url, pic) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
cursor.execute(sql, (music_info['type'], music_info['link'], music_info['songid'], music_info['title'], music_info['author'],
|
||||
music_info['lrc'], music_info['url'], music_info['pic']))
|
||||
con.commit()
|
||||
return {"message": "success"}
|
||||
except Exception as e:
|
||||
con.rollback()
|
||||
return {"message": "error", "error": str(e)}
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
music_id_json = {
|
||||
"message": "success",
|
||||
"data": {
|
||||
"data": [
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=2007985520",
|
||||
"songid": 2007985520,
|
||||
"title": "我爱你",
|
||||
"author": "刘大拿,刘思达LOFTHESTAR",
|
||||
"lrc": "[00:00.00] 作词 : 卢广仲/刘思达LOFTHESTAR\n[00:00.09] 作曲 : 卢广仲/刘思达LOFTHESTAR\n[00:00.19] 编曲 : 天秤Dav\n[00:00.29] 原唱 : 卢广仲\n[00:00.39]出品:网易飓风\n[00:00.75]OP:添翼创越工作室\n[00:01.26]【此版本为正式授权翻唱作品。未经著作权人许可,不得翻唱、翻录或使用】\n[00:03.18]曾经在我眼前\n[00:03.60]却又消失不见\n[00:05.79]这是今天的第六遍\n[00:11.16]电影里的配乐\n[00:13.74]好像你的双眼\n[00:16.20]我爱你快回到我身边\n[00:22.23]有些感情像是金子但不能拿来抵换\n[00:24.60]是你带我起航却不负责到达彼岸\n[00:27.18]为了追随你我的心换了籍贯\n[00:29.67]但却有太多的不得已让习惯变成遗憾\n[00:32.16]你怎么不说话呢\n[00:33.90]一直沉默\n[00:35.13]要怎么理清瓜葛\n[00:36.42]不甘心占多\n[00:38.13]你陪我看过的风景都还记得\n[00:40.65]在你离开后这一切都变灰色\n[00:42.36]再也猜不到重点\n[00:43.32]你做的一切都像是让我更加痛点\n[00:45.81]又过了一夜\n[00:46.68]惊醒在又一次的梦魇\n[00:48.15]一次次的\n[00:48.48]循环之中\n[00:49.26]看到你模糊的脸\n[00:50.67]觉得这不是惩罚更像奖励多些\n[00:53.55]I dont want be saved now\n[00:55.83]My brain thought is all about u\n[00:58.59]Don't let me down again\n[01:02.25]曾经在我眼前却又消失不见\n[01:07.26]这是今天的第六遍\n[01:12.42]电影里的配乐 好像你的双眼\n[01:17.10]我爱你 快回到我身边\n[01:22.17]我在你之后变想的多\n[01:24.33]有话也不爱说\n[01:25.26]外面再吵闹也一个人听歌\n[01:27.33]歌里唱的你和我\n[01:29.07]它就像旁观者\n[01:30.03]每一句旋律都刺在我心窝\n[01:32.67]找你不是没想过意料中的失落总会让我退缩\n[01:37.62]我也不想再听说你如何又如何只会更折磨\n[01:42.72]总是会在释怀和不舍中不停的切换\n[01:46.14]唯独遗憾给的痛苦从不间断\n[01:48.60]每当我想通回忆又来添乱\n[01:50.94]不在身边的你自动变成我的牵绊\n[01:53.97]这感觉何时能够停止 notyet\n[01:56.34]好像时间又慢了些\n[01:59.43]今天的第六遍\n[02:03.57]曾经在我眼前却又消失不见\n[02:07.92]这是今天的第六遍\n[02:13.02]电影里的配乐 好像你的双眼\n[02:17.79]我爱你 快回到我身边\n[02:23.79]曾经在我眼前却又消失不见\n[02:28.14]这是今天的第六遍\n[02:33.21]电影里的配乐 好像你的双眼\n[02:37.98]我爱你 快回到我身边\n[02:41.97]制作人:李彦泽\n[02:42.36]吉他:张振\n[02:42.75]混音/母带工程师:沙栩帆\n[02:48.42]和声编写&和声:沙栩帆/俞建明\n[02:51.24]统筹企划:蔡梦珏\n[02:52.68]监制:徐思灵/胡圣羽/张泽宥\n[02:53.40]封面设计:武中奇\n[02:53.85]音乐营销:网易飓风\n[02:54.33]出品人:谢奇笛\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=2007985520.mp3",
|
||||
"pic": "http://p1.music.126.net/iy39tO2gJt_DPctRSYt8ag==/109951168160088998.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=205421",
|
||||
"songid": 205421,
|
||||
"title": "P.S.我爱你",
|
||||
"author": "黄丽玲",
|
||||
"lrc": "[00:00.000] 作词 : 邬裕康\n[00:01.000] 作曲 : 刘勇志\n[00:16.440]我想要成为你的眼\n[00:22.140]把最美的风景\n[00:26.500]收进你的心中\n[00:31.710]我想要成为你的手\n[00:38.200]好让我 从现在到以后\n[00:42.640]占有你温柔 一刻不放过\n[00:48.170]恨不得把明天没收\n[00:52.100]让你永远不会变动\n[00:56.720]专注的爱着我\n[01:03.000]我爱你没有保留\n[01:06.710]我爱你就到最后\n[01:10.700]有些人值得等候\n[01:13.420]有些悲伤值得忍受\n[01:18.790]我爱你不是冲动\n[01:23.200]生命尽头反正一场空\n[01:26.700]只要你记得 我们那么爱过\n[01:41.300]\n[01:52.100]我要替你收集笑容\n[01:57.710]怕未来 快乐变得贵重\n[02:03.300]要是少了我 你有多寂寞\n[02:09.420]恨不得把明天没收\n[02:13.110]让你永远不会变动\n[02:17.900]专注的爱着我\n[02:22.490]我爱你没有保留\n[02:26.700]我爱你就到最后\n[02:30.129]有些人值得等候\n[02:33.400]有些悲伤值得忍受\n[02:37.570]我爱你不是冲动\n[02:41.450]生命尽头反正一场空\n[02:45.400]只要你记得 我们那么爱过\n[02:52.100]太阳不会放弃天空\n[02:57.400]哪怕你不再属于我\n[03:01.330]我会在不同的窗口 给你拥抱\n[03:12.110]我爱你没有保留\n[03:16.170]我爱你就到最后\n[03:20.080]有些人值得等候\n[03:23.160]有些悲伤值得忍受\n[03:28.010]我爱你不是冲动\n[03:31.810]生命尽头反正一场空\n[03:36.060]只要你记得 我们那么爱过\n[03:44.490]我忘不掉 你第一次吻我\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=205421.mp3",
|
||||
"pic": "http://p1.music.126.net/Td7zYX0OXWRu0CWP7aw8ow==/109951164163127618.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=504652401",
|
||||
"songid": 504652401,
|
||||
"title": "我爱你 Luv Is Luv",
|
||||
"author": "贺仙人",
|
||||
"lrc": "[00:00.00] 作词 : 贺仙人\n[00:01.00] 作曲 : 贺仙人\n[00:02.00] 编曲 : 王晓夫/St.K4N3/2Majik\n[00:03.00] 录音 : 王晓夫\n[00:04.00] 混音 : 王晓夫\n[00:05.00] 制作 : 王晓夫\n[00:06.00] 吉他 : 徐可\n[00:12.59]你是否属于我这不重要\n[00:20.77]你在我的心里面\n[00:24.36]你存在于\n[00:27.86]我的每个习惯和每次呼吸\n[00:33.13]蔓延在我的血液\n[00:37.25]hey 我孤单的灵魂被你照亮\n[00:45.53]你是最温暖的光\n[00:48.67]oh 你的爱\n[00:52.40]她平静而又深邃让我着迷\n[00:56.79]oh baby I just can’t leave u now\n[01:01.82]我 对你的爱就像河流\n[01:06.00]穿越平原和山丘\n[01:09.27]从不畏艰险 不远万里而向你奔流\n[01:15.35]我的心如此疯狂\n[01:18.55]前所未有的明朗\n[01:21.84]我想这一定是因为我爱你就像…\n[01:36.07]因为我爱你就像…\n[01:50.98]hey 我孤单的灵魂被你照亮\n[01:59.41]你是最温暖的光\n[02:02.47]oh 你的爱\n[02:06.36]她平静而又深邃让我着迷\n[02:10.69]oh baby I just can’t leave u now\n[02:15.68]我 对你的爱就像河流\n[02:19.91]穿越平原和山丘\n[02:23.00]从不畏艰险 不远万里而向你奔流\n[02:29.19]我的心如此疯狂\n[02:32.36]前所未有的明朗\n[02:35.44]我想这一定是因为我爱你就像…\n[02:49.93]因为我爱你就像…\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=504652401.mp3",
|
||||
"pic": "http://p1.music.126.net/h2zkaSqvw3ufLilm2R1sQw==/109951163021924377.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=26601421",
|
||||
"songid": 26601421,
|
||||
"title": "我爱你(live版)",
|
||||
"author": "卢广仲",
|
||||
"lrc": "[00:00.00] 作词 : 卢广仲\n[00:01.00] 作曲 : 卢广仲\n[00:47.82]曾...曾经在我眼前\n[01:26.39]却又消失不见\n[01:33.00]这是今天的第六遍\n[01:43.83]电影里的配乐\n[01:48.58]好像你的双眼\n[01:53.89]我爱你 快回到 我身边\n[02:20.01]\n[02:29.34]好不好 好不好 好不好\n[02:31.89]答案没有什么好不好\n[02:34.15]不知道 不知道 不知道\n[02:37.09]不知道是什么好预兆\n[02:39.27]好不好 好不好 好不好\n[02:42.09]答答答答答答答答答\n[02:44.41]不知道 不知道 不知道\n[02:47.24]不知道是什么好预兆\n[02:49.35]太阳公公出来了\n[02:54.65]他对我呀笑呀笑\n[02:59.77]我爱你 你知不知道\n[03:06.93]曾经在我眼前\n[03:09.59]却又消失不见\n[03:12.09]这是今天的第六遍\n[03:17.25]电影里的配乐\n[03:19.89]好像你的双眼\n[03:22.09]我爱你 快回到 我身边\n[03:35.52]\n[03:38.68]好不好 好不好 好不好\n[03:41.18]答答答答答答答答答\n[03:43.57]不知道 不知道 不知道\n[03:46.39]不知道是什么好预兆\n[03:48.59]太阳公公出来了\n[03:53.54]他对我呀笑呀笑\n[03:58.88]我爱你 你知不知道\n[04:05.78]曾经在我眼前\n[04:08.49]却又消失不见\n[04:11.04]这是今天的第六遍\n[04:16.20]电影里的配乐\n[04:18.88]好像你的双眼\n[04:21.09]我爱你 快回到 我身边\n[04:40.60]\n[05:08.61]太阳公公出来了\n[05:12.85]他对我呀笑呀笑\n[05:18.19]我爱你 你知不知道\n[05:25.57]曾经在我眼前\n[05:28.10]却又消失不见\n[05:30.64]我不要比赛交白卷\n[05:35.81]电影里的配乐\n[05:38.34]好像你的双眼\n[05:40.50]我爱你 快回到\n[05:45.85]我爱你 快回到\n[05:51.05]我爱你 快回到 我身边\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=26601421.mp3",
|
||||
"pic": "http://p1.music.126.net/w-bF0DCMxMcESCBYXJmlDw==/4439827952972968.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=526935815",
|
||||
"songid": 526935815,
|
||||
"title": "อยากรู้...แต่ไม่อยากถาม",
|
||||
"author": "Pop Pongkool",
|
||||
"lrc": "[00:00.00] 作词 : วิวัฒน์ ฉัตรธีรภาพ\n[00:01.00] 作曲 : อพิสิษฎ์ ณ ตะกั่วทุ่ง\n[00:16.88]ได้ชิดเพียงลมหายใจ\n[00:20.23]แค่ได้ใช้เวลาร่วมกัน\n[00:23.62]แค่เพื่อนเท่านั้น\n[00:26.30]แต่มันเกินห้ามใจ\n[00:31.84]ที่ค้างในความรู้สึก\n[00:35.35]ว่าลึกๆเธอคิดยังไง\n[00:38.59]รักเธอเท่าไร\n[00:41.39]แต่ไม่เคยพูดกัน\n[00:45.99]อะไรที่อยู่ในใจก็เก็บเอาไว้\n[00:53.77]มันมีความสุขแค่นี้ก็ดีมากมาย\n[01:01.06]เธอจะมีใจหรือเปล่า\n[01:04.96]เธอเคยมองมาที่ฉันหรือเปล่า\n[01:09.48]ที่เราเป็นอยู่นั้นคืออะไร\n[01:16.28]เธอจะมีใจหรือเป\n[01:19.94]มันคือความจริงที่ฉันอยากรู้ติดอยู่ในใจ\n[01:25.20]แต่ไม่อยากถาม\n[01:28.22]กลัวว่าเธอเปลี่ยนไป\n[01:35.80]ไม่ถามยังดีซะกว่า\n[01:38.86]เพราะฉันรู้ถ้าเราถามกัน\n[01:42.40]กลัวคำๆนั้น อาจทำร้ายหัวใจ\n[01:49.88]อะไรที่อยู่ในใจก็เก็บเอาไว้\n[01:57.27]มันมีความสุขแค่นี้ก็ดีมากมาย\n[02:04.87]เธอจะมีใจหรือเปล่า\n[02:08.71]เธอเคยมองมาที่ฉันหรือเปล่า\n[02:13.35]ที่เราเป็นอยู่นั้นคืออะไร\n[02:19.97]เธอจะมีใจหรือเปล่า\n[02:23.58]มันคือความจริงที่ฉันอยากรู้ติดอยู่ในใจ\n[02:28.76]แต่ไม่อยากถาม\n[02:32.10]กลัวรับมันไม่ไหว\n[02:49.84]เธอจะมีใจหรือเปล่า\n[02:53.62]มันคือความจริงที่ฉันอยากรู้ติดอยู่ในใจ\n[02:58.92]แต่ไม่อยากถาม\n[03:01.97]กลัวรับมันไม่ไหว\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=526935815.mp3",
|
||||
"pic": "http://p1.music.126.net/YHJf5d-3r4CdhVm1ZsNlrw==/109951163095371221.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=1829162380",
|
||||
"songid": 1829162380,
|
||||
"title": "Ayasa绚沙-Ayasa绚沙-我爱你(小提琴虹 remix)",
|
||||
"author": "violin琪虹",
|
||||
"lrc": "",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=1829162380.mp3",
|
||||
"pic": "http://p1.music.126.net/vsrq8MI6dWo_mVxY1Vzyow==/109951165806756872.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=1988565276",
|
||||
"songid": 1988565276,
|
||||
"title": "我爱你",
|
||||
"author": "法老,MC脏脏",
|
||||
"lrc": "[00:00.000] 作词 : 法老/MC脏脏\n[00:01.000] 作曲 : 法老/MC脏脏\n[00:02.521]混音:隆历奇\n[00:04.640]编曲:隆历奇\n[00:07.295]录音:杨秋儒\n[00:09.693]我好爱你\n[00:20.851]我此刻不会再隐瞒你\n[00:22.442]在开始恋情之前我说\n[00:24.300]我没资格去评判你\n[00:25.362]你那么美丽\n[00:26.422]从头到尾散发魅力\n[00:28.281]我想和你环游世界一起去看看北极\n[00:30.404]你说 我会一直陪你陪你 一切的习惯都随你\n[00:33.335]在酒吧的前厅 窗外又开始响起雷雨\n[00:35.722]我们走出户外 在雨中开始漫长的接吻\n[00:38.641]两个不羁的人格 决定一起对世界泄愤\n[00:41.030]自由是我们的信条\n[00:42.357]心跳是信号\n[00:43.694]一起去滑板摔出青泡\n[00:45.286]但只要两个人浸泡在一起那温柔的就像摔进天堂的音道\n[00:49.002]让我们互相眼里只有彼此 把所有荷尔蒙都引爆\n[00:52.186]但世界末日我们也会分开\n[00:54.045]因为宇宙塌了下来 所以我要去为你撑开\n[00:56.707]火车轨道 只是为了我们存在\n[00:59.362]我们马上出发 就让不相干的人全滚蛋\n[01:02.016](在一刹那woman)\n[01:03.115](特别的话woman)\n[01:04.178]你是我见过镜头里最完美那woman\n[01:06.833](在一刹那woman)\n[01:08.160](特别的话woman)\n[01:09.487]我一定不会认错那就是爱woman\n[01:12.138](那就是爱)越过山河和你拥吻\n[01:15.071](这就是爱)in this moment\n[01:17.191]要多伟大的爱才能把爱这个字写的工整\n[01:20.110]我可以停止呼吸\n[01:21.437]但我不能停止爱你 woman\n[01:22.766]你说你爱听摇滚\n[01:24.623]可居然陪我喜欢听说唱\n[01:25.950]你说这世界的音乐就像动物多种多样\n[01:28.349]别藐视\n[01:29.144]看海岸路边的礁石\n[01:30.472]麋鹿在天际消失\n[01:31.800]当我拉着你的手时 自然的十指交织\n[01:33.656]我们和所有当地艺术家都成为了朋友\n[01:36.576]或许他们没有成就\n[01:37.913]但从未忘记奋斗\n[01:39.242]就像现在并非旺季\n[01:40.832]我们却牵手在海边贩卖我们的手工制品\n[01:43.488]青青子衿,悠悠我心\n[01:45.078]你美的好像来自诗经\n[01:46.936]你却说为我感到有文化而吃惊\n[01:48.804]我生气地在后面追着你划过了海岸线\n[01:51.458]转瞬我们就在呼伦贝尔的羊群里面 过夜\n[01:54.111]每次贴近你 我都感到大脑与呼吸 脱节\n[01:56.768]我好爱你 爱到想把此刻的时间 全部终结\n[01:59.429]我不关心火星是否有水 只关心这个冬天\n[02:02.085]我找了好几辈子的人就 站在我的身边\n[02:04.738](在一刹那woman)\n[02:05.535](特别的话woman)\n[02:06.874]你是我见过镜头里最完美那woman\n[02:09.530](在一刹那woman)\n[02:10.866](特别的话woman)\n[02:12.192]我一定不会认错那就是爱woman\n[02:14.582](那就是爱)越过山河和你拥吻\n[02:17.503](这就是爱)in this moment\n[02:19.623]要多伟大的爱才能把爱这个字写的工整\n[02:22.553]我可以停止呼吸\n[02:23.879]但我不能停止爱你 woman\n[02:25.472]我们搭建了两个人的家庭\n[02:27.328]建在房车里的咖啡厅\n[02:28.922]让那些忙碌的人 带来故事由我们聆听\n[02:31.350]我说再也不回城市\n[02:33.139]我想要自由真实\n[02:34.200]我想和你一起老去化成分子\n[02:36.067]那暖熏的风暴将把我们\n[02:37.926]卷上天空\n[02:38.723]降下雨水\n[02:39.253]滋润雄伟的天山最高尖峰\n[02:41.377]这不就是我们所追求的吗\n[02:42.969]哪怕这臭水沟 连喝水都会 硌牙\n[02:45.359]我们也做相依伴的荷花\n[02:46.960]我看着她的眼睛\n[02:48.300]语气坚定\n[02:49.098]她却 突然闪烁地像是画布上的剪影\n[02:51.485]开始变形\n[02:52.282]奇怪的光线开始交织\n[02:53.874]我大喊她的名字\n[02:54.934]她只是微笑 直到变成了蝴蝶消失\n[02:57.059]再睁开眼睛 是泪水 是害怕地把呼吸屏住\n[03:00.252]是黑暗里找她的手却摸到件工作服\n[03:03.173]忙碌的窗外 没有爱情\n[03:04.764]有混凝土 有风声在呼 有东方 明珠\n[03:07.153](在一刹那woman)\n[03:08.225](特别的话woman)\n[03:09.552]你是我见过镜头里最完美那woman\n[03:12.207](在一刹那woman)\n[03:13.531](特别的话woman)\n[03:14.596]我一定不会认错那就是爱woman\n[03:17.287](那就是爱)越过山河和你拥吻\n[03:19.940](这就是爱)in this moment\n[03:22.065]要多伟大的爱才能把爱这个字写的工整\n[03:25.449]我可以停止呼吸\n[03:26.510]但我不能停止爱你\n[03:33.110]监制:邓思楚\n[03:35.527]出品公司:AYO!\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=1988565276.mp3",
|
||||
"pic": "http://p1.music.126.net/WEOaWIg8WAG_kBhmAx7zbA==/109951168688783089.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=68378",
|
||||
"songid": 68378,
|
||||
"title": "我爱你",
|
||||
"author": "新裤子",
|
||||
"lrc": "[00:00.000] 作词 : 新裤子\n[00:00.193] 作曲 : 新裤子\n[00:00.386] 编曲 : 新裤子\n[00:00.580]我爱你,我总怕见不到你\n[00:07.650]看着你,我要把全部给你\n[00:14.120]纷纷乱乱的记忆 无拘无束的哭泣\n[00:21.380]反反复复的想你 我终于失去你\n[00:27.530]分离 和你在一起\n[00:32.700]\n[00:34.370](KeyBoard Solo)\n[01:03.300]我爱你,我总怕见不到你\n[01:09.940]看着你,我要把全部给你\n[01:16.570]纷纷乱乱的记忆 无拘无束的哭泣\n[01:23.710]反反复复的想你 我终于失去你\n[01:30.360]分离 和你在一起\n[01:37.990]\n[01:38.180](Music)新裤子-我爱你\n[01:51.930]我爱你,我总怕见不到你\n[01:58.880]看着你,我要把全部给你\n[02:05.400]纷纷乱乱的记忆 无拘无束的哭泣\n[02:12.530]反反复复的想你 我终于失去你\n[02:18.980]分离 和你在一起\n[02:25.760](Music)\n[40:39.990]\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=68378.mp3",
|
||||
"pic": "http://p1.music.126.net/PHmfQN1ssTM56sjHU9AuSQ==/86861418607081.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=1459498368",
|
||||
"songid": 1459498368,
|
||||
"title": "我爱你(抖音完整版)(翻自 卢广仲)",
|
||||
"author": "徐心愉",
|
||||
"lrc": "[00:00.000] 作词 : 卢广仲/群可/邢书郡\n[00:01.000] 作曲 : 卢广仲/邢书郡\n[00:02.000] 编曲 : 王中易\n[00:07.230] 制作人:王中易\n[00:08.660] 吉他:陈柏彤\n[00:09.819] 和声:栗可\n[00:11.076] 混音:王宇呈/王中易\n[00:12.674] 制作团队:伊格赛听\n[00:22.114] 曾经在我眼前 却又消失不见\n[00:27.352] 这是今天的第六遍\n[00:32.413] 电影里的配乐 好像你的双眼\n[00:37.394] 我爱你 快回到 我身边\n[00:42.751] 曾经在我眼前 却又消失不见\n[00:47.680] 这是今天的第六遍\n[00:52.794] 电影里的配乐 好像你的双眼\n[00:57.495] 我爱你 快回到 我身边\n[01:03.540] One Two Three\n[01:06.293] 有没有 这样的一封信\n[01:11.319] 上面 记载着你的心情\n[01:16.440] 有没有 这样的一首歌\n[01:21.460] 唱 出人们的悲欢离合\n[01:26.526] 有没有 这样的一场电影\n[01:31.425] 能让你我 触景伤情\n[01:35.629] O mY BABY\n[01:37.964] 原来你早已经 带走了我的心\n[01:46.320] 听到爱听的音乐 想起熟悉的你\n[01:48.646] 快要陌生的轴距 可能触景生情\n[01:51.142] 哈 我想我 都不属于自己\n[01:53.854] 或许 自己的心情 不再删除那记忆\n[01:56.539] 看不见你的时候 勉强的我好累\n[01:58.906] 从第一眼见到你的时候 就感觉很对\n[02:01.790] 那么也请你 给我一次机会\n[02:04.171] 不要让我每天 带着安慰入睡\n[02:06.716] 在我眼前 却又消失不见\n[02:10.927] 这是今天的第六遍\n[02:16.232] 电影里的情节 好像你的双眼\n[02:20.636] 我爱你 快回到 我身边\n[02:26.707] 在我眼前 却又消失不见\n[02:31.121] 这是今天的第六遍\n[02:36.241] 电影里的配乐 好像你的双眼\n[02:41.051] 我爱你 快回到 我身边\n[03:06.993] 听到爱听的音乐 想起熟悉的你\n[03:09.268] 快要陌生的轴距 可能触景生情\n[03:11.872] 哈 我想我 都不属于自己\n[03:14.327] 或许 自己的心情 不再删除那记忆\n[03:17.339] 看不见你的时候 勉强的我好累\n[03:19.799] 从第一眼见到你的时候 就感觉很对\n[03:22.422] 那么也请你 给我一次机会\n[03:24.983] 不要让我每天 带着安慰入睡\n[03:27.535] 在我眼前 却又消失不见\n[03:31.766] 这是今天的第六遍\n[03:36.988] 电影里的情节 好像你的双眼\n[03:41.508] 我爱你 快回到 我身边\n[03:47.572] 在我眼前 却又消失不见\n[03:52.030] 这是今天的第六遍\n[03:57.088] 电影里的配乐 好像你的双眼\n[04:01.859] 我爱你 快回到 我身边\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=1459498368.mp3",
|
||||
"pic": "http://p1.music.126.net/HRUorxaQMCzcQh89nEe6YQ==/109951165100677013.jpg?param=300x300"
|
||||
},
|
||||
{
|
||||
"type": "netease",
|
||||
"link": "http://music.163.com/#/song?id=2000142344",
|
||||
"songid": 2000142344,
|
||||
"title": "我爱你-程佳佳",
|
||||
"author": "打造完美音乐",
|
||||
"lrc": "[00:00.00] 作词 : 打造完美音乐\n[00:00.00] 作曲 : 打造完美音乐\n[00:00.00] 编曲 : 打造完美音乐\n[00:00.00]那么也请你给我一次机会\n[00:08.46]不要让我每天带着安慰入睡\n[00:10.91]在我眼前\n[00:12.82]却又消失不见\n[00:15.39]这是今天的第六遍\n[00:20.58]电影里的情节\n[00:23.05]好像你的双眼\n[00:25.38]我爱你 快回到 我 身边\n[00:31.22]oh~在我眼前\n[00:33.27]却又消失不见\n[00:35.84]这是今天的第六遍\n[00:40.87]电影里的情节\n[00:43.48]好像你的双眼\n[00:45.74]我爱你 快回到 我身边\n",
|
||||
"url": "http://music.163.com/song/media/outer/url?id=2000142344.mp3",
|
||||
"pic": "http://p1.music.126.net/-XOM0P5Jw7ELN5ufko05lw==/109951167900715199.jpg?param=300x300"
|
||||
}
|
||||
],
|
||||
"code": 200,
|
||||
"error": ""
|
||||
}
|
||||
}
|
||||
music_id_json = music_id_json['data']
|
||||
print(music_id_json)
|
||||
save_search_music(music_id_json)
|
62
server/user_server.py
Normal file
62
server/user_server.py
Normal file
@ -0,0 +1,62 @@
|
||||
import csv
|
||||
import pymysql
|
||||
import untils
|
||||
import hashlib
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password, port=mysql_port, charset="utf8",
|
||||
database=mysql_database)
|
||||
|
||||
# md5加密
|
||||
def md5(password):
|
||||
md5 = hashlib.md5()
|
||||
md5.update(password.encode("utf-8"))
|
||||
return md5.hexdigest()
|
||||
|
||||
|
||||
def create_user(username, password):
|
||||
password = md5(password)
|
||||
|
||||
try:
|
||||
with con.cursor() as cur:
|
||||
# 判断用户是否存在
|
||||
if cur.execute("SELECT * FROM User WHERE username = %s", (username,)):
|
||||
return {"status": 400, "msg": "User Already Exists"}
|
||||
|
||||
# 创建用户
|
||||
sql = """
|
||||
INSERT INTO User (username, password) VALUES (%s, %s);
|
||||
"""
|
||||
cur.execute(sql, (username, password))
|
||||
con.commit()
|
||||
|
||||
return {"status": 200, "msg": "Success Create User"}
|
||||
except Exception as e:
|
||||
con.rollback()
|
||||
print(e)
|
||||
return {"status": 400, "msg": "Failed Create User"}
|
||||
|
||||
|
||||
def login_user(username, password):
|
||||
password = md5(password)
|
||||
try:
|
||||
with con.cursor() as cur:
|
||||
# 判断用户是否存在
|
||||
if cur.execute("SELECT * FROM User WHERE username = %s", (username,)):
|
||||
# 判断密码是否正确
|
||||
if cur.execute("SELECT * FROM User WHERE username = %s AND password = %s", (username, password)):
|
||||
return {"status": 200, "msg": "Success Login"}
|
||||
else:
|
||||
return {"status": 400, "msg": "Password Error"}
|
||||
else:
|
||||
return {"status": 400, "msg": "User Not Exists"}
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return {"status": 400, "msg": "Failed Login"}
|
||||
|
@ -1,64 +0,0 @@
|
||||
import csv
|
||||
|
||||
|
||||
def register(username, password):
|
||||
# 读取现有的用户信息
|
||||
existing_users = read_users()
|
||||
|
||||
# 检查用户名是否已存在
|
||||
if username in existing_users:
|
||||
return False, "Username already exists."
|
||||
|
||||
# 添加新用户信息
|
||||
new_user = {"username": username, "password": password}
|
||||
existing_users[username] = new_user
|
||||
|
||||
# 将用户信息保存到CSV文件
|
||||
save_users(existing_users)
|
||||
|
||||
return True, "Registration successful."
|
||||
|
||||
|
||||
def login(username, password):
|
||||
# 读取用户信息
|
||||
existing_users = read_users()
|
||||
|
||||
# 验证用户名和密码
|
||||
user = existing_users.get(username)
|
||||
if user and user["password"] == password:
|
||||
return True, "Login successful."
|
||||
return False, "Invalid credentials."
|
||||
|
||||
|
||||
def read_users():
|
||||
# 从CSV文件中读取用户信息
|
||||
users = {}
|
||||
try:
|
||||
with open("data/users.csv", "r", newline="") as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
users[row["username"]] = {"username": row["username"], "password": row["password"]}
|
||||
except FileNotFoundError:
|
||||
pass # 如果文件不存在,说明还没有注册用户,返回一个空字典
|
||||
return users
|
||||
|
||||
|
||||
def save_users(users):
|
||||
# 将用户信息保存到CSV文件
|
||||
with open("data/users.csv", "w", newline="") as csvfile:
|
||||
fieldnames = ["username", "password"]
|
||||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
for user in users.values():
|
||||
writer.writerow(user)
|
||||
|
||||
# 测试注册功能
|
||||
# register("user1", "password1")
|
||||
# register("user2", "password2")
|
||||
|
||||
# 测试登录功能
|
||||
# login_success, message = login("user1", "password1")
|
||||
# print(message) # 输出:Login successful.
|
||||
#
|
||||
# login_success, message = login("user3", "password3")
|
||||
# print(message) # 输出:Invalid credentials.
|
38
sql/create_UserPlayList.py
Normal file
38
sql/create_UserPlayList.py
Normal file
@ -0,0 +1,38 @@
|
||||
# 导入pymysql
|
||||
import pymysql
|
||||
import untils
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password,port=mysql_port, charset="utf8", database=mysql_database)
|
||||
|
||||
# 创建游标对象
|
||||
cur = con.cursor()
|
||||
|
||||
# 编写创建表的sql
|
||||
# UserPlayList是用户的歌单表关联用户表
|
||||
sql = """
|
||||
CREATE TABLE UserPlayList (
|
||||
playlist_id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
playlist_name VARCHAR(255) NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES User(user_id)
|
||||
);
|
||||
"""
|
||||
|
||||
try:
|
||||
# 执行创建表的sql
|
||||
cur.execute(sql)
|
||||
print("创建成功")
|
||||
# 关闭游标连接
|
||||
cur.close()
|
||||
# 关闭数据库连接
|
||||
con.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("创建表失败")
|
32
sql/create_database.py
Normal file
32
sql/create_database.py
Normal file
@ -0,0 +1,32 @@
|
||||
# 导入pymysql
|
||||
import pymysql
|
||||
import untils
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password,port=mysql_port, charset="utf8")
|
||||
|
||||
# 创建游标对象
|
||||
cur = con.cursor()
|
||||
|
||||
# 编写创建表的sql
|
||||
sql = """
|
||||
create database music_sql;
|
||||
"""
|
||||
|
||||
try:
|
||||
# 执行创建表的sql
|
||||
cur.execute(sql)
|
||||
print("创建数据库成功")
|
||||
# 关闭游标连接
|
||||
cur.close()
|
||||
# 关闭数据库连接
|
||||
con.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("创建表失败")
|
||||
|
44
sql/create_music.py
Normal file
44
sql/create_music.py
Normal file
@ -0,0 +1,44 @@
|
||||
# 导入pymysql
|
||||
import pymysql
|
||||
import untils
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password,port=mysql_port, charset="utf8", database=mysql_database)
|
||||
|
||||
# 创建游标对象
|
||||
cur = con.cursor()
|
||||
|
||||
# 编写创建表的sql
|
||||
sql = """
|
||||
CREATE TABLE Music (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
type VARCHAR(50),
|
||||
link VARCHAR(255),
|
||||
songid INT,
|
||||
title VARCHAR(255),
|
||||
author VARCHAR(255),
|
||||
lrc TEXT,
|
||||
url VARCHAR(255),
|
||||
pic VARCHAR(255),
|
||||
UNIQUE KEY unique_songid (songid)
|
||||
|
||||
);
|
||||
"""
|
||||
|
||||
try:
|
||||
# 执行创建表的sql
|
||||
cur.execute(sql)
|
||||
print("创建成功")
|
||||
# 关闭游标连接
|
||||
cur.close()
|
||||
# 关闭数据库连接
|
||||
con.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("创建表失败")
|
39
sql/create_playlistsong.py
Normal file
39
sql/create_playlistsong.py
Normal file
@ -0,0 +1,39 @@
|
||||
# 导入pymysql
|
||||
import pymysql
|
||||
import untils
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password,port=mysql_port, charset="utf8", database=mysql_database)
|
||||
|
||||
# 创建游标对象
|
||||
cur = con.cursor()
|
||||
|
||||
# 编写创建表的sql
|
||||
# PlaylistSong是歌单的歌曲表关联歌单表和歌曲表
|
||||
sql = """
|
||||
CREATE TABLE PlaylistSong (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
playlist_id INT NOT NULL,
|
||||
songid INT NOT NULL,
|
||||
FOREIGN KEY (playlist_id) REFERENCES UserPlayList(playlist_id),
|
||||
FOREIGN KEY (songid) REFERENCES Music(songid)
|
||||
);
|
||||
"""
|
||||
|
||||
try:
|
||||
# 执行创建表的sql
|
||||
cur.execute(sql)
|
||||
print("创建成功")
|
||||
# 关闭游标连接
|
||||
cur.close()
|
||||
# 关闭数据库连接
|
||||
con.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("创建表失败")
|
39
sql/create_user.py
Normal file
39
sql/create_user.py
Normal file
@ -0,0 +1,39 @@
|
||||
# 导入pymysql
|
||||
import pymysql
|
||||
import untils
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password,port=mysql_port, charset="utf8", database=mysql_database)
|
||||
|
||||
# 创建游标对象
|
||||
cur = con.cursor()
|
||||
|
||||
# 编写创建表的sql
|
||||
sql = """
|
||||
CREATE TABLE User (
|
||||
user_id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
date_joined TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
"""
|
||||
|
||||
try:
|
||||
# 执行创建表的sql
|
||||
cur.execute(sql)
|
||||
print("创建成功")
|
||||
# 关闭游标连接
|
||||
cur.close()
|
||||
# 关闭数据库连接
|
||||
con.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("创建表失败")
|
||||
|
2
test/key_test.py
Normal file
2
test/key_test.py
Normal file
@ -0,0 +1,2 @@
|
||||
import os
|
||||
|
23
test/sql_test.py
Normal file
23
test/sql_test.py
Normal file
@ -0,0 +1,23 @@
|
||||
# 导入pymysql
|
||||
import pymysql
|
||||
import untils
|
||||
|
||||
mysql_host = untils.mysql_host
|
||||
mysql_port = untils.mysql_port
|
||||
mysql_user = untils.mysql_user
|
||||
mysql_password = untils.mysql_password
|
||||
mysql_database = untils.mysql_database
|
||||
|
||||
# 创建连接
|
||||
con = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password,port=mysql_port, charset="utf8", database=mysql_database)
|
||||
|
||||
# 创建游标对象
|
||||
cursor = con.cursor()
|
||||
|
||||
email = "1264204425@qq.com"
|
||||
# 编写创建表的sql
|
||||
cursor.execute("SELECT * FROM User WHERE email = %s", (email,))
|
||||
user = cursor.fetchone()
|
||||
print(user)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user