-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmp3split.py
47 lines (39 loc) · 1.6 KB
/
mp3split.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
46
47
#!/usr/bin/python
# Example hooks script for gPodder.
# To use, copy it as a Python script into ~/.config/gpodder/hooks/mp3split.py
# See the module "gpodder.hooks" for a description of when each hook
# gets called and what the parameters of each hook are.
import gpodder
import subprocess
import os
from gpodder.liblogger import log
def mp3split(from_file, to_file):
# http://docs.python.org/library/subprocess.html#subprocess-replacements
# http://www.doughellmann.com/PyMOTW/subprocess/
try:
destination = os.path.dirname(to_file)
log("mp3split: destination is %s", destination)
command = 'mp3splt -ft 10.00 -o "@f_@n" "%s" -d "%s"' % (from_file, destination)
log("mp3split: Executing %s", command)
p = subprocess.Popen(command, shell=True)
# retcode[1] values:
# <0: error
# 0: success, script handle the copy by hand(snif, progress bar is not used)
retcode = os.waitpid(p.pid, 0)
log("mp3split: Child with pid %s returned %s", retcode[0], retcode[1])
os.remove(to_file)
log("mp3split: Original file %s removed", to_file)
except OSError, e:
log("mp3split: Execution failed: %s", e)
class gPodderHooks(object):
def __init__(self):
pass
def on_podcast_updated(self, podcast):
pass
def on_podcast_save(self, podcast):
pass
def on_episode_save(self, episode):
pass
def on_file_copied_to_filesystem(self, mp3playerdevice, from_file, to_file):
log(u'on_file_copied_to_filesystem(%s, %s)' % (from_file, to_file))
mp3split(from_file, to_file)