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

read and modify tags

parent 62613ae3
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,9 @@ import argparse ...@@ -6,8 +6,9 @@ import argparse
from good_ol_mixtape import MixTape from good_ol_mixtape import MixTape
parser = argparse.ArgumentParser(description="Créer une mix-tape") parser = argparse.ArgumentParser(description="Créer une mix-tape")
parser.add_argument("-p", "--playlist", help="le fichier .m3u8 de la playlist", type=str) parser.add_argument("-p", "--playlist", help="le fichier .m3u8 de la playlist", type=str)
parser.add_argument("-t", "--mix_title", help="le titre du mix", type=str, default = None)
args = parser.parse_args() args = parser.parse_args()
if __name__ == "__main__": if __name__ == "__main__":
mx = MixTape(args.playlist) mx = MixTape(args.playlist, args.mix_title)
print(mx) print(mx)
...@@ -6,11 +6,26 @@ import music_tag ...@@ -6,11 +6,26 @@ import music_tag
from urllib.parse import unquote from urllib.parse import unquote
class Song: class Song:
def __init__(self,song_path): def __init__(self,song_path, mixAlbum = None, mixNumber = None):
self.file = music_tag.load_file(song_path) self.track = music_tag.load_file(song_path)
self.title = self.track['title'].first
self.o_album = self.track['album'].first
self.artist = self.track['artist'].first
self.o_number = self.track['tracknumber'].first
self.o_year = self.track['year'].first
if mixAlbum != None:
self.set_mixTitle(mixAlbum)
if mixNumber != None:
self.set_numInMix(mixNumber)
def set_mixTitle(self, mixAlbum):
self.track['album']=mixAlbum
def set_numInMix(self, mixNumber):
self.track['tracknumber']=mixNumber
def __str__(self): def __str__(self):
return str(self.file['title']) return f"{self.track['tracknumber'].first}. {self.track['album'].first}/{self.title}{self.artist} (track #{self.o_number} of {self.o_album})"
class MixTape: class MixTape:
@classmethod @classmethod
...@@ -21,11 +36,17 @@ class MixTape: ...@@ -21,11 +36,17 @@ class MixTape:
else: else:
return unquote(res) return unquote(res)
def __init__(self, pl_path): def __init__(self, pl_path, title = None):
self.playlist = [] self.playlist = []
self.title = title
num = 1
for s in m3u8.load(pl_path).segments: for s in m3u8.load(pl_path).segments:
try: try:
self.playlist.append(Song(MixTape.uri2path(s.uri))) if self.title == None :
self.playlist.append(Song(MixTape.uri2path(s.uri)))
else:
self.playlist.append(Song(MixTape.uri2path(s.uri), self.title, num))
num += 1
except ValueError as e: except ValueError as e:
print(e) print(e)
......
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