Esempio n. 1
0
    def generate_frame(self, song: ID3):
        """Creates a frame object of the songtag in the ID3 file sent.

            Parameters
            ----------
            song : ID3 -
                Song where the frame object should be created.
            """
        if self.has_tag(song):
            return
        encoding = id3.Encoding.UTF8
        frame: Frames
        try:
            if 'TXXX' not in self.name:
                # ? Checks if the tag is custom or not.
                frame = Frames[self.name](encoding, [])
            else:
                # ? Custom tags work differently, taking in an extra param.
                # ?This param is desc, which is a description taken
                # ? from the tag name.
                desc = self.name.split(':')[1]
                frame = Frames['TXXX'](encoding, desc=desc, text=[])
            song.add(frame)
        except TypeError:
            # ? Cannot create a tag frame with this key.
            print("Tag Name: " + str(self.name))
Esempio n. 2
0
def _embed_id3_img(root_dir, audio: id3.ID3):
    emb_image = os.path.join(root_dir, "cover.jpg")
    multi_emb_image = os.path.join(
        os.path.abspath(os.path.join(root_dir, os.pardir)), "cover.jpg")
    if os.path.isfile(emb_image):
        cover_image = emb_image
    else:
        cover_image = multi_emb_image

    with open(cover_image, "rb") as cover:
        audio.add(id3.APIC(3, "image/jpeg", 3, "", cover.read()))
Esempio n. 3
0
def add_chapters(tags: id3.ID3, chapters: List[Tuple[int, int, str]]) -> None:
    toc = [f"chp{index}" for index in range(len(chapters))]
    tags.add(
        id3.CTOC(encoding=id3.Encoding.LATIN1,
                 element_id="toc",
                 flags=id3.CTOCFlags.TOP_LEVEL | id3.CTOCFlags.ORDERED,
                 child_element_ids=toc,
                 sub_frames=[]))

    for idx, chapter in enumerate(chapters):
        tags.add(
            id3.CHAP(encoding=id3.Encoding.LATIN1,
                     element_id=f"chp{idx}",
                     start_time=chapter[0],
                     end_time=chapter[1],
                     sub_frames=[
                         id3.TIT2(encoding=id3.Encoding.LATIN1,
                                  text=chapter[2])
                     ]))
Esempio n. 4
0
def add_episode_number(tags: id3.ID3, episode_number: int) -> None:
    tags.add(id3.TRCK(encoding=id3.Encoding.LATIN1, text=str(episode_number)))
Esempio n. 5
0
def add_episode_title(tags: id3.ID3, episode_name: str) -> None:
    tags.add(id3.TIT2(encoding=id3.Encoding.LATIN1, text=episode_name))
Esempio n. 6
0
def add_podcast_name(tags: id3.ID3, name: str) -> None:
    tags.add(id3.TPE1(encoding=id3.Encoding.LATIN1, text=name))