diff --git a/.gitignore b/.gitignore index 3caa297..7abc2af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ album_art.gif album_art.jpg + diff --git a/album_art.gif b/album_art.gif index 52502c8..c0765b7 100644 Binary files a/album_art.gif and b/album_art.gif differ diff --git a/album_art.jpg b/album_art.jpg index eb7e02c..408a42f 100644 Binary files a/album_art.jpg and b/album_art.jpg differ diff --git a/get_oorp.py b/get_oorp.py new file mode 100755 index 0000000..0683691 --- /dev/null +++ b/get_oorp.py @@ -0,0 +1,83 @@ +#!/bin/python3 + +from tkinter import * +from tkinter.font import Font +from PIL import Image +import requests +import urllib + + +class RadioParadise(object): + def __init__(self): + self.load_api() + + def load_api(self): + respons=requests.get("https://api.radioparadise.com/api/now_playing") + rp_dict=respons.json() + self.title=rp_dict["title"] + self.artist=rp_dict["artist"] + self.album=rp_dict["album"] + self.year=rp_dict["year"] + self.time=rp_dict["time"] + self.jpg_path=rp_dict["cover"] + return rp_dict + + def get_fmt_list(self): + result=(f'Titel: {self.title}\nArtiest: {self.artist}\nAlbum: {self.album}\nJaar: {self.year}\nTijd: {self.time}') + return result + + def store_albumcover(self): + rp_raw_image=requests.get(self.jpg_path).content + rp_file=open("album_art.jpg", "wb") + rp_file.write(rp_raw_image) + rp_file.close() + rp_convert_img=Image.open("album_art.jpg") + rp_convert_img.save("album_art.gif") + rp_convert_img.close() + + +class RPViewer(Tk): + def __init__(self, radioparadise, *args, **kwargs): + super().__init__(*args, **kwargs) + self.rp=radioparadise + self.title("Radio Paradise Viewer") + self.geometry("500x740") + self.resizable(False,False) + self.label=Label(self, font="Arial, 14", text="Radio Paradise now playing:") + self.label.pack() + self.button_quit=Button(self, text="Quit", command=self.quit) + self.button_refresh=Button(self, text="Refresh", command=lambda: [self.rp.load_api(),self.refresh_textbox()]) + self.button_quit.pack(side=BOTTOM) + self.button_refresh.pack(side=TOP) + self.font=Font(family="Arial", size=14) + self.textbox=Text(self, height=6, width=50, font=self.font) + self.textbox.insert("1.0", self.rp.get_fmt_list()) + self.textbox.config(state=DISABLED) + self.textbox.pack() + self.rp.store_albumcover() + self.img = PhotoImage(file="album_art.gif", format='gif') + self.image_lbl = Label(self, image=self.img) + self.image_lbl.pack() + + def quit(self): + exit() + + def refresh_textbox(self): + self.textbox.config(state=NORMAL) + self.textbox.delete("1.0", "end") + self.textbox.insert("1.0", self.rp.get_fmt_list()) + self.textbox.config(state=DISABLED) + self.rp.store_albumcover() + self.img = PhotoImage(file="album_art.gif", format='gif') + self.image_lbl.configure(image=self.img) + self.image_lbl.image=self.img + + +def main(): + rp_play=RadioParadise() + app=RPViewer(rp_play) + app.mainloop() + +if __name__=="__main__": + main() + \ No newline at end of file diff --git a/get_rp.py b/get_rp.py deleted file mode 100755 index 282fde0..0000000 --- a/get_rp.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/python3 - -from tkinter import * -from tkinter.font import Font -import requests -import urllib -from PIL import Image - -def get_rp(): - # Get API respons - respons = requests.get("https://api.radioparadise.com/api/now_playing") - tekst = respons.json() - - # Selection of data to use - title = tekst["title"] - artist = tekst["artist"] - album = tekst["album"] - year = tekst["year"] - time = tekst["time"] - jpg_path = tekst["cover"] - - # Return caller standard information - message = (f'Titel: {title}\nArtiest: {artist}\nAlbum: {album}\nJaar: {year}\nTijd: {time}') - return message,jpg_path - -def rp_quit(): - exit() - -# Refresh data from Radio Paradise when asked -def rp_refresh(): - rp_tekstbox.delete("1.0", "end") - rp_tekstbox.insert("1.0", get_rp()[0]) - - # Convert the jpg-file from RP to a manageable gif - get_and_convert_art() - - # Load the image into the label - img = PhotoImage(file="album_art.gif", format='gif') - image_lbl.configure(image=img) - image_lbl.image=img - -# Converts and stores a .jpg into a .gif -def get_and_convert_art(): - rp_image_path = get_rp()[1] - rp_image_file = requests.get(rp_image_path).content - - rp_file=open("album_art.jpg", 'wb') - rp_file.write(rp_image_file) - rp_file.close() - rp_image = Image.open("album_art.jpg") - rp_image.save("album_art.gif") - rp_image.close() - -if __name__=="__main__": - - window=Tk() - window.title("Radio Paradise") - - rp_font=Font(family="Arial", size=14) - rp_tekstbox=Text(window, height=6, width=50, font=rp_font) - - label=Label(window, font="Arial, 14", text="Radio Paradise now playing") - label.pack() - - button_quit=Button(window, text="Quit", command=rp_quit) - button_refresh=Button(window, text="Refresh", command=rp_refresh) - button_quit.pack(side=BOTTOM) - button_refresh.pack(side=TOP) - - rp_tekstbox.insert("1.0", get_rp()[0]) - rp_tekstbox.pack() - - get_and_convert_art() - - img = PhotoImage(file="album_art.gif", format='gif') - image_lbl = Label(window, image=img) - image_lbl.pack() - - window.mainloop() \ No newline at end of file