summaryrefslogtreecommitdiff
path: root/formats/flac.py
blob: 35db1e41526172dd601e38e3a3c29b47eccec91b (plain)
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
from formats.__base__ import *
from utils import to_bytes

import subprocess

class FlacHandler(BaseHandler):
	name = "flac"
	ext = "flac"

	def encode(self, opt, info):
		self.add("flac sox -")

		if opt.compression is not None:
			self.add("-C %d" % opt.compression)

		self.add_sox_args(opt, info)
		self.add("%f")

		return self.build()

	def tag(self, path, tags):
		args = ["metaflac", "--remove-all-tags", "--import-tags-from=-", path]

		proc = subprocess.Popen(args, stdin = subprocess.PIPE)
		for k, v in tags.items():
			if v is not "":
				proc.stdin.write(to_bytes("%s=%s\n" % (k.upper(), v)))
		proc.stdin.close()

		return proc.wait() is 0

def init():
	return FlacHandler