Skip to content

Commit

Permalink
develop #comment rename playlistId to playlist_id.
Browse files Browse the repository at this point in the history
 - Now display the playlist ID when logging a video object.
  • Loading branch information
Luc Sinet committed Jan 11, 2019
1 parent 998d9f5 commit e743d2b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions RaspberryCast/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def queue(self, video, first=False):
logger.info("[player] queue video: {}".format(video))
# Position the video with the videos of the same playlist.
index = 0 if first else len(self._queue)
if first and video.playlistId is not None:
if first and video.playlist_id is not None:
for i, v in enumerate(reversed(self._queue)):
if v.playlistId == video.playlistId:
if v.playlist_id == video.playlist_id:
index = len(self._queue) - i
break
self._queue.insert(index, video)
Expand Down
2 changes: 1 addition & 1 deletion RaspberryCast/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _video(self):
logger.debug("Control command received: {}".format(control))

if control == 'pause':
self._controller.play_pause_video(True)
self._controller.play_pause_video()
elif control == 'stop':
self._controller.stop_video()
elif control == 'right':
Expand Down
29 changes: 16 additions & 13 deletions RaspberryCast/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@


class Video(object):
def __init__(self, url, playlistId=None):
def __init__(self, url, playlist_id=None):
self._url = url
self._playlistId = playlistId
self._playlist_id = playlist_id
self._path = None
self._title = None
self._subtitles = []

path = Path(url)
if path.is_file():
self.path = url
self._playlistId = self._path.parent
self._playlist_id = self._path.parent
self._title = self._path.name

def __repr__(self):
title = '' if self._title is None else str(self._title)
playlist_id = '' if self._playlist_id is None else str(self._playlist_id)
return str({'title': title,
'url': str(self._url),
'playlist_id': playlist_id})

def __eq__(self, other):
return (self._url is other._url and
self._playlist_id is other._playlist_id)

@property
def url(self):
return self._url
Expand All @@ -46,16 +57,8 @@ def title(self, title):
self._title = str(title.encode('ascii', 'ignore'))

@property
def playlistId(self):
return self._playlistId

def __repr__(self):
title = '' if self._title is None else str(self._title)
return str({'title': title, 'url': str(self._url)})

def __eq__(self, other):
return (self._url is other._url and
self._playlistId is other._playlistId)
def playlist_id(self):
return self._playlist_id

def is_local(self):
return self._path is not None
Expand Down
4 changes: 2 additions & 2 deletions RaspberryCast/video_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def _queue_video(self, video, dl_callback, first):
if '/playlist' in video.url:
logger.debug("[controller] playlist detected, unfolding...")
# Generate a unique ID for the playlist
playlistId = uuid.uuid4()
playlist_id = uuid.uuid4()
urls = self._downloader.extract_playlist(video.url)
videos = [Video(u, playlistId) for u in urls]
videos = [Video(u, playlist_id) for u in urls]
logger.debug("[controller] playlist url unfolded to {}"
.format(videos))
self._downloader.queue(videos, dl_callback, first)
Expand Down
4 changes: 2 additions & 2 deletions RaspberryCast/video_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def _queue_downloads(self, videos, dl_callback, first):
continue
# Position the video with the videos of the same playlist.
index = 0 if first else len(self._queue)
if first and video.playlistId is not None:
if first and video.playlist_id is not None:
for i, v in enumerate(reversed(self._queue)):
if v[0].playlistId == video.playlistId:
if v[0].playlist_id == video.playlist_id:
index = len(self._queue) - i
break
logger.info("[downloader] queue video {}".format(video))
Expand Down
14 changes: 7 additions & 7 deletions test/video_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ def test_construction_from_url(self):
video = Video(url)

self.assertEqual(video.url, url)
self.assertIsNone(video.playlistId)
self.assertIsNone(video.playlist_id)
self.assertIsNone(video.path)
self.assertIsNone(video.title)
self.assertEmpty(video.subtitles)

def test_construction_from_playlist_url(self):
url = 'https://domain.com/video=test&playlist=playlist'
playlistId = 'id'
video = Video(url, playlistId)
playlist_id = 'id'
video = Video(url, playlist_id)

self.assertEqual(video.url, url)
self.assertEqual(video.playlistId, playlistId)
self.assertEqual(video.playlist_id, playlist_id)
self.assertIsNone(video.path)
self.assertIsNone(video.title)
self.assertEmpty(video.subtitles)
Expand All @@ -37,7 +37,7 @@ def test_construction_from_path(self):
self.make_file(path)

self.assertEqual(video.url, path)
self.assertEqual(video.playlistId, Path(path).parent)
self.assertEqual(video.playlist_id, Path(path).parent)
self.assertEqual(video.path, Path(path))
self.assertEqual(video.title, 'test')
self.assertEmpty(video.subtitles)
Expand All @@ -51,5 +51,5 @@ def test_local_video_same_parent(self):
self.make_file('/tmp/foo')
self.make_file('/tmp/bar')

self.assertEqual(Video('/tmp/foo').playlistId,
Video('/tmp/bar').playlistId)
self.assertEqual(Video('/tmp/foo').playlist_id,
Video('/tmp/bar').playlist_id)

0 comments on commit e743d2b

Please sign in to comment.