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

read files' tags

parent d7b5f7be
No related branches found
No related tags found
No related merge requests found
......@@ -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
```
......@@ -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
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