1 import os
, sys
, random
, cfg
5 sound
= __import__(cfg
.cf
['sound'])
8 self
.out
= sound
.Music()
9 self
.playlistfile
= os
.path
.join(sys
.path
[0], '.lastplayed.lst')
12 return self
.out
.isplaying()
16 if self
.out
.play(self
.tracks
[self
.pos
]):
19 if len(self
.tracks
) != 1:
20 self
.tracks
.remove(self
.tracks
[self
.pos
])
34 return self
.out
.paused
38 return self
.out
.time()
42 def track(self
, split
=False, frompos
=0):
44 if len(self
.tracks
)>0:
45 if self
.pos
+frompos
> len(self
.tracks
)-1:
46 frompos
= frompos
-len(self
.tracks
)
47 txt
= self
.tracks
[self
.pos
+frompos
]
49 trash
, txt
= os
.path
.split(txt
)
50 txt
, trash
= os
.path
.splitext(txt
)
56 if self
.out
.isplaying():
57 self
.out
.playing
= False
59 if os
.path
.isfile(self
.playlistfile
):
61 os
.unlink(self
.playlistfile
)
67 if self
.pos
== len(self
.tracks
) - 1:
70 self
.pos
= self
.pos
+ 1
76 self
.pos
= len(self
.tracks
) - 1
78 self
.pos
= self
.pos
- 1
82 self
.tracks
.append(name
)
84 def add_dir(self
, name
, filetypes
, selected
=None, keep
=False):
85 old_tracks
= self
.tracks
89 inp
= os
.listdir(name
)
91 (shortname
, ext
) = os
.path
.splitext(line
)
94 self
.tracks
.append(os
.path
.join(name
, line
))
96 self
.tracks
.sort(key
=str.lower
)
97 if self
.tracks
!= [] and keep
== False:
100 if self
.out
.isplaying():
104 self
.tracks
= old_tracks
106 def super_add(self
, name
, filetypes
, keep
=False):
107 old_tracks
= self
.tracks
111 sadd
= Superadd(name
, filetypes
)
112 if sadd
.files
!= [] and keep
== False:
113 self
.tracks
= sadd
.files
114 if self
.out
.isplaying():
118 self
.tracks
= old_tracks
123 random
.shuffle(self
.tracks
)
129 out_file
= open(self
.playlistfile
,'w')
130 out_file
.write(str(self
.pos
) + '\n')
131 for file in self
.tracks
:
133 out_file
.write(file + '\n')
138 def load(self
, file=None):
140 file = self
.playlistfile
141 if os
.path
.isfile(file):
142 in_file
= open(file,'r')
147 if i
== 0 and file == self
.playlistfile
:
150 if os
.path
.isfile(line
[:-1]):
151 self
.tracks
.append(str(line
[:-1]))
157 def __init__(self
, path
, ft
=None):
160 self
.searchdir(path
, ft
)
163 def searchdir(self
, path
, ft
=None):
164 for line
in os
.listdir(path
):
165 if os
.path
.isdir(os
.path
.join(path
,line
)):
166 self
.searchdir(os
.path
.join(path
,line
), ft
)
170 (shortname
, ex
) = os
.path
.splitext(line
)
172 self
.files
.append(os
.path
.join(path
,line
))
174 self
.files
.append(os
.path
.join(path
,line
))
175 return self
.files
.sort(key
=str.lower
)
177 PLAYLIST
= Playlist()