Skip to content

Commit

Permalink
Merge pull request #2 from fancybits/add-new-endpoints
Browse files Browse the repository at this point in the history
Add New Endpoints
  • Loading branch information
maddox authored Aug 7, 2020
2 parents 080f269 + c53a669 commit ae1fb03
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 31 deletions.
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,52 +103,72 @@ This returns an array of channel Dicts. Here's an example.
You can control Channels with these methods.

#### Toggle Mute
client.toggle_mute()
client.toggle_mute

#### Toggle Captions
client.toggle_cc

#### Channel Up
client.channel_up

#### Channel Down
client.channel_down

#### Previous Channel
client.previous_channel
Jump back to the last watched channel.

#### Toggle Pause
client.toggle_pause()
client.toggle_pause

#### Toggle Recording
client.toggle_record
Record the program playing on the current channel

#### Pause
client.pause()
client.pause

#### Resume
client.resume()
client.resume

#### Stop
client.stop()
client.stop

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

#### Seek Forward
client.seek_forward()
client.seek_forward
Seek forward in the timeline by the set number of seconds in Channels.

#### Seek Backward
client.seek_backward()
Seek backward in the timeline by the set number of seconds in Channels.

#### Skip Forward
client.skip_forward()
client.skip_forward
Skip to the next chapter mark. This is for recordings made with Channels DVR that have their commercials indexed.

#### Seek Backward
client.seek_backward
Seek backward in the timeline by the set number of seconds in Channels.

#### Skip Backward
client.skip_backward()
client.skip_backward
Skip to the previous chapter mark. This is for recordings made with Channels DVR that have their commercials indexed.

#### Previous Channel
client.previous_channel()
Jump back to the last watched channel.


#### Play Channel
client.play_channel(channel_number)
Play a channel by passing it the channel number.

#### Play Recording
client.play_recording(recording_id)
Play a recording from Channels DVR
Play a recording from Channels.

#### Navigate
client.navigate(section)
Change to a section of the app by providing its name. EX, `Guide`, `Library`, `Live TV`

#### Notify
client.notify(title, message)
Present a notification while playing video.

## Contributions

Expand Down
48 changes: 36 additions & 12 deletions pychannels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import requests
import json

TIMEOUT = 1

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

try:
if method == 'GET':
response = requests.get(url, timeout=TIMEOUT)
response = requests.get(url, timeout=TIMEOUT, headers=headers)
elif method == "POST":
response = requests.post(url, params, timeout=TIMEOUT)
response = requests.post(url, json=params, timeout=TIMEOUT, headers=headers)
elif method == "PUT":
response = requests.put(url, params, timeout=TIMEOUT)
response = requests.put(url, json=params, timeout=TIMEOUT, headers=headers)
elif method == "DELETE":
response = requests.delete(url, timeout=TIMEOUT)
response = requests.delete(url, timeout=TIMEOUT, headers=headers)

if response:
return response.json()
Expand Down Expand Up @@ -68,6 +70,26 @@ def favorite_channels(self):
else:
return []

def toggle_mute(self):
"""Toggle mute state and returns the current state."""
return self._command('toggle_mute')

def toggle_cc(self):
"""Toggle captions state and returns the current state."""
return self._command('toggle_cc')

def channel_up(self):
"""Change the channel and returns the current state."""
return self._command('channel_up')

def channel_down(self):
"""Change the channel and returns the current state."""
return self._command('channel_down')

def previous_channel(self):
"""Jump back to the last channel."""
return self._command('previous_channel')

def toggle_pause(self):
"""Toggle paused state and returns the current state."""
return self._command('toggle_pause')
Expand Down Expand Up @@ -105,20 +127,22 @@ def skip_backward(self):
"""Skip backward to the previous chapter mark."""
return self._command('skip_backward')

def previous_channel(self):
"""Jump back to the last channel."""
return self._command('previous_channel')

def toggle_muted(self):
"""Mute and returns the current state."""
return self._command('toggle_mute')

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

def play_recording(self, recording_id):
"""Set a recording to play and returns the current state."""
return self._request('POST', '/api/play/recording/' +
str(recording_id))
return self._command('play/recording/' + str(recording_id))

def navigate(self, section):
"""Change to a section of the app by providing its name and returns success status"""
return self._command('navigate/' + section)

def notify(self, title, message):
"""Present a notification while playing video and returns success status."""
return self._request('POST', '/api/notify', {'title': title, 'message': message})
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pychannels',
version="1.1.0",
version="1.2.0",
packages=['pychannels',],
license='The MIT License',
description = 'API client for the Channels app - https://getchannels.com',
Expand Down

0 comments on commit ae1fb03

Please sign in to comment.