Beispiel #1
0
async def redraw(session, sonos_data, display):
    """Redraw the screen with current data."""
    if sonos_data.status == "API error":
        if remote_debug_key != "": print("API error reported fyi")
        return

    pil_image = None

    # see if something is playing
    if sonos_data.status == "PLAYING":
        if remote_debug_key != "": print("Music playing")

        if not sonos_data.is_track_new():
            # Ensure the album frame is displayed in case the current track was paused, seeked, etc
            if not display.is_showing:
                display.show_album()
            return

        # slim down the trackname
        if sonos_settings.demaster:
            offline = not getattr(sonos_settings, "demaster_query_cloud",
                                  False)
            sonos_data.trackname = demaster.strip_name(sonos_data.trackname,
                                                       offline)
            if remote_debug_key != "":
                print("Demastered to " + sonos_data.trackname)
            _LOGGER.debug("Demastered to %s", sonos_data.trackname)

        image_data = await get_image_data(session, sonos_data.image_uri)
        if image_data:
            pil_image = Image.open(BytesIO(image_data))

        if pil_image is None:
            pil_image = Image.open(sys.path[0] + "/sonos.png")
            _LOGGER.warning("Image not available, using default")

        display.update(pil_image, sonos_data)
    else:
        display.hide_album()
        if remote_debug_key != "": print("Track not playing - doing nothing")
Beispiel #2
0
def update():

    global root
    global track_name
    global tk_image
    global previous_polled_trackname

    # Get sonos data from API
    current_trackname, current_artist, current_album, current_image, playing_status = sonos_user_data.current(
        sonos_room)

    # see if something is playing
    if playing_status == "PLAYING":

        # check whether the track has changed - don't bother updating everything if not
        if current_trackname != previous_polled_trackname:

            # update previous trackname so we know what has changed in future
            previous_polled_trackname = current_trackname

            # slim down the trackname
            if sonos_settings.demaster:
                current_trackname = demaster.strip_name(current_trackname)

            # set the details we need from the API into variables
            track_name.set(current_trackname)
            detail_text.set(current_artist + " • " + current_album)

            # pull the image from the uri provided
            image_url = current_image

            image_failed_to_load = False
            try:
                image_url_response = requests.get(image_url)
                pil_image = Image.open(BytesIO(image_url_response.content))
            except:
                pil_image = Image.open('sonos-black.png')
                target_image_width = 500

            # set the image size based on whether we are showing track details as well
            if sonos_settings.show_details == True:
                target_image_width = thumbwidth
            else:
                target_image_width = screenwidth

            # resize the image
            wpercent = (target_image_width / float(pil_image.size[0]))
            hsize = int((float(pil_image.size[1]) * float(wpercent)))
            pil_image = pil_image.resize((target_image_width, hsize),
                                         Image.ANTIALIAS)

            tk_image = ImageTk.PhotoImage(pil_image)
            label_albumart.configure(image=tk_image)

    if playing_status != "PLAYING":
        track_name.set("")
        detail_text.set("")
        label_albumart.configure(image="")
        previous_polled_trackname = ""

    # Schedule the poll() function for another 500 ms from now
    root.after(500, update)
Beispiel #3
0
import sys
import demaster

print ("")
print ("")
print ("Demaster script example - checks online API first, and if that fails runs locally")
print ("/offline to set offline mode")
print ("/quit to quit")
print ("")


offline_only = False
while True:
    name_to_check = input (">> ")
    if name_to_check == "/quit":
        sys.exit("")
    
    if name_to_check == "//offline":
        offline_only = True

    text_to_print = demaster.strip_name(name_to_check, offline_only)
    print (text_to_print)
    print ("")
    print ("")
Beispiel #4
0
def update():

    global root
    global track_name
    global tk_image
    global previous_polled_trackname

    # Get sonos data from API
    current_trackname, current_artist, current_album, current_image, playing_status = sonos_user_data.current(
        sonos_room)

    # see if something is playing
    if playing_status == "PLAYING":
        if remote_debug_key != "": print("Music playing")

        # check whether the track has changed - don't bother updating everything if not
        if current_trackname != previous_polled_trackname:
            if remote_debug_key != "":
                print("Current track " + current_trackname +
                      " is not same as previous track " +
                      previous_polled_trackname)

            # update previous trackname so we know what has changed in future
            previous_polled_trackname = current_trackname

            # slim down the trackname
            if sonos_settings.demaster:
                current_trackname = demaster.strip_name(current_trackname)
                if remote_debug_key != "":
                    print("Demastered to " + current_trackname)

            # set the details we need from the API into variables
            track_name.set(current_trackname)
            detail_text.set(current_artist + " • " + current_album)

            # pull the image from the uri provided
            image_url = current_image

            image_failed_to_load = False
            try:
                image_url_response = requests.get(
                    image_url, timeout=sonos_user_data.DEFAULT_TIMEOUT)
                pil_image = Image.open(BytesIO(image_url_response.content))
            except:
                pil_image = Image.open(sys.path[0] + "/sonos.png")
                target_image_width = 500
                print("Image failed to load so showing standard sonos logo")

            # set the image size based on whether we are showing track details as well
            if sonos_settings.show_details == True:
                target_image_width = thumbwidth
            else:
                target_image_width = screenwidth

            # resize the image
            wpercent = (target_image_width / float(pil_image.size[0]))
            hsize = int((float(pil_image.size[1]) * float(wpercent)))
            pil_image = pil_image.resize((target_image_width, hsize),
                                         Image.ANTIALIAS)

            set_backlight_power(True)
            tk_image = ImageTk.PhotoImage(pil_image)
            label_albumart.configure(image=tk_image)

    if playing_status == "API error":
        if remote_debug_key != "": print("API error reported fyi")
        time.sleep(5)

    if playing_status != "PLAYING":
        set_backlight_power(False)
        track_name.set("")
        detail_text.set("")
        label_albumart.configure(image="")
        previous_polled_trackname = ""
        if remote_debug_key != "": print("Track not playing - doing nothing")

    # Schedule the poll() function for another 500 ms from now
    root.after(500, update)
Beispiel #5
0
    # check if anything is playing
    if play_status == "PLAYING":
        # wake from sleep mode if we're in it
        sleep_mode_sleeping = False
        number_of_sheep_counted = 0
       
        # see if there is new data to display
        if current_track == previous_track_name:  #check if the track name is same as what we displayed last time
            print ("no change to data - not refreshing")
        else:
            print ("new data found from api - refreshing screen")
            previous_track_name = current_track

            # demaster the track name if set to do so
            if sonos_settings.demaster == True:
                current_track = demaster.strip_name (current_track)

            #print to the ink
            ink_printer.print_text_to_ink (current_track, current_artist, current_album)

            # keep a record of the previous track name to see if it changes next time
    else:
        # nothing is playing right now

        # ... but check whether this is just a momentary pause
        if number_of_sheep_counted <= sleep_mode_sheep_to_count:
            # not enough sleep counted yet to go to sleep - add one
            number_of_sheep_counted = number_of_sheep_counted + 1
            print ("Counting " + str(number_of_sheep_counted) + " sheep")
        
        else: