-
Notifications
You must be signed in to change notification settings - Fork 43
/
playlist.py
83 lines (62 loc) · 2.42 KB
/
playlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# *************************************
# PLAYLIST CLASS
# ************************************
class PlayList():
"""https://en.wikipedia.org/wiki/Media_type
manages a playlist of tracks and the track selected from the playlist
"""
#field definition constants
LOCATION=0
TITLE=1
LOCATION_BACKUP=2
# template for a new track
_new_track=['','','']
def __init__(self, YTDL_WAIT_TAG):
self.YTDL_WAIT_TAG = YTDL_WAIT_TAG
self._num_tracks=0
self._tracks = [] # list of track titles
self._selected_track = PlayList._new_track
self._selected_track_index = -1 # index of currently selected track
def length(self):
return self._num_tracks
def track_is_selected(self):
if self._selected_track_index>=0:
return True
else:
return False
def selected_track_index(self):
return self._selected_track_index
def selected_track(self):
return self._selected_track
def append(self, track):
"""appends a track to the end of the playlist store"""
self._tracks.append(track)
self._num_tracks+=1
def remove(self,index):
self._tracks.pop(index)
self._num_tracks-=1
# is the deleted track always the selcted one?
self._selected_track_index=-1
def clear(self):
self._tracks = []
self._num_tracks=0
self._track_locations = []
self._selected_track_index=-1
self.selected_track_title=""
self.selected_track_location=""
def replace(self,index,replacement):
self._tracks[index]= replacement
def select(self,index):
"""does housekeeping necessary when a track is selected"""
if self._num_tracks>0 and index<= self._num_tracks:
# save location and title to currently selected variables
self._selected_track_index=index
self._selected_track = self._tracks[index]
self.selected_track_location = self._selected_track[PlayList.LOCATION]
self.selected_track_title = self._selected_track[PlayList.TITLE]
def waiting_tracks(self):
waiting = []
for i in range(len(self._tracks)):
if self._tracks[i][1].startswith(self.YTDL_WAIT_TAG):
waiting += [(i, self._tracks[i])]
return waiting if len(waiting) else False