-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathitunec
executable file
·95 lines (75 loc) · 2.71 KB
/
itunec
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python3
# Decription
# -----------
# Mounts USB device, syncs new podcast in gpodder then umounts device
# Author: [Dmitry](http://dmi3.net) [Source](https://github.com/dmi3/bin)
# Requirements
# ------------
# 1. `sudo apt-get install python3 id3v2`
# 2. `wget https://raw.github.com/dmi3/bin/master/notify-append -P ~/bin && chmod +x ~/bin/notify-append`
# Usage
# -----
# 1. set LABEL to label of your player filesystem (for example `SANSA CLIP` to find label type `ls -l /dev/disk/by-label/`)
# 2. set GPODDER_DIR to directory where gpodder download podcasts
# 3. run `itunec` when you want to sync
# or
# 1. gpodder -> Podcasts -> Prefences -> Devices; set Device type to `Filesystem-based` and `Mountpoint` path where device is mounted by default
# 2. gpodder -> Podcasts -> Prefences -> Edit config -> cmd_all_download_complete -> itunec
LABEL = "AUDIOS"
GPODDER_DIR = "/media/archive/incoming/gpodder/"
import os,sys,time
from sh import ls,udisks,ErrorReturnCode_1,traceback,gpo,zenity,find,notify_append,id3v2
def fix_tags(dirsa):
for root, subFolders, files in os.walk(dirsa):
for f in files:
if f.count(".mp3")>0 and not is_russian(root):
show_title=os.path.basename(root)
path=os.path.join(root,f)
try:
if (id3v2("-l",path).count("TAL") == 0):
id3v2("-A",show_title,path)
except UnicodeDecodeError:
print("Error reading %s" % path)
def is_russian(s):
for letter in "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ":
if s.count(letter)>0:
return True
return False
def notify(text):
notify_append("Itunec",text)
def gpodder_has_new_episodes():
return not find(GPODDER_DIR,"-name","*.mp3")==""
try:
if not gpodder_has_new_episodes():
notify("No new episodes")
sys.exit()
#Find device by LABEL
devices = ls("-l","/dev/disk/by-label/")
device = next(x for x in devices if LABEL in x)
devid = device.split("/")[-1]
devpath = "/dev/"+devid.replace("\n","")
#Mount device
mntmsg = udisks("--mount",devpath)
wasmnt = "is mounted" in mntmsg
if not wasmnt:
notify(mntmsg)
fix_tags(GPODDER_DIR)
notify("Starting synchronization")
gpo("sync")
time.sleep(3)
#Umount device
if not wasmnt:
mntmsg = udisks("--unmount",devpath)
if mntmsg == "":
zenity("--info","--text","Its now safe to remove "+LABEL)
else:
notify(mntmsg)
else:
zenity("--info","--text","Sync done")
except StopIteration:
notify("Unable to find device "+LABEL)
except ErrorReturnCode_1:
notify("Unable to mount device "+LABEL)
except Exception:
notify("Unknown problem during sync")
traceback.print_exc()