Skip to content

Commit

Permalink
Merge pull request #2 from ur1katz/feature_clear_and_playlist
Browse files Browse the repository at this point in the history
Minor version 0.2.0 Adds:
* Clear play queue
* Play playlists
  • Loading branch information
ur1katz authored Sep 21, 2018
2 parents d71d368 + d0c6a21 commit b2852fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ pip install casttube

**Features**
* Play video
* Play a playlist
* Add video to the end of the play queue
* Play next
* Remove video
* Clear the entire queue

```
from casttube import YouTubeSession
Expand Down
14 changes: 10 additions & 4 deletions casttube/YouTubeSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
COUNT = "count"

ACTION_SET_PLAYLIST = "setPlaylist"
ACTION_CLEAR = "clearPlaylist"
ACTION_REMOVE = "removeVideo"
ACTION_INSERT = "insertVideo"
ACTION_ADD = "addVideo"


GSESSIONID = "gsessionid"
CVER = "CVER"
RID = "RID"
Expand Down Expand Up @@ -55,14 +57,15 @@ def in_session(self):
else:
return False

def play_video(self, video_id):
def play_video(self, video_id, list_id=""):
"""
Play video(video_id) now. This ignores the current play queue order.
:param list_id: list id for playing playlist ...youtube.com/watch?v=VIDEO_ID&list=LIST_ID
:param video_id: YouTube video id(http://youtube.com/watch?v=video_id)
"""
# We always want to start a new session here to ensure an empty queue.
self._start_session()
self._initialize_queue(video_id)
self._initialize_queue(video_id, list_id)

def add_to_queue(self, video_id):
"""
Expand All @@ -85,6 +88,9 @@ def remove_video(self, video_id):
"""
self._queue_action(video_id, ACTION_REMOVE)

def clear_playlist(self):
self._queue_action('', ACTION_CLEAR)

def _start_session(self):
self._get_lounge_id()
self._bind()
Expand Down Expand Up @@ -120,11 +126,11 @@ def _bind(self):
self._sid = sid.group(1)
self._gsession_id = gsessionid.group(1)

def _initialize_queue(self, video_id):
def _initialize_queue(self, video_id, list_id=""):
"""
Initialize a queue with a video and start playing that video.
"""
request_data = {LIST_ID: "",
request_data = {LIST_ID: list_id,
ACTION: ACTION_SET_PLAYLIST,
CURRENT_TIME: "0",
CURRENT_INDEX: -1,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = fh.read()

setup(name='casttube',
version='0.1.0',
version='0.2.0',
description='YouTube chromecast api',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit b2852fb

Please sign in to comment.