feature:支持音乐指纹识别,即使没有元数据也可以识别音乐

This commit is contained in:
charlesxie
2023-07-14 16:14:45 +08:00
parent 72dc7d71f4
commit 4685b847cc
13 changed files with 1178 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ class BatchUpdateId3Serializer(serializers.Serializer):
class FetchId3ByTitleSerializer(serializers.Serializer):
title = serializers.CharField(required=True)
resource = serializers.CharField(required=True)
full_path = serializers.CharField(required=False, allow_null=True, allow_blank=True)
class FetchLlyricSerializer(serializers.Serializer):

View File

@@ -0,0 +1,22 @@
from component.mz.run import get_acoustid
class AcoustidClient:
def fetch_id3_by_title(self, title):
songs = []
res = get_acoustid(title)
for each in res:
songs.append({
"id": each[1],
"name": each[2],
"artist": each[3],
"artist_id": "",
"album": each[4],
"album_id": "",
"album_img": "",
"year": "",
})
return songs
def fetch_lyric(self, song_id):
raise Exception("暂不支持该音乐平台")

View File

@@ -1,6 +1,7 @@
import requests
import base64
from applications.task.services.acoust import AcoustidClient
from applications.task.services.kugou import KugouClient
from applications.task.services.kuwo import KuwoClient
from applications.task.services.qm import QQMusicApi
@@ -23,6 +24,8 @@ class MusicResource:
return KugouClient()
elif info == "kuwo":
return KuwoClient()
elif info == "acoustid":
return AcoustidClient()
raise Exception("暂不支持该音乐平台")
def fetch_lyric(self, song_id):

View File

@@ -211,8 +211,11 @@ class TaskViewSets(GenericViewSet):
def fetch_id3_by_title(self, request, *args, **kwargs):
validate_data = self.is_validated_data(request.data)
resource = validate_data["resource"]
full_path = validate_data.get("full_path", "")
title = validate_data["title"]
if resource == "acoustid":
title = full_path
songs = MusicResource(resource).fetch_id3_by_title(title)
return self.success_response(data=songs)