Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion dlnap/dlnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# 1.0 moved from idea version

__version__ = "0.15"
__version__ = "0.16"

import re
import sys
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -678,6 +688,7 @@ def usage():
print(' --device <device name or part of the name> - discover devices with this name as substring')
print(' --all - flag to discover all upnp devices, not only devices with AVTransport ability')
print(' --play <url> - set current url for play and start playback it. In case of url is empty - continue playing recent media.')
print(' --urlNext <url> - set next url for play, only work without a proxy.')
print(' --pause - pause current playback')
print(' --stop - stop current playback')
print(' --mute - mute playback')
Expand Down Expand Up @@ -711,6 +722,7 @@ def version():
'mute',
'unmute',
'seek=',
'urlNext=',


# discover arguments
Expand All @@ -732,6 +744,7 @@ def version():

device = ''
url = ''
urlNext = ''
vol = 10
position = '00:00:00'
timeout = 1
Expand All @@ -743,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)
Expand Down Expand Up @@ -796,6 +812,7 @@ def version():
elif opt in ('--proxy-port'):
proxy_port = int(arg)


logging.basicConfig(level=logLevel)

st = URN_AVTransport_Fmt if compatibleOnly else SSDP_ALL
Expand All @@ -818,6 +835,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

Expand All @@ -827,12 +849,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.')
Expand All @@ -854,6 +880,10 @@ def version():
print(d.info())
elif action == 'media-info':
print(d.media_info())
elif action == 'urlNext':
d.set_next_media(url=urlNext)

print(action)

if proxy:
while running:
Expand Down