forked from puddletag/puddletag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore_tag.py
45 lines (35 loc) · 991 Bytes
/
restore_tag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
import os
import pickle
import traceback
import mutagen
from PyQt6.QtWidgets import QFileDialog
from PyQt6.QtGui import QAction
from puddlestuff.plugins import status
last_fn = {'fn': '~'}
def save_tags(files, fn):
tags = []
for f in files:
try:
tags.append(mutagen.File(f))
except:
traceback.print_exc()
pass
output = open(fn, 'wb')
pickle.dump(tags, output)
output.close()
def export_tags():
selectedFile = QFileDialog.getSaveFileName(None, "Save tags", last_fn['fn'], "*.*")
fn = selectedFile[0]
if fn:
save_tags(f.filepath for f in status['all_tags'])
last_fn['fn'] = os.path.dirname(fn)
def init(parent=None):
state = {}
def sep():
k = QAction(parent)
k.setSeparator(True)
return k
action = QAction('Export tags', parent)
action.toggled.connect(export_tags)
add_shortcuts('&Plugins', [sep(), action, sep()])