1313"""
1414
1515import requests
16+ import json
1617
1718TIMEOUT = 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 })
0 commit comments