Skip to content
Snippets Groups Projects
Commit 0e75f032 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

rename

parent 18ebeb99
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,12 @@
import m3u8
import music_tag
from urllib.parse import unquote
import os
class Song:
def __init__(self,song_path, mixAlbum = None, mixNumber = None, mixAuthor=None, mixCover=None):
self.track = music_tag.load_file(song_path)
self.path = song_path
self.track = music_tag.load_file(self.path)
self.title = self.track['title'].first
self.o_album = self.track['album'].first
self.artist = self.track['artist'].first
......@@ -45,9 +47,17 @@ class Song:
self.track.append_tag('artwork', a)
def update_tag(self):
#self.track.save()
self.track.save()
print("uncomment to update "+str(self))
def rename_track(self):
self.update_tag()
new_path = f"{os.path.dirname(self.path)}/{self.track['tracknumber'].first}. {self.title} [{self.artist}]{os.path.splitext(os.path.basename(self.path))[1]}"
os.rename(self.path, new_path)
self.path = new_path
self.track = music_tag.load_file(self.path)
def __str__(self):
return f"{self.track['tracknumber'].first}/{self.track['totaltracks'].first}. {self.track['album'].first}/{self.title}{self.artist} (track #{self.o_number} of {self.o_album})"
......@@ -81,9 +91,14 @@ class MixTape:
for t in self.playlist:
t.set_totalnum(len(self.playlist))
t.update_tag()
t.rename_track()
def __str__(self):
res = ""
for track in self.playlist:
res += track.__str__()+"\n"
return res
if __name__ == "__main__":
s = Song("sampleData/archive/02. NoName - Rainforest.flac", "test", 5, "me", "sampleData/CONNECTED.png")
s.set_totalnum(12)
s.rename_track()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment