Skip to content

Commit ae1fb03

Browse files
authored
Merge pull request #2 from fancybits/add-new-endpoints
Add New Endpoints
2 parents 080f269 + c53a669 commit ae1fb03

File tree

3 files changed

+75
-31
lines changed

3 files changed

+75
-31
lines changed

README.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,52 +103,72 @@ This returns an array of channel Dicts. Here's an example.
103103
You can control Channels with these methods.
104104

105105
#### Toggle Mute
106-
client.toggle_mute()
106+
client.toggle_mute
107+
108+
#### Toggle Captions
109+
client.toggle_cc
110+
111+
#### Channel Up
112+
client.channel_up
113+
114+
#### Channel Down
115+
client.channel_down
116+
117+
#### Previous Channel
118+
client.previous_channel
119+
Jump back to the last watched channel.
107120

108121
#### Toggle Pause
109-
client.toggle_pause()
122+
client.toggle_pause
123+
124+
#### Toggle Recording
125+
client.toggle_record
126+
Record the program playing on the current channel
110127

111128
#### Pause
112-
client.pause()
129+
client.pause
113130

114131
#### Resume
115-
client.resume()
132+
client.resume
116133

117134
#### Stop
118-
client.stop()
135+
client.stop
119136

120137
#### Seek By
121138
client.seek_by(seconds)
122139
Seek forward or backward on the timeline with an inputted number of seconds. Negative values go backward.
123140

124141
#### Seek Forward
125-
client.seek_forward()
142+
client.seek_forward
126143
Seek forward in the timeline by the set number of seconds in Channels.
127144

128-
#### Seek Backward
129-
client.seek_backward()
130-
Seek backward in the timeline by the set number of seconds in Channels.
131-
132145
#### Skip Forward
133-
client.skip_forward()
146+
client.skip_forward
134147
Skip to the next chapter mark. This is for recordings made with Channels DVR that have their commercials indexed.
135148

149+
#### Seek Backward
150+
client.seek_backward
151+
Seek backward in the timeline by the set number of seconds in Channels.
152+
136153
#### Skip Backward
137-
client.skip_backward()
154+
client.skip_backward
138155
Skip to the previous chapter mark. This is for recordings made with Channels DVR that have their commercials indexed.
139156

140-
#### Previous Channel
141-
client.previous_channel()
142-
Jump back to the last watched channel.
143-
144-
145157
#### Play Channel
146158
client.play_channel(channel_number)
147159
Play a channel by passing it the channel number.
148160

149161
#### Play Recording
150162
client.play_recording(recording_id)
151-
Play a recording from Channels DVR
163+
Play a recording from Channels.
164+
165+
#### Navigate
166+
client.navigate(section)
167+
Change to a section of the app by providing its name. EX, `Guide`, `Library`, `Live TV`
168+
169+
#### Notify
170+
client.notify(title, message)
171+
Present a notification while playing video.
152172

153173
## Contributions
154174

pychannels/__init__.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
import requests
16+
import json
1617

1718
TIMEOUT = 1
1819

@@ -30,16 +31,17 @@ def _base_url(self):
3031
def _request(self, method, path, params=None):
3132
"""Make the actual request and returns the parsed response."""
3233
url = self._base_url + path
34+
headers = {'Content-Type': 'application/json'}
3335

3436
try:
3537
if method == 'GET':
36-
response = requests.get(url, timeout=TIMEOUT)
38+
response = requests.get(url, timeout=TIMEOUT, headers=headers)
3739
elif method == "POST":
38-
response = requests.post(url, params, timeout=TIMEOUT)
40+
response = requests.post(url, json=params, timeout=TIMEOUT, headers=headers)
3941
elif method == "PUT":
40-
response = requests.put(url, params, timeout=TIMEOUT)
42+
response = requests.put(url, json=params, timeout=TIMEOUT, headers=headers)
4143
elif method == "DELETE":
42-
response = requests.delete(url, timeout=TIMEOUT)
44+
response = requests.delete(url, timeout=TIMEOUT, headers=headers)
4345

4446
if response:
4547
return response.json()
@@ -68,6 +70,26 @@ def favorite_channels(self):
6870
else:
6971
return []
7072

73+
def toggle_mute(self):
74+
"""Toggle mute state and returns the current state."""
75+
return self._command('toggle_mute')
76+
77+
def toggle_cc(self):
78+
"""Toggle captions state and returns the current state."""
79+
return self._command('toggle_cc')
80+
81+
def channel_up(self):
82+
"""Change the channel and returns the current state."""
83+
return self._command('channel_up')
84+
85+
def channel_down(self):
86+
"""Change the channel and returns the current state."""
87+
return self._command('channel_down')
88+
89+
def previous_channel(self):
90+
"""Jump back to the last channel."""
91+
return self._command('previous_channel')
92+
7193
def toggle_pause(self):
7294
"""Toggle paused state and returns the current state."""
7395
return self._command('toggle_pause')
@@ -105,20 +127,22 @@ def skip_backward(self):
105127
"""Skip backward to the previous chapter mark."""
106128
return self._command('skip_backward')
107129

108-
def previous_channel(self):
109-
"""Jump back to the last channel."""
110-
return self._command('previous_channel')
111-
112130
def toggle_muted(self):
113131
"""Mute and returns the current state."""
114132
return self._command('toggle_mute')
115133

116134
def play_channel(self, channel_number):
117135
"""Set a channel to play and returns the current state."""
118-
return self._request('POST', '/api/play/channel/' +
119-
str(channel_number))
136+
return self._command('play/channel/' + str(channel_number))
120137

121138
def play_recording(self, recording_id):
122139
"""Set a recording to play and returns the current state."""
123-
return self._request('POST', '/api/play/recording/' +
124-
str(recording_id))
140+
return self._command('play/recording/' + str(recording_id))
141+
142+
def navigate(self, section):
143+
"""Change to a section of the app by providing its name and returns success status"""
144+
return self._command('navigate/' + section)
145+
146+
def notify(self, title, message):
147+
"""Present a notification while playing video and returns success status."""
148+
return self._request('POST', '/api/notify', {'title': title, 'message': message})

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pychannels',
5-
version="1.1.0",
5+
version="1.2.0",
66
packages=['pychannels',],
77
license='The MIT License',
88
description = 'API client for the Channels app - https://getchannels.com',

0 commit comments

Comments
 (0)