forked from Tscheggi/pyLoad-stuff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileBot.py
224 lines (147 loc) · 7.7 KB
/
FileBot.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# !/usr/bin/python
# -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License,published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import subprocess
import os
import string
from module.plugins.Hook import Hook
from module.utils import save_join
class FileBot(Hook):
__name__ = "FileBot"
__version__ = "0.13"
__config__ = [("activated", "bool", "Activated", "False"),
("destination", "folder", "destination folder", ""),
("conflict", """skip;override""", "conflict handling", "override"),
("action", """move;copy;test""", "copy, move or test(dry run)", "move"),
("lang", "str", "language (en, de, fr, es, etc)", ""),
("subtitles", "str", "subtitles language (en, de, fr, es, etc)", ""),
("unsorted", """y;n""", "sort out files that cannot be proceed to $destination/unsorted/", "n"),
("ignore", "str", "ignore files (regex)", ""),
("artwork", """y;n""", "download artwork", "n"),
("clean", """y;n""", "clean folder from clutter thats left behind", "y"),
("movie", "str", "movie destination (relative to destination or absolute)", ""),
("series", "str", "series destination (relative to destination or absolute)", ""),
("music", "str", "music destination (relative to destination or absolute)", ""),
("anime", "str", "anime destination (relative to destination or absolute)", ""),
("gmail", "str", "gmail login (without @gmail.com)", ""),
("gmailpw", "password", "gmail password", ""),
("mail", "str", "mail (host:port:from)", ""),
("mailto", "str", "mailto", ""),
("excludeList", "str", "exclude list file", "pyload-amc.txt"),
("myepisodes", "str", "myepisodes login", " "),
("myepisodespw", "password", "myepisodes password", " "),
("pushover", "str", "pushover user key", ""),
("pushbullet", "str", "pushbullet api key", ""),
("xbmc", "str", "xbmc hostname", ""),
("plex", "str", "plex hostname", ""),
("reportError", """y;n""", "report error via email", "n"),
("filebot", "str", "filebot executable", "filebot"),
("exec", "str", "additional exec script", ""),
("storeReport", """y;n""", "save reports to local filesystem", "n"),
("extensions","list","comma-separated file extensions to process, that are not archives ","mkv,mp4,ts,avi,wmv,mpeg")]
__description__ = "automated renaming and sorting for tv episodes movies, music and animes"
__author_name__ = ("Branko Wilhelm", "Kotaro", "Gutz-Pilz")
event_list = ["downloadFinished","archive_extracted","unrarFinished"]
def archive_extracted(self, pyfile, folder, fname, extracted_files):
self.Finished(folder)
def unrarFinished(self, folder, fname):
self.Finished(folder,"unrarFinished")
def downloadFinished(self, pyfile):
filename = os.path.splitext(pyfile.name)
extensions = string.split(self.getConf("extensions"), ',')
if filename[1].replace('.','') in extensions:
package = pyfile.package()
folder = save_join(self.config['general']['download_folder'], package.folder)
self.Finished(folder)
def Finished(self, folder):
args = [] # http://www.filebot.net/forums/viewtopic.php?f=4&t=215&p=1561
self.logDebug(folder)
if self.getConfig('filebot'):
args.append(self.getConfig('filebot'))
else:
args.append('filebot')
args.append('-script')
args.append('fn:amc')
args.append('-non-strict')
args.append('--log-file')
args.append('amc.log')
args.append('-r')
args.append('--conflict')
args.append(self.getConfig('conflict'))
args.append('--action')
args.append(self.getConfig('action'))
if self.getConfig('destination'):
args.append('--output')
args.append(self.getConfig('destination'))
else:
args.append('--output')
args.append(folder)
if self.getConfig('lang'):
args.append('--lang')
args.append(self.getConfig('lang'))
# start with all definitions:
args.append('--def')
if self.getConfig('exec'):
args.append('exec=' + self.getConfig('exec'))
if self.getConfig('clean'):
args.append('clean=' + self.getConfig('clean'))
if self.getConfig('mail'):
args.append('mail=' + self.getConfig('mail'))
if self.getConfig('mailto'):
args.append('mailto=' + self.getConfig('mailto'))
args.append('skipExtract=y')
if self.getConfig('excludeList'):
args.append('excludeList=' + self.getConfig('excludeList'))
if self.getConfig('reportError'):
args.append('reportError=' + self.getConfig('reportError'))
if self.getConfig('storeReport'):
args.append('storeReport=' + self.getConfig('storeReport'))
if self.getConfig('artwork'):
args.append('artwork=' + self.getConfig('artwork'))
if self.getConfig('subtitles'):
args.append('subtitles=' + self.getConfig('subtitles'))
if self.getConfig('ignore'):
args.append('ignore=' + self.getConfig('ignore'))
if self.getConfig('unsorted'):
args.append('unsorted=' + self.getConfig('unsorted'))
if self.getConfig('gmail') and self.getConfig('gmailpw'):
args.append('gmail=' + self.getConfig('gmail') + ':' + self.getConfig('gmailpw'))
if self.getConfig('myepisodes') and self.getConfig('myepisodespw'):
args.append('myepisodes=' + self.getConfig('myepisodes') + ':' + self.getConfig('myepisodespw'))
if self.getConfig('pushover'):
args.append('pushover=' + self.getConfig('pushover'))
if self.getConfig('pushbullet'):
args.append('pushbullet=' + self.getConfig('pushbullet'))
if self.getConfig('xbmc'):
args.append('xbmc=' + self.getConfig('xbmc'))
if self.getConfig('plex'):
args.append('plex=' + self.getConfig('plex'))
if self.getConfig('movie'):
args.append('movieFormat=' + self.getConfig('movie'))
if self.getConfig('series'):
args.append('seriesFormat=' + self.getConfig('series'))
if self.getConfig('music'):
args.append('musicFormat=' + self.getConfig('music'))
else:
args.append('music=n')
if self.getConfig('anime'):
args.append('animeFormat=' + self.getConfig('anime'))
args.append(folder)
try:
subprocess.Popen(args, bufsize=-1)
self.logInfo('executed')
self.logDebug(' '.join(args))
except Exception, e:
self.logError(str(e))