Exemplo n.º 1
0
def print_cdtext_track_info_old(device, track, message):
    print(message)
    t = device.get_track(track)
    cdt = t.get_cdtext()

    for i in range(pycdio.MIN_CDTEXT_FIELDS, pycdio.MAX_CDTEXT_FIELDS):
        value = cdt.get(i)
        # value can be empty but exist, compared to NULL values
        if value is not None:
            print("\t%s: %s" % (pycdio.cdtext_field2str(i), value))
            pass
        pass
    return
Exemplo n.º 2
0
def print_cdtext_info_new(device, message):
    print(message)
    cdt = device.get_cdtext()
    i_tracks = device.get_num_tracks()
    i_first_track = pycdio.get_first_track_num(device.cd)

    for t in range(i_first_track, i_tracks + i_first_track):
        for i in range(pycdio.MIN_CDTEXT_FIELD, pycdio.MAX_CDTEXT_FIELDS):
            value = cdt.get(i, t)
            # value can be empty but exist, compared to NULL values
            if value is not None:
                print("\t%s: %s" % (pycdio.cdtext_field2str(i), value))
                pass
            pass
        pass
    return
Exemplo n.º 3
0
    def parse_cdtext(self, cdtext) -> List[CDText_type]:
        # [ - { language: "<lang>", data: { key: text, ... } ]
        parsed: List[CDText_type] = []
        if cdtext:
            for lang_id in pycdio.cdtext_list_languages_v2(cdtext):
                lang_name = pycdio.cdtext_lang2str(lang_id)
                data: Dict[int, Dict[str, bytes]] = {}
                if lang_id == pycdio.CDTEXT_LANGUAGE_INVALID or lang_id == pycdio.CDTEXT_LANGUAGE_BLOCK_UNUSED:
                    continue

                if not pycdio.cdtext_select_language(cdtext, lang_id):
                    raise DiscException(f"Could not select language '{lang_name}'")
                for t in [0] + list(self.track_nums()):
                    data[t]: Dict[str, bytes] = {}
                    for i in range(pycdio.MIN_CDTEXT_FIELD, pycdio.MAX_CDTEXT_FIELDS):
                        key = pycdio.cdtext_field2str(i)
                        if txt := pycdio.cdtext_get(cdtext, i, t):
                            data[t][key] = txt

                parsed.append({"language": lang_name, "data": data})
Exemplo n.º 4
0
def info_from_cdtext(disc):
    """
    Extracts metadata from the CDText information if
    it exists on the `disc`. `None` iis returned if
    no CDText information is stored on the disc.
    """
    try:
        d = cdio.Device(driver_id=pycdio.DRIVER_UNKNOWN)
    except IOError as err:
        print("Problem finding a CD-ROM")
        raise err

    if d.get_disc_mode() != 'CD-DA':
        raise NotCDDAError()

    t = d.get_cdtext()

    # Build the dictionnary for album info
    album_info = {
        pycdio.cdtext_field2str(i): t.get(i, 0)
        for i in range(pycdio.MIN_CDTEXT_FIELD, pycdio.MAX_CDTEXT_FIELDS)
        if t.get(i, 0) is not None
    }

    if "TITLE" in album_info:
        disc_info = {"source": "CDText", "album": album_info["TITLE"]}

        if "PERFORMER" in album_info:
            disc_info["albumartist"] = album_info["PERFORMER"]
        elif "COMPOSER" in album_info:
            disc_info["albumartist"] = album_info["COMPOSER"]
        elif "SONGWRITER" in album_info:
            disc_info["albumartist"] = album_info["SONGWRITER"]
    else:
        return None

    disc_info["discid"] = disc.id

    disc_info["tracks"] = {}
    tracks_info = disc_info["tracks"]

    for track in itrack(disc):
        track_info = {
            pycdio.cdtext_field2str(i): t.get(i, int(track))
            for i in range(pycdio.MIN_CDTEXT_FIELD, pycdio.MAX_CDTEXT_FIELDS)
            if t.get(i, int(track)) is not None
        }

        tracks_info[track] = {
            "track": track,
            "album": disc_info["album"],
            "name": "Track {}".format(track),
            "title":
            track_info["TITLE"] if "TITLE" in track_info else "Unknown"
        }

        if "GENRE" in track_info:
            tracks_info[track]["genre"] = track_info["GENRE"]

        if "COMPOSER" in track_info:
            tracks_info[track]["composer"] = track_info["COMPOSER"]

        if "ARRANGER" in track_info:
            tracks_info[track]["conductor"] = track_info["ARRANGER"]

        if "PERFORMER" in track_info:
            tracks_info[track]["artist"] = track_info["PERFORMER"]
        elif "SONGWRITER" in track_info:
            tracks_info[track]["artist"] = track_info["SONGWRITER"]
        elif "COMPOSER" in track_info:
            tracks_info[track]["artist"] = track_info["COMPOSER"]
        else:
            tracks_info[track]["artist"] = "Unknown"

    return disc_info
Exemplo n.º 5
0
 def test_keyword(self):
     """Test keywords"""
     self.assertEquals(
         pycdio.cdtext_field2str(pycdio.CDTEXT_FIELD_PERFORMER), "PERFORMER"
     )