simple playlist with no escaping character
This commit is contained in:
parent
bef6737138
commit
bd8ed30ffe
38
musipy.py
38
musipy.py
@ -17,6 +17,9 @@ class musipy:
|
||||
if self.parser.mode == 'sort':
|
||||
self.collect()
|
||||
self.move_files()
|
||||
elif self.parser.mode == 'playlist':
|
||||
self.collect()
|
||||
self.playlist()
|
||||
else:
|
||||
pass
|
||||
return
|
||||
@ -65,6 +68,41 @@ class musipy:
|
||||
print("")
|
||||
return
|
||||
|
||||
def playlist(self):
|
||||
print("Create playlist name {}".format(self.parser.playlistname))
|
||||
pl_file = self.parser.source + '/' + self.parser.playlistname + '.m3u'
|
||||
mode = 'w'
|
||||
|
||||
while os.path.exists(pl_file):
|
||||
rewrite = input('Playlist existed, rewrite?(y/n) ')
|
||||
if rewrite == 'y':
|
||||
break
|
||||
newname = input("New file name: ")
|
||||
pl_file = self.parser.source + '/' + newname + '.m3u'
|
||||
# return
|
||||
|
||||
playlist = open(pl_file, mode)
|
||||
playlist.write('#EXTM3U\n')
|
||||
|
||||
for key, musics in self.data.items():
|
||||
for music in musics:
|
||||
tag = TinyTag.get(music)
|
||||
if tag.artist is None:
|
||||
tag.artist = ''
|
||||
if tag.title is None:
|
||||
tag.title = ''
|
||||
tag.duration = int(tag.duration)
|
||||
# write comment
|
||||
playlist.write('#EXTINF:{},{} - {}\n'
|
||||
.format(tag.duration, tag.artist, tag.title))
|
||||
# change special char to hex
|
||||
# TODO
|
||||
# write file direction
|
||||
playlist.write('file//{}\n'.format(music))
|
||||
|
||||
print("{} created".format(pl_file))
|
||||
return
|
||||
|
||||
# collect all files and store in self.data
|
||||
def collect(self):
|
||||
folder_queue = [self.parser.source]
|
||||
|
@ -11,10 +11,12 @@ class Parser():
|
||||
self.attr = None
|
||||
self.mode = None
|
||||
|
||||
self.playlistname = None
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(
|
||||
argv, 'hs:o:a:m:',
|
||||
['source=', 'output=', 'attribute=', 'mode='])
|
||||
argv, 'hs:o:a:m:pln:',
|
||||
['source=', 'output=', 'attribute=', 'mode=', 'playlistname='])
|
||||
|
||||
except getopt.GetoptError:
|
||||
print('')
|
||||
@ -32,6 +34,8 @@ class Parser():
|
||||
self.attr = arg
|
||||
elif opt in ('-m', '--mode'):
|
||||
self.mode = arg
|
||||
elif opt in ('-pl', '--playlistname'):
|
||||
self.playlistname = arg
|
||||
else:
|
||||
print("Unknown flag {} {}".format(opt, arg))
|
||||
|
||||
@ -44,6 +48,10 @@ class Parser():
|
||||
if self.mode is None:
|
||||
self.mode = 'sort'
|
||||
|
||||
if self.mode == 'playlist' and self.playlistname is None:
|
||||
print("No play list name")
|
||||
exit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = Parser()
|
||||
|
Loading…
Reference in New Issue
Block a user