From 62613ae3c4bf873bbc08164d41e18f30872a5d13 Mon Sep 17 00:00:00 2001 From: Mathieu Loiseau <mathieu.loiseau@liris.cnrs.fr> Date: Tue, 17 May 2022 15:59:31 +0200 Subject: [PATCH] read files' tags --- README.md | 5 +++++ good_ol_mixtape.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 00ed7af..0d1819d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ A little python project to create old school mix-CDs out of an m3u playlist ## Dependencies +* m3u8 +* music-tag +* urllib.parse +## Install ```bash pip install m3u8 +pip install music-tag ``` diff --git a/good_ol_mixtape.py b/good_ol_mixtape.py index 7cd79a8..0849d94 100644 --- a/good_ol_mixtape.py +++ b/good_ol_mixtape.py @@ -2,10 +2,35 @@ # -*- coding: UTF-8 -*- # created by lzbk import m3u8 +import music_tag +from urllib.parse import unquote + +class Song: + def __init__(self,song_path): + self.file = music_tag.load_file(song_path) + + def __str__(self): + return str(self.file['title']) class MixTape: - def __init__(self, pl): - self.playlist = m3u8.load(pl) + @classmethod + def uri2path(cls, uri): + res = uri.replace("file://","") + if res == uri: + raise ValueError(uri+" is not a file uri.") + else: + return unquote(res) + + def __init__(self, pl_path): + self.playlist = [] + for s in m3u8.load(pl_path).segments: + try: + self.playlist.append(Song(MixTape.uri2path(s.uri))) + except ValueError as e: + print(e) def __str__(self): - return str(self.playlist.segments) + "\n" + str(self.playlist.target_duration) + res = "" + for track in self.playlist: + res += track.__str__()+"\n" + return res -- GitLab