Compare commits

..
10 Commits
Author SHA1 Message Date
sulzlep ab65e1dcf0 no idea 2024-11-26 21:36:25 +01:00
sulzlep b522935ee9 Merge pull request 'oopdev naar master' (#5) from oopdev into master
Reviewed-on: http://gitea.fritz.box:3000/sulzlep/get_rp/pulls/5
2023-12-30 12:05:16 +01:00
sulzlep 47eb2e02f8 Cleanup 2023-12-30 11:58:45 +01:00
sulzlep 8a55fd9ffb Refreshing of Album Cover now works as intended
(maybe needs some rewrting of the function)
2023-12-30 11:53:24 +01:00
sulzlep 360ea58a7c AlbumCover is now displayed 2023-12-30 11:39:34 +01:00
sulzlep b82b95a911 WIP on AlbumCover class 2023-12-30 11:17:16 +01:00
sulzlep 19efe3984c Formatting string in textbox from class RadioParadise 2023-12-30 11:07:20 +01:00
sulzlep 45f0a3cfeb small improvements to make textbox non-editable 2023-12-30 11:00:16 +01:00
sulzlep 52ec8a20d9 New branch 2023-12-28 17:45:58 +01:00
sulzlep 5d2e682b51 Button not working, but init is ok 2023-12-28 17:30:43 +01:00
5 changed files with 89 additions and 96 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 215 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 51 KiB

+38 -17
View File
@@ -9,14 +9,9 @@ import urllib
class RadioParadise(object): class RadioParadise(object):
def __init__(self): def __init__(self):
self.title=None self.load_api()
self.artist=None
self.album=None
self.year=None
self.time=None
self.jpg_path=None
def rp_reload_api(self): def load_api(self):
respons=requests.get("https://api.radioparadise.com/api/now_playing") respons=requests.get("https://api.radioparadise.com/api/now_playing")
rp_dict=respons.json() rp_dict=respons.json()
self.title=rp_dict["title"] self.title=rp_dict["title"]
@@ -25,15 +20,16 @@ class RadioParadise(object):
self.year=rp_dict["year"] self.year=rp_dict["year"]
self.time=rp_dict["time"] self.time=rp_dict["time"]
self.jpg_path=rp_dict["cover"] self.jpg_path=rp_dict["cover"]
return rp_dict
class AlbumCover(RadioParadise): def get_fmt_list(self):
def __init__(self, path): result=(f'Titel: {self.title}\nArtiest: {self.artist}\nAlbum: {self.album}\nJaar: {self.year}\nTijd: {self.time}')
self.jpg_path=path return result
def store_albumcover(self): def store_albumcover(self):
rp_raw_image=requests.get(self.jpg_path).content rp_raw_image=requests.get(self.jpg_path).content
rp_file=open("album_art.jpg", "wb") rp_file=open("album_art.jpg", "wb")
rp_file.write("rp_raw_image") rp_file.write(rp_raw_image)
rp_file.close() rp_file.close()
rp_convert_img=Image.open("album_art.jpg") rp_convert_img=Image.open("album_art.jpg")
rp_convert_img.save("album_art.gif") rp_convert_img.save("album_art.gif")
@@ -41,20 +37,45 @@ class AlbumCover(RadioParadise):
class RPViewer(Tk): class RPViewer(Tk):
def __init__(self, *args, **kwargs): def __init__(self, radioparadise, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.rp=radioparadise
self.title("Radio Paradise Viewer") self.title("Radio Paradise Viewer")
self.geometry("500x740") self.geometry("500x740")
self.resizable(False,False) 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(): def main():
rp_play=RadioParadise() rp_play=RadioParadise()
rp_play.rp_reload_api() app=RPViewer(rp_play)
print (rp_play.title)
print(rp_play.artist)
print (rp_play.time)
app=RPViewer()
app.mainloop() app.mainloop()
if __name__=="__main__": if __name__=="__main__":
-79
View File
@@ -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()
+51
View File
@@ -0,0 +1,51 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Response struct {
Title string `json:"title"`
Artist string `json:"artist"`
Album string `json:"album"`
Year string `json:"year"`
Time int `json:"time"` // Seconds to go to end of song
Cover string `json:"cover"` // URL to picture of album cover
}
/*func getImage(url string) {
fmt.Println("Calling API and get image...")
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Print(err.Error())
}
return req
}
*/
func main() {
fmt.Println("Calling API...")
client := &http.Client{}
req, err := http.NewRequest("GET", "https://api.radioparadise.com/api/now_playing", nil)
if err != nil {
fmt.Print(err.Error())
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Print(err.Error())
}
var responseObject Response
json.Unmarshal(bodyBytes, &responseObject)
// coverUrl := responseObject.Cover
// getImage(coverUrl)
fmt.Printf("API Response as struct %+v\n", responseObject)
fmt.Println("Image from albumcover...")
}