]> git.abendapudi.com Git - simplepytagger.git/commitdiff
initial commit
authorAbhijeet Bendapudi <abendapudi@protonmail.com>
Sat, 6 Jan 2024 05:18:04 +0000 (10:48 +0530)
committerAbhijeet Bendapudi <abendapudi@protonmail.com>
Sat, 6 Jan 2024 05:18:04 +0000 (10:48 +0530)
simplepytagger.py [new file with mode: 0644]
simplepytagger_lib.py [new file with mode: 0644]

diff --git a/simplepytagger.py b/simplepytagger.py
new file mode 100644 (file)
index 0000000..56e3d08
--- /dev/null
@@ -0,0 +1,59 @@
+import cmd, sys
+from simplepytagger_lib import *
+
+
+class TaggerShell(cmd.Cmd):
+    intro = 'Welcome to the tagger shell.   Type help or ? to list commands.\n'
+    prompt = '(>_<) '
+    file = None
+    open_file = None
+
+    def do_open(self, arg):
+        self.open_file = parse(arg)[0]
+        print(self.open_file)
+
+    def do_title(self, arg):
+        if self.open_file is not None:
+            apply_track_title(self.open_file, parse(arg)[0])
+
+    def do_num(self, arg):
+        if self.open_file is not None:
+            apply_track_idx(self.open_file, parse(arg)[0])
+
+    def do_year(self, arg):
+        if self.open_file is not None:
+            apply_release_year(self.open_file, parse(arg)[0])
+
+    def do_art(self, arg):
+        if self.open_file is not None:
+            apply_album_art(self.open_file, parse(arg)[0])
+
+    def do_album(self, arg):
+        if self.open_file is not None:
+            apply_album_title(self.open_file, parse(arg)[0])
+
+    def precmd(self, line):
+        line = line.lower()
+        if self.file and 'playback' not in line:
+            print(line, file=self.file)
+        return line
+
+    def do_bye(self, arg):
+        print('Thank you for using tagger')
+        self.close()
+        return True
+
+
+
+    def close(self):
+        if self.file:
+            self.file.close()
+            self.file = None
+
+
+def parse(arg):
+    return tuple(map(str, arg.split()))
+
+
+if __name__ == "__main__":
+    TaggerShell().cmdloop()
diff --git a/simplepytagger_lib.py b/simplepytagger_lib.py
new file mode 100644 (file)
index 0000000..65481a9
--- /dev/null
@@ -0,0 +1,58 @@
+from urllib.request import urlretrieve
+from mutagen.id3 import ID3, APIC, TALB, TDRC, TIT2, TRCK
+from mutagen import File
+import mutagen
+import glob
+
+def apply_album_art(mp3_file: str, url: str):
+    if url.split('.')[-1] == 'jpg' or 'jpeg':
+        urlretrieve(url, 'thumbnail.jpg')
+    else:
+        res_ = input('Are you sure this is a .jpg or .jpeg file? ')
+        if res_.lower() == 'yes' or 'y':
+            urlretrieve(url, 'thumbnail.jpg')
+        else:
+            return
+    song = ID3(mp3_file)
+    with open('thumbnail.jpg', 'rb') as cover:
+        song['APIC'] = APIC(
+            encoding=3,
+            mime='image/jpeg',
+            type=3,
+            desc=u'Cover',
+            data=cover.read()
+        )
+    song.save()
+
+
+def apply_album_title(mp3_file: str, name: str):
+    song = ID3(mp3_file)
+    song["TALB"] = TALB(text=name)
+    song.save()
+
+
+def apply_release_year(mp3_file: str, year: str):
+    song = ID3(mp3_file)
+    song["TDRC"] = TDRC(text=year)
+    song.save()
+
+
+def apply_track_title(mp3_file: str, name: str):
+    song = ID3(mp3_file)
+    song["TIT2"] = TIT2(text=name)
+    song.save()
+
+
+def apply_track_idx(mp3_file: str, idx: str):
+    song = ID3(mp3_file)
+    song["TRCK"] = TRCK(text=idx)
+    song.save()
+
+
+if __name__ == "__main__":
+    apply_album_title('doth')
+    apply_album_art('https://f4.bcbits.com/img/a1184758497_10.jpg')
+    apply_release_year('1996')
+    apply_track_idx('file_example_MP3_700KB.mp3', '2')
+    apply_track_title('file_example_MP3_700KB.mp3', 'creme')
+