-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGTZAN_excerpt_analysis_AudD.py
53 lines (49 loc) · 1.54 KB
/
GTZAN_excerpt_analysis_AudD.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import requests
import os
import os.path
import json
import openpyxl
path = ''
wb = openpyxl.load_workbook(path)
sheet = wb.active
data = {
'api_token': '',
}
PATH = ''
def getAudioInformation():
sno = 0
ROW = 2
tags = []
for root, dirs, files in os.walk(PATH):
for File in files:
try:
root = root.replace("\\","/")
files = {
'file': open(f'{root}/{File}', 'rb'),
}
result = requests.post('https://api.audd.io/', data=data, files=files)
result_json = json.loads(result.text)
metadata = {
'sno': sno,
'artist': result_json['result']['artist'],
'title': result_json['result']['title'],
'album': result_json['result']['album']
}
print(metadata)
songid = sheet.cell(row=ROW, column=1)
track = sheet.cell(row=ROW, column=2)
artist = sheet.cell(row=ROW, column=3)
album = sheet.cell(row=ROW, column=4)
songid.value = sno
track.value = result_json['result']['title']
artist.value = result_json['result']['artist']
album.value = result_json['result']['album']
tags.append(metadata)
sno += 1
ROW += 1
wb.save(path)
except:
sno += 1
continue
return tags
print(getAudioInformation())