Révision | fa5c6134b5236a25e431c9a498f94cd08e88d799 (tree) |
---|---|
l'heure | 2019-08-30 04:50:30 |
Auteur | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Use the convert plugin
@@ -6,16 +6,15 @@ | ||
6 | 6 | import sqlite3 |
7 | 7 | import shutil |
8 | 8 | import datetime |
9 | -import subprocess | |
10 | -import tempfile | |
11 | 9 | |
12 | 10 | IS_PY3 = sys.version_info[0] >= 3 |
13 | 11 | |
14 | 12 | from beets.plugins import BeetsPlugin |
15 | 13 | from beets.ui import Subcommand |
16 | -from beets.util import prune_dirs, bytestring_path, command_output | |
14 | +from beets.util import prune_dirs, bytestring_path | |
17 | 15 | from beets.dbcore import OrQuery |
18 | 16 | from beets.library import parse_query_parts, Item |
17 | +from beetsplug.convert import get_format, ConvertPlugin | |
19 | 18 | |
20 | 19 | _CREATE_DATABASE_SCRIPT=''' |
21 | 20 | CREATE TABLE song(idSong INTEGER PRIMARY KEY, filename TEXT NOT NULL, date TIMESTAMP, synced BOOL); |
@@ -137,15 +136,10 @@ | ||
137 | 136 | else: |
138 | 137 | fmt = _format_from_ext(new_ext.lstrip('.')) |
139 | 138 | self.info('Converting to {0}: {1}', fmt, item) |
140 | - args = sys.argv[:sys.argv.index('sync')] | |
141 | - temp_dir = tempfile.mkdtemp() | |
142 | - try: | |
143 | - args.extend(['convert', '--yes', '--format', fmt, '--dest', temp_dir, 'id:' + str(item_id)]) | |
144 | - out = subprocess.check_call(args) | |
145 | - temp_path = os.path.join(temp_dir, song_path) | |
146 | - shutil.copyfile(temp_path, copy_path) | |
147 | - finally: | |
148 | - shutil.rmtree(temp_dir) | |
139 | + convert_command, _ = get_format(fmt) | |
140 | + self.config['quiet'] = False | |
141 | + ConvertPlugin.encode(self, convert_command, item['path'], | |
142 | + copy_path.encode() if (IS_PY3 and isinstance(copy_path, str)) else copy_path) | |
149 | 143 | db.execute('UPDATE song SET synced=1,date=? WHERE idSong=?', (datetime.datetime.now(), item_id)) |
150 | 144 | |
151 | 145 | for item_id, song_path in db.execute(''' |