From 838c88af61005b9851cb15bd27818a024905dbfe Mon Sep 17 00:00:00 2001 From: Raimund Meyer Date: Thu, 3 Feb 2022 01:20:29 +0100 Subject: [PATCH 1/2] Support spotifyconnect (volatile service, without queue) --- plugins/miscellanea/pirateaudio/display.py | 53 ++++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/plugins/miscellanea/pirateaudio/display.py b/plugins/miscellanea/pirateaudio/display.py index fa612491b..41da6bf1e 100644 --- a/plugins/miscellanea/pirateaudio/display.py +++ b/plugins/miscellanea/pirateaudio/display.py @@ -79,7 +79,7 @@ position = '' # v.0.0.4 nav_array_name, nav_array_uri, nav_array_type, nav_array_service = [], [], [], [] marker, listmax, liststart, listresult = 0, int(obj['listmax']['value']), 0, 0 - +volatile_service = False BUTTONS = [5, 6, 16, obj['gpio_ybutton']['value']] # LABELS = ['A', 'B', 'X', 'Y'] @@ -261,6 +261,11 @@ def display_stuff(picture, text, marked, start, icons='nav'): # v.0.0.4 test fo display_stuff('bg_default', obj_trans['DISPLAY']['WAIT'], 0, 0, 'info') socketIO = SocketIO('localhost', 3000) +def display_prevnext(): + if volatile_service: + display_stuff('bg_default', [obj_trans['DISPLAY']['PREVNEXT'], title], 1, 0, 'seek') + else: + display_stuff('bg_default', [str(position + 1) + '/' + str(len_queue), obj_trans['DISPLAY']['PREVNEXT'], title_queue[position]], 1, 0, 'seek') def seeking(direction): # start_time = time.time() # debug, time of code execution @@ -280,22 +285,25 @@ def seeking(direction): def prevnext(direction): - # start_time = time.time() # debug, time of code execution - global position - if direction == 'prev': - position -= 1 + if volatile_service is True: + socketIO.emit(direction) else: - position += 1 - if position > len_queue - 1: # set position to first entry to loop through playlist infinite - position = 0 - elif position < 0: # set position to last entry to loop through playlist infinite - position = len_queue - 1 - display_stuff('bg_default', [str(position + 1) + '/' + str(len_queue), obj_trans['DISPLAY']['PREVNEXT'], title_queue[position]], 1, 0, 'seek') - socketIO.emit('stop') - socketIO.emit('play', {"value": position}) - # print("prevnext--- %s seconds ---" % (time.time() - start_time)) # debug, time of code execution - - + # start_time = time.time() # debug, time of code execution + global position + if direction == 'prev': + position -= 1 + else: + position += 1 + if position > len_queue - 1: # set position to first entry to loop through playlist infinite + position = 0 + elif position < 0: # set position to last entry to loop through playlist infinite + position = len_queue - 1 + display_prevnext() + socketIO.emit('stop') + socketIO.emit('play', {"value": position}) + # print("prevnext--- %s seconds ---" % (time.time() - start_time)) # debug, time of code execution + + def on_push_queue(*args): global title_queue, len_queue # reset variables first @@ -310,7 +318,7 @@ def on_push_queue(*args): def on_push_state(*args): # start_time = time.time() # debug, time of code execution - global img, img2, dark, txt_col, str_col, bar_bgcol, bar_col, status, service, volume, albumart, img_check, mode, seek, duration, position + global img, img2, dark, txt_col, str_col, bar_bgcol, bar_col, status, service, volume, title, albumart, img_check, mode, seek, duration, position, volatile_service def f_textsize(text, fontsize): w1, y1 = draw.textsize(text, fontsize) @@ -336,7 +344,11 @@ def f_content(field, fontsize, top, shadowoffset=1): # return args[0][field] volume = int(args[0]['volume']) - position = args[0]['position'] # v.0.0.4 + if 'position' in args[0]: + position = args[0]['position'] # v.0.0.4 + volatile_service = args[0]['volatile'] + title = args[0]['title'] + if mode == 'player': #status = args[0]['status'].encode('ascii', 'ignore') status = args[0]['status'] # v0.0.6 @@ -435,7 +447,8 @@ def f_content(field, fontsize, top, shadowoffset=1): img_check = img sendtodisplay(img) # print("on_push_state--- %s seconds ---" % (time.time() - start_time)) # debug, time of code execution - + if (mode == 'prevnext' and volatile_service is True): + display_prevnext() img = Image.new('RGBA', (240, 240), color=(0, 0, 0, 25)) draw = ImageDraw.Draw(img, 'RGBA') @@ -509,7 +522,7 @@ def handle_button(pin): elif nav_array_type[marker] == 'prevnext': # v.0.0.4 socketIO.emit('getQueue', on_push_queue) # refresh variables of queue mode = 'prevnext' - display_stuff('bg_default', [str(position + 1) + '/' + str(len_queue), obj_trans['DISPLAY']['PREVNEXT'], title_queue[position]], 1, 0, 'seek') + display_prevnext() else: # browsesource reset_variable('navigation') socketIO.emit('getBrowseSources', '', on_push_browsesources) From 8470b1f023ba614508b5b8d342548fcbd057ef4a Mon Sep 17 00:00:00 2001 From: Raimund Meyer Date: Sat, 5 Feb 2022 21:30:33 +0100 Subject: [PATCH 2/2] volatile may not be set --- plugins/miscellanea/pirateaudio/display.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/miscellanea/pirateaudio/display.py b/plugins/miscellanea/pirateaudio/display.py index 41da6bf1e..6a0b3681a 100644 --- a/plugins/miscellanea/pirateaudio/display.py +++ b/plugins/miscellanea/pirateaudio/display.py @@ -346,7 +346,11 @@ def f_content(field, fontsize, top, shadowoffset=1): volume = int(args[0]['volume']) if 'position' in args[0]: position = args[0]['position'] # v.0.0.4 - volatile_service = args[0]['volatile'] + if 'volatile' in args[0]: + volatile_service = args[0]['volatile'] + else: + volatile_service = False + title = args[0]['title'] if mode == 'player':