Skip to content

Commit

Permalink
Merge pull request #1 from XenosLu/master
Browse files Browse the repository at this point in the history
Added seek, get_volume, position_info function
  • Loading branch information
ttopholm authored Jun 26, 2017
2 parents b53c8d1 + b492d4b commit dd85a90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Simple network player for DLNA/UPnP devices allows you discover devices and play
## TODO
- [ ] Fix '&' bug
- [ ] Set next media
- [ ] Volume control
- [x] Volume control
- [ ] Position control
- [ ] Add support to play media from local machine, e.g --play /home/username/media/music.mp3 for py3
- [ ] Try it on Windows
- [ ] Add AVTransport:2 and further support
Expand Down
34 changes: 34 additions & 0 deletions dlnap/dlnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ def stop(self, instance_id = 0):
packet = self._create_packet('Stop', {'InstanceID': instance_id, 'Speed': 1})
_send_tcp((self.ip, self.port), packet)


def seek(self, position, instance_id = 0):
"""
Seek position
"""
packet = self._create_packet('Seek', {'InstanceID':instance_id, 'Unit':'REL_TIME', 'Target': position })
_send_tcp((self.ip, self.port), packet)


def volume(self, volume=10, instance_id = 0):
""" Stop media that is currently playing back.
Expand All @@ -523,6 +532,14 @@ def volume(self, volume=10, instance_id = 0):
packet = self._create_packet('SetVolume', {'InstanceID': instance_id, 'DesiredVolume': volume, 'Channel': 'Master'})

_send_tcp((self.ip, self.port), packet)


def get_volume(self, vol, instance_id = 0):
"""
get volume
"""
packet = self._create_packet('GetVolume', {'InstanceID':instance_id, 'Channel': 'Master'})
_send_tcp((self.ip, self.port), packet)


def mute(self, instance_id = 0):
Expand Down Expand Up @@ -557,6 +574,15 @@ def media_info(self, instance_id=0):
packet = self._create_packet('GetMediaInfo', {'InstanceID': instance_id})
return _send_tcp((self.ip, self.port), packet)


def position_info(self, instance_id=0):
""" Position info.
instance_id -- device instance id
"""
packet = self._create_packet('GetPositionInfo', {'InstanceID': instance_id})
return _send_tcp((self.ip, self.port), packet)


def set_next(self, url):
pass

Expand Down Expand Up @@ -629,6 +655,7 @@ def usage():
print(' --mute - mute playback')
print(' --unmute - unmute playback')
print(' --volume <vol> - set current volume for playback')
print(' --seek <position in HH:MM:SS> - set current position for playback')
print(' --timeout <seconds> - discover timeout')
print(' --ssdp-version <version> - discover devices by protocol version, default 1')
print(' --proxy - use local proxy on proxy port')
Expand All @@ -655,6 +682,7 @@ def version():
'volume=',
'mute',
'unmute',
'seek=',


# discover arguments
Expand All @@ -677,6 +705,7 @@ def version():
device = ''
url = ''
vol = 10
position = '00:00:00'
timeout = 1
action = ''
logLevel = logging.WARN
Expand Down Expand Up @@ -723,6 +752,9 @@ def version():
elif opt in ('--volume'):
action = 'volume'
vol = arg
elif opt in ('--seek'):
action = 'seek'
position = arg
elif opt in ('--mute'):
action = 'mute'
elif opt in ('--unmute'):
Expand Down Expand Up @@ -783,6 +815,8 @@ def version():
d.stop()
elif action == 'volume':
d.volume(vol)
elif action == 'seek':
d.seek(position)
elif action == 'mute':
d.mute()
elif action == 'unmute':
Expand Down

0 comments on commit dd85a90

Please sign in to comment.