From 17d6605941b4b4076676d9bb14c40ca565ee5b58 Mon Sep 17 00:00:00 2001 From: Sparkle Date: Wed, 5 Feb 2020 23:37:35 +0800 Subject: [PATCH 1/3] add urlNext for continuous play --- dlnap/dlnap.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/dlnap/dlnap.py b/dlnap/dlnap.py index 97b6acb..985daaf 100755 --- a/dlnap/dlnap.py +++ b/dlnap/dlnap.py @@ -23,7 +23,7 @@ # # 1.0 moved from idea version -__version__ = "0.15" +__version__ = "0.16" import re import sys @@ -510,6 +510,16 @@ def set_current_media(self, url, instance_id = 0): packet = self._create_packet('SetAVTransportURI', {'InstanceID':instance_id, 'CurrentURI':url, 'CurrentURIMetaData':'' }) _send_tcp((self.ip, self.port), packet) + def set_next_media(self, url, instance_id=0): + """ Set next media to playback. + + url -- next media url + instance_id -- device instance id + """ + packet = self._create_packet('SetNextAVTransportURI', {'InstanceID': instance_id, 'NextURI': url, 'NextURIMetaData': ''}) + _send_tcp((self.ip, self.port), packet) + + def play(self, instance_id = 0): """ Play media that was already set as current. @@ -678,6 +688,7 @@ def usage(): print(' --device - discover devices with this name as substring') print(' --all - flag to discover all upnp devices, not only devices with AVTransport ability') print(' --play - set current url for play and start playback it. In case of url is empty - continue playing recent media.') + print(' --urlNext - set next url for play, only work without a proxy.') print(' --pause - pause current playback') print(' --stop - stop current playback') print(' --mute - mute playback') @@ -711,6 +722,7 @@ def version(): 'mute', 'unmute', 'seek=', + 'urlNext=', # discover arguments @@ -732,6 +744,7 @@ def version(): device = '' url = '' + urlNext = '' vol = 10 position = '00:00:00' timeout = 1 @@ -795,6 +808,8 @@ def version(): proxy = True elif opt in ('--proxy-port'): proxy_port = int(arg) + elif opt in ('--urlNext'): + urlNext = arg logging.basicConfig(level=logLevel) @@ -818,6 +833,11 @@ def version(): process = subprocess.Popen(['youtube-dl', '-g', url], stdout = subprocess.PIPE) url, err = process.communicate() + if urlNext.lower().replace('https://', '').replace('www.', '').startswith('youtube.'): + import subprocess + process = subprocess.Popen(['youtube-dl', '-g', urlNext], stdout = subprocess.PIPE) + urlNext, err = process.communicate() + if url.lower().startswith('https://'): proxy = True @@ -827,12 +847,16 @@ def version(): t.daemon = True t.start() time.sleep(2) + if urlNext: + urlNext = None if action == 'play': try: d.stop() url = 'http://{}:{}/{}'.format(ip, proxy_port, url) if proxy else url d.set_current_media(url=url) + if not proxy and urlNext: + d.set_next_media(url=urlNext) d.play() except Exception as e: print('Device is unable to play media.') From ba6afba4a5a1c8442dcd6c0788958ff919c13d54 Mon Sep 17 00:00:00 2001 From: Sparkle Date: Wed, 5 Feb 2020 23:54:02 +0800 Subject: [PATCH 2/3] set urlNext without play --- dlnap/dlnap.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dlnap/dlnap.py b/dlnap/dlnap.py index 985daaf..50f9f40 100755 --- a/dlnap/dlnap.py +++ b/dlnap/dlnap.py @@ -878,6 +878,8 @@ def version(): print(d.info()) elif action == 'media-info': print(d.media_info()) + elif urlNext: + d.set_next_media(url=urlNext) if proxy: while running: From f67c8b6d9b29d778522bfd9bb49500f9620678d1 Mon Sep 17 00:00:00 2001 From: Sparkle Date: Thu, 6 Feb 2020 00:13:19 +0800 Subject: [PATCH 3/3] add urlNext, can use without play --- dlnap/dlnap.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dlnap/dlnap.py b/dlnap/dlnap.py index 50f9f40..85307dc 100755 --- a/dlnap/dlnap.py +++ b/dlnap/dlnap.py @@ -756,6 +756,9 @@ def version(): proxy_port = 8000 ssdp_version = 1 for opt, arg in opts: + if opt in ('--urlNext'): + action = 'urlNext' + urlNext = arg if opt in ('-h', '--help'): usage() sys.exit(0) @@ -808,8 +811,7 @@ def version(): proxy = True elif opt in ('--proxy-port'): proxy_port = int(arg) - elif opt in ('--urlNext'): - urlNext = arg + logging.basicConfig(level=logLevel) @@ -878,8 +880,10 @@ def version(): print(d.info()) elif action == 'media-info': print(d.media_info()) - elif urlNext: + elif action == 'urlNext': d.set_next_media(url=urlNext) + + print(action) if proxy: while running: