Skip to content

Commit 4f8a997

Browse files
committed
Cover loading for spotify and youtube
1 parent 56feff4 commit 4f8a997

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

no-cover.png

8.8 KB
Loading

radio_main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def remove_prev_files(rootdir):
6969
#os.system("ffmpeg -re -f concat -safe 0 -i {} -c:a libmp3lame -ar 44100 -ac 2 -vn -f mp3 -map_metadata 0 -content_type 'audio/mpeg' {} &".format(audiofiles_path, icecast_mountpoint))
7070

7171
subprocess.Popen("ffmpeg -re -f concat -safe 0 -i {} -c:a libmp3lame -ar 44100 -ac 2 -vn -f mp3 -map_metadata 0 -content_type 'audio/mpeg' {}".format(audiofiles_path, icecast_mountpoint), shell=True, start_new_session=True, stderr=subprocess.STDOUT)
72-
time.sleep(4)
73-
songupdater2.title_updater_start(songs, mountpoint)
72+
songupdater2.title_updater_start(lines, songs, mountpoint)
7473

7574

7675

songupdater2.py

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
11
import time
22
import requests
33
import sys
4+
import shutil
5+
import os
6+
from mutagen.id3 import ID3
7+
48

59
stream_start = float(time.time())
610

711
def get_stream_time():
812
return float(time.time()) - stream_start
913

1014
def update_stream_title(new_title, mountpoint):
11-
headers = {'authorization': 'Basic YWRtaW46JGljZWFkbWluJA=='}
15+
response = 0
16+
headers = {'authorization': 'Basic UR_KEY'}
1217
url = "http://192.168.1.2:2139/admin/metadata.xsl?song={}&mount=%2F{}&mode=updinfo&charset=UTF-8".format(new_title, mountpoint)
13-
r = requests.get(url, headers=headers)
18+
19+
while response != 200:
20+
time.sleep(0.5)
21+
r = requests.get(url, headers=headers)
22+
response = r.status_code
1423

1524
return r
1625

17-
def title_updater_start(songs, mountpoint):
26+
def set_song_cover(file, mountpoint):
27+
id3_data = ID3(file)
28+
29+
if "APIC:Album cover" in id3_data:
30+
cover = id3_data["APIC:Album cover"].data
31+
with open("/home/bonzo/radiosite/img/cover-{}.png".format(mountpoint), "wb") as coverfile:
32+
coverfile.write(cover)
33+
coverfile.close()
34+
else:
35+
external_cover_file = file.split(".")[0] + ".jpg"
36+
destination_image = "/home/bonzo/radiosite/img/cover-{}.png".format(mountpoint)
37+
if os.path.exists(external_cover_file):
38+
shutil.copy(external_cover_file, destination_image)
39+
else:
40+
shutil.copy("no-cover.png", destination_image)
41+
42+
43+
44+
def title_updater_start(files, songs, mountpoint):
1845
indexx = 0
1946
songs.sort(reverse=False, key=lambda x: int(x[0]))
2047

@@ -36,6 +63,7 @@ def title_updater_start(songs, mountpoint):
3663
if current_time_seconds <= next_song_start:
3764
if not donotsend:
3865
req = update_stream_title(entry[1], mountpoint)
66+
set_song_cover(files[indexx - 1], mountpoint)
3967
current_song = entry[1]
4068
else:
4169
break

0 commit comments

Comments
 (0)