You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.0 KiB

  1. # Copyright 2015 Adafruit Industries.
  2. # Author: Tony DiCola
  3. # License: GNU GPLv2, see LICENSE.txt
  4. class Playlist(object):
  5. """Representation of a playlist of movies."""
  6. def __init__(self, movies):
  7. """Create a playlist from the provided list of movies."""
  8. self._movies = movies
  9. self._index = None
  10. def get_next(self):
  11. """Get the next movie in the playlist. Will loop to start of playlist
  12. after reaching end.
  13. """
  14. # Check if no movies are in the playlist and return nothing.
  15. if len(self._movies) == 0:
  16. return None
  17. # Start at the first movie and increment through them in order.
  18. if self._index is None:
  19. self._index = 0
  20. else:
  21. self._index += 1
  22. # Wrap around to the start after finishing.
  23. if self._index >= len(self._movies):
  24. self._index = 0
  25. return self._movies[self._index]
  26. def length(self):
  27. """Return the number of movies in the playlist."""
  28. return len(self._movies)