From 7f5b856e2ef104f8a906cb1ad32d97d816cb0960 Mon Sep 17 00:00:00 2001 From: Sqozz Date: Sun, 9 Oct 2016 23:20:07 +0200 Subject: [PATCH] added MusicBrainz mapping while ripping --- ripbot.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/ripbot.py b/ripbot.py index 863bed0..ca9ad55 100755 --- a/ripbot.py +++ b/ripbot.py @@ -4,6 +4,40 @@ import sys import discid import musicbrainzngs as mb +class Disk: + __albums__ = list() + def __init__(self): + pass + + def addAlbum(self, album): + self.__albums__.append(album) + +class Album: + songs = list() + name = "" + artist = "" + def __init__(self, artist = "", name = ""): + self.artist = artist + self.name = name + + def addSong(self, song, position = -1): + if position == -1: + self.songs += [song] + else: + self.songs = self.songs[0:position] + [song] + self.songs[position:] + +class Artist: + def __init__(self): + pass + +class Song: + name = "" + position = -1 + def __init__(self, name, position): + self.name = name + self.position = position + + def getTitleAmount(): process = subprocess.Popen(["cdparanoia", "-Q", "--stderr-progress", "--"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) startCount = False @@ -23,20 +57,35 @@ def getTitleAmount(): def getMBbyDisc(): disc = discid.read("/dev/cdrom") mb.set_useragent("ripbot", "0.01", "https://git.geekify.de/sqozz/ripbot") - releases = mb.get_releases_by_discid(disc.id) + releases = mb.get_releases_by_discid(disc.id, includes=["artists", "recordings"]) if len(releases["disc"]["release-list"]) > 1: print("Found {0} relases by discid {1}".format(releases["disc"]["release-count"], releases["disc"]["id"])) - + else: + release = releases["disc"]["release-list"][0] + album = Album() + albumTitle = release["title"] + album.title = albumTitle + artist = release["artist-credit"][0]["artist"]["name"] + album.artist = artist + print("{0} - {1}:".format(albumTitle, artist)) + for disc in release["medium-list"]: + for track in disc["track-list"]: + song = Song(track["recording"]["title"], track["number"]) + album.addSong(song) + return album -def ripTitles(): +def ripTitles(album = None): process = subprocess.Popen(["cdparanoia", "-B", "-l", "--stderr-progress", "--", "\"1-2\""], stdout=subprocess.PIPE, stderr=subprocess.PIPE) currentTitle = 0 for line in process.stderr: out = line.decode() if "outputting to" in out: currentTitle += 1 - print("Ripping title {0}".format(currentTitle)) + if album is None: + print("Ripping title {0}".format(currentTitle)) + else: + print("Ripping {1}. title: {0}".format(album.songs[currentTitle - 1].name, album.songs[currentTitle - 1].position)) elif "##" == out[:2]: print(out.strip(), end="\r") sys.stdout.write("\r") @@ -45,8 +94,8 @@ def ripTitles(): titleAmount = getTitleAmount() print("Found {0} titles".format(titleAmount)) -getMBbyDisc() +album = getMBbyDisc() print("Start ripping") -#ripTitles() +ripTitles(album) # vim:ts=2 sts=2 sw=2 noexpandtab: