trackma 0.4__py2.7.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +19 -0
- EGG-INFO/SOURCES.txt +35 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/entry_points.txt +8 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +10 -0
- EGG-INFO/top_level.txt +1 -0
- trackma/__init__.py +0 -0
- trackma/__init__.pyc +0 -0
- trackma/accounts.py +110 -0
- trackma/accounts.pyc +0 -0
- trackma/data/anilist.jpg +0 -0
- trackma/data/hb.jpg +0 -0
- trackma/data/icon.png +0 -0
- trackma/data/mal.jpg +0 -0
- trackma/data/melative.jpg +0 -0
- trackma/data/vndb.jpg +0 -0
- trackma/data.py +585 -0
- trackma/data.pyc +0 -0
- trackma/engine.py +742 -0
- trackma/engine.pyc +0 -0
- trackma/extras/AnimeInfoExtractor.py +308 -0
- trackma/extras/AnimeInfoExtractor.pyc +0 -0
- trackma/extras/__init__.py +0 -0
- trackma/extras/__init__.pyc +0 -0
- trackma/extras/plex.py +100 -0
- trackma/extras/plex.pyc +0 -0
- trackma/lib/__init__.py +0 -0
- trackma/lib/__init__.pyc +0 -0
- trackma/lib/lib.py +162 -0
- trackma/lib/lib.pyc +0 -0
- trackma/lib/libanilist.py +355 -0
- trackma/lib/libanilist.pyc +0 -0
- trackma/lib/libhb.py +248 -0
- trackma/lib/libhb.pyc +0 -0
- trackma/lib/libmal.py +705 -0
- trackma/lib/libmal.pyc +0 -0
- trackma/lib/libmelative.py +213 -0
- trackma/lib/libmelative.pyc +0 -0
- trackma/lib/libvndb.py +373 -0
- trackma/lib/libvndb.pyc +0 -0
- trackma/messenger.py +42 -0
- trackma/messenger.pyc +0 -0
- trackma/tracker.py +301 -0
- trackma/tracker.pyc +0 -0
- trackma/ui/__init__.py +0 -0
- trackma/ui/__init__.pyc +0 -0
- trackma/ui/cli.py +712 -0
- trackma/ui/cli.pyc +0 -0
- trackma/ui/curses.py +1049 -0
- trackma/ui/curses.pyc +0 -0
- trackma/ui/gtkui.py +2360 -0
- trackma/ui/gtkui.pyc +0 -0
- trackma/ui/qtui.py +2120 -0
- trackma/ui/qtui.pyc +0 -0
- trackma/utils.py +299 -0
- trackma/utils.pyc +0 -0
trackma/engine.pyc
ADDED
|
Binary file
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# This file is part of wMAL.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
from decimal import Decimal
|
|
19
|
+
|
|
20
|
+
class AnimeInfoExtractor(object):
|
|
21
|
+
"""
|
|
22
|
+
Extracts lots of information about anime from filename alone
|
|
23
|
+
@author: Tyris
|
|
24
|
+
@author: Uriziel
|
|
25
|
+
@note: Thanks for Tyris for providing easy way to extract data
|
|
26
|
+
@note: Does more than what's needed, but that behaviour is well tested
|
|
27
|
+
"""
|
|
28
|
+
def __init__(self, filename):
|
|
29
|
+
self.originalFilename = filename
|
|
30
|
+
self.resolution = ''
|
|
31
|
+
self.hash = ''
|
|
32
|
+
self.subberTag = ''
|
|
33
|
+
self.videoType = []
|
|
34
|
+
self.audioType = []
|
|
35
|
+
self.releaseSource = []
|
|
36
|
+
self.extension = ''
|
|
37
|
+
self.episodeStart = ''
|
|
38
|
+
self.episodeEnd = ''
|
|
39
|
+
self.volumeStart = ''
|
|
40
|
+
self.volumeEnd = ''
|
|
41
|
+
self.version = 1
|
|
42
|
+
self.name = ''
|
|
43
|
+
self.pv = -1
|
|
44
|
+
self._processFilename()
|
|
45
|
+
|
|
46
|
+
def getName(self):
|
|
47
|
+
return self.name
|
|
48
|
+
|
|
49
|
+
def getEpisodeNumbers(self):
|
|
50
|
+
return self.episodeStart, self.episodeEnd
|
|
51
|
+
|
|
52
|
+
def getEpisode(self):
|
|
53
|
+
ep = self.episodeStart if self.episodeEnd == '' else self.episodeEnd
|
|
54
|
+
ep = ep if ep != '' else '1'
|
|
55
|
+
|
|
56
|
+
return int(ep)
|
|
57
|
+
|
|
58
|
+
def __extractExtension(self, filename):
|
|
59
|
+
m = re.search("\.(\w{3})$", filename)
|
|
60
|
+
if m:
|
|
61
|
+
self.extension = m.group(1)
|
|
62
|
+
filename = filename[:-4]
|
|
63
|
+
return filename
|
|
64
|
+
|
|
65
|
+
def __cleanUpSpaces(self, filename):
|
|
66
|
+
filename = filename.replace('_', ' ')
|
|
67
|
+
if not ' ' in filename:
|
|
68
|
+
filename = re.sub('([^.])\.([^.])', r'\1 \2', filename)
|
|
69
|
+
# to handle .-. case (where - is any single chara)
|
|
70
|
+
filename = re.sub('([^.])\.([^.])', r'\1 \2', filename)
|
|
71
|
+
# If there are still no spaces try replacing hyphens with spaces
|
|
72
|
+
if not ' ' in filename:
|
|
73
|
+
filename = re.sub('([^\-])-([^\-])', r'\1 \2', filename)
|
|
74
|
+
# to handle -.- case (where . is any single chara)
|
|
75
|
+
filename = re.sub('([^\-])-([^\-])', r'\1 \2', filename)
|
|
76
|
+
return filename
|
|
77
|
+
|
|
78
|
+
def __extractSpecialTags(self, filename):
|
|
79
|
+
tags = {'video': ['H264', 'H.264', 'x264', 'XviD', 'DivX', 'MP4'],
|
|
80
|
+
'audio': ['AC3', 'AAC', 'MP3', 'FLAC'],
|
|
81
|
+
'source': ['TV', 'DVD', 'BluRay', 'BD', 'Blu-Ray', 'BDMV']}
|
|
82
|
+
for k, v in tags.iteritems():
|
|
83
|
+
for tag in v:
|
|
84
|
+
m = re.search('(?:[\(\[](?:|[^\)\]]*?[^0-9a-zA-Z\)\]]))(' + tag + ')(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
85
|
+
if m:
|
|
86
|
+
if (k == 'video'):
|
|
87
|
+
self.videoType.append(tag)
|
|
88
|
+
elif (k == 'audio'):
|
|
89
|
+
self.audioType.append(tag)
|
|
90
|
+
elif (k == 'source'):
|
|
91
|
+
self.releaseSource.append(tag)
|
|
92
|
+
filename = filename[:m.start(1)] + '###NO#SUBBER#HERE###' + filename[m.end(1):] # remove the match
|
|
93
|
+
return filename
|
|
94
|
+
|
|
95
|
+
def __extractVideoProfile(self, filename):
|
|
96
|
+
# Check for 8bit/10bit
|
|
97
|
+
tags_10bit = ['Hi10P', 'Hi10', '10bit', '10 bit', '10-bit']
|
|
98
|
+
tags_8bit = ['8bit', '8-bit']
|
|
99
|
+
for tag in tags_10bit:
|
|
100
|
+
if tag in filename:
|
|
101
|
+
self.videoType = ['H264', 'Hi10P']
|
|
102
|
+
# Don't replace Hi10 coz its a subber name
|
|
103
|
+
if tag != 'Hi10':
|
|
104
|
+
filename = filename.replace(tag, '')
|
|
105
|
+
return filename
|
|
106
|
+
if not self.videoType == ['H264', 'Hi10P']:
|
|
107
|
+
for tag in tags_8bit:
|
|
108
|
+
if tag in filename:
|
|
109
|
+
self.videoType = ['H264', '8bit']
|
|
110
|
+
filename = filename.replace(tag, '')
|
|
111
|
+
return filename
|
|
112
|
+
return filename
|
|
113
|
+
|
|
114
|
+
def __extractResolution(self, filename):
|
|
115
|
+
# Match 3 or 4 chars followed by p, i, or x and 3 or 4 more chars, surrounded by any non-alphanumberic chars
|
|
116
|
+
m = re.search('(?:[^0-9a-zA-Z])(\d{3,4}(?:p|i|x\d{3,4}))(?:[^0-9a-zA-Z]|$)', filename)
|
|
117
|
+
if m:
|
|
118
|
+
self.resolution = m.group(1)
|
|
119
|
+
filename = filename[:m.start(1)] + filename[m.end(1):]
|
|
120
|
+
else:
|
|
121
|
+
m = re.search('(?:\[|\(|\d)(HD|SD)(?:\]|\)| |\.)', filename)
|
|
122
|
+
if m:
|
|
123
|
+
self.resolution = m.group(1)
|
|
124
|
+
filename = filename[:m.start(1)] + filename[m.end(1):]
|
|
125
|
+
else:
|
|
126
|
+
m = re.search('(?:\d{1,3})(HD|SD)(?:[^a-zA-Z])', filename)
|
|
127
|
+
if m:
|
|
128
|
+
self.resolution = m.group(1)
|
|
129
|
+
filename = filename[:m.start(1)] + filename[m.end(1):] # Super special case for HD/SD imediately after episode
|
|
130
|
+
return filename
|
|
131
|
+
|
|
132
|
+
def __extractHash(self, filename):
|
|
133
|
+
# Match anything in square or round brackets that is 8 hex digits
|
|
134
|
+
m = re.search('(?:\[|\()((?:[A-F]|[a-f]|\d){8})(?:\]|\))', filename)
|
|
135
|
+
if m:
|
|
136
|
+
self.hash = m.group(1)
|
|
137
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
138
|
+
return filename
|
|
139
|
+
|
|
140
|
+
def __checkIfRemux(self, filename):
|
|
141
|
+
m = re.search('(?:[\(\[][^\)\]]*?[^0-9a-zA-Z\)\]]?)(Remux)(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
142
|
+
return True if m else False
|
|
143
|
+
|
|
144
|
+
def __cleanUpBrackets(self, filename):
|
|
145
|
+
# Can get rid of the brackets that won't contain subber
|
|
146
|
+
filename = re.sub('\((?:[^\)]*?)###NO#SUBBER#HERE##(?:.*?)\)', '', filename)
|
|
147
|
+
filename = re.sub('\[(?:[^\]]*?)###NO#SUBBER#HERE##(?:.*?)\]', '', filename)
|
|
148
|
+
# Strip any empty sets of brackets
|
|
149
|
+
filename = re.sub('(?:\[(?:[^0-9a-zA-Z]*?)\])|(?:\((?:[^0-9a-zA-Z]*?)\))', ' ', filename)
|
|
150
|
+
return filename
|
|
151
|
+
|
|
152
|
+
def __extractSubber(self, filename, remux):
|
|
153
|
+
# Extract the subber from square brackets (or round failing that)
|
|
154
|
+
m = re.search('\[([^\. ].*?)\]', filename)
|
|
155
|
+
if m:
|
|
156
|
+
self.subberTag = m.group(1)
|
|
157
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
158
|
+
else:
|
|
159
|
+
m = re.search('\(([^\. ].*?)\)', filename)
|
|
160
|
+
if m:
|
|
161
|
+
self.subberTag = m.group(1)
|
|
162
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
163
|
+
else:
|
|
164
|
+
m = re.search('{([^\. ].*?)}', filename)
|
|
165
|
+
if m:
|
|
166
|
+
self.subberTag = m.group(1)
|
|
167
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
168
|
+
self.subberTag = self.subberTag.strip(' -')
|
|
169
|
+
# Add the remux string if this was a remux and its not found in the subber tag
|
|
170
|
+
if remux and not 'remux' in self.subberTag.lower():
|
|
171
|
+
# refind remux and remove it
|
|
172
|
+
m = re.search('(?:[\(\[][^\)\]]*?[^0-9a-zA-Z\)\]]?)(Remux)(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
173
|
+
if m:
|
|
174
|
+
filename = filename[:m.start(1)] + filename[m.end(1):]
|
|
175
|
+
if self.subberTag:
|
|
176
|
+
self.subberTag = self.subberTag + '-Remux'
|
|
177
|
+
else:
|
|
178
|
+
self.subberTag = 'Remux'
|
|
179
|
+
return filename
|
|
180
|
+
|
|
181
|
+
def __extractVersion(self, filename):
|
|
182
|
+
# Extract the version number (limit at v7 since V8 is possible in a title...)
|
|
183
|
+
m = re.search('(?:[^a-zA-Z])v([0-7])(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
184
|
+
if m:
|
|
185
|
+
self.version = int(m.group(1))
|
|
186
|
+
filename = filename[:m.start(1) - 1] + filename[m.end(1):]
|
|
187
|
+
return filename
|
|
188
|
+
|
|
189
|
+
def __extractVolumeIfPack(self, filename, title_len):
|
|
190
|
+
# Check if this is a volume pack - only relevant for no extension
|
|
191
|
+
if not self.extension:
|
|
192
|
+
m = re.search('[^0-9a-zA-Z](?:vol(?:ume)?\.? ?)(\d{1,3})(?: ?- ?(?:vol(?:ume)?\.? ?)?(\d{1,3}))?(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
193
|
+
if m:
|
|
194
|
+
self.volumeStart = int(m.group(1))
|
|
195
|
+
if m.group(2):
|
|
196
|
+
self.volumeEnd = int(m.group(2))
|
|
197
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
198
|
+
title_len = m.start()
|
|
199
|
+
return filename, title_len
|
|
200
|
+
|
|
201
|
+
def __extractPv(self, filename):
|
|
202
|
+
# Check if this is a PV release (not relevant if its a pack)
|
|
203
|
+
m = re.search(' PV ?(\d)?(?:[^a-zA-Z0-9]|$)', filename)
|
|
204
|
+
if not self.volumeStart and m:
|
|
205
|
+
self.pv = 0
|
|
206
|
+
if m.group(1):
|
|
207
|
+
self.pv = int(m.group(1))
|
|
208
|
+
filename = filename[:m.start(0)]
|
|
209
|
+
return filename
|
|
210
|
+
|
|
211
|
+
def __extractEpisodeNumbers(self, filename):
|
|
212
|
+
# First check for concurrent episodes (with a +)
|
|
213
|
+
m = re.search('[^0-9a-zA-Z](?:E\.?|Ep(?:i|isode)?s?(?: |\.)?)?(\d{1,4})\+(\d{1,4})(?:[^0-9a-zA-Z]|$)', filename, flags=re.IGNORECASE)
|
|
214
|
+
if m:
|
|
215
|
+
start = int(m.group(1))
|
|
216
|
+
end = int(m.group(2))
|
|
217
|
+
if end == start + 1:
|
|
218
|
+
self.episodeStart = start
|
|
219
|
+
self.episodeEnd = end
|
|
220
|
+
filename = filename[:m.start() + 1]
|
|
221
|
+
if not self.episodeStart:
|
|
222
|
+
# Check for multiple episodes
|
|
223
|
+
if self.extension:
|
|
224
|
+
# no spaces allowed around the hyphen
|
|
225
|
+
ep_search_string = '[^0-9a-zA-Z](?:E\.?|Ep(?:i|isode)?(?: |\.)?)?((?:\d{1,3}|1[0-8]\d{2})(?:\.\d{1})?)-(\d{1,4}(?:\.\d{1})?)(?:[^0-9a-zA-Z]|$)'
|
|
226
|
+
else:
|
|
227
|
+
ep_search_string = '[^0-9a-zA-Z](?:E\.?|Ep(?:i|isode)?(?: |\.)?)?((?:\d{1,3}|1[0-8]\d{2})(?:\.\d{1})?) ?- ?(\d{1,4}(?:\.\d{1})?)(?:[^0-9a-zA-Z]|$)' # probably a pack... so allow spaces around the hyphen
|
|
228
|
+
m = re.search(ep_search_string, filename, flags=re.IGNORECASE)
|
|
229
|
+
if m:
|
|
230
|
+
self.episodeStart = Decimal(m.group(1))
|
|
231
|
+
self.episodeEnd = Decimal(m.group(2))
|
|
232
|
+
filename = filename[:m.start() + 1]
|
|
233
|
+
if not self.episodeStart:
|
|
234
|
+
# Check if there is an episode specifier
|
|
235
|
+
m = re.search('(?:[^0-9a-zA-Z])(E\.?|Ep(?:i|isode)?(?: |\.)?)(\d{1,}(?:\.\d{1})?)(?:[^\d]|$)', filename, flags=re.IGNORECASE)
|
|
236
|
+
if m:
|
|
237
|
+
self.episodeStart = Decimal(m.group(2))
|
|
238
|
+
filename = filename[:m.start() + 1]
|
|
239
|
+
if not self.episodeStart:
|
|
240
|
+
# Check any remaining lonely numbers as episode (towards the end has priority)
|
|
241
|
+
# First try outside brackets
|
|
242
|
+
m = re.search('(?:.*)(?:[^0-9a-zA-Z\.])((?:\d{1,3}|1[0-8]\d{2})(?:\.\d{1})?)(?:[^0-9a-zA-Z]|$)', filename)
|
|
243
|
+
if m:
|
|
244
|
+
self.episodeStart = Decimal(m.group(1))
|
|
245
|
+
filename = filename[:m.start(1)]
|
|
246
|
+
if not self.episodeStart:
|
|
247
|
+
# then allow brackets
|
|
248
|
+
m = re.search('(?:.*)(?:[^0-9a-zA-Z\.\[\(])((?:\d{1,3}|1[0-8]\d{2})(?:\.\d{1})?)(?:[^0-9a-zA-Z\]\)]|$)', filename)
|
|
249
|
+
if m:
|
|
250
|
+
self.episodeStart = Decimal(m.group(1))
|
|
251
|
+
filename = filename[:m.start(1)]
|
|
252
|
+
return filename
|
|
253
|
+
|
|
254
|
+
def __extractShowName(self, filename):
|
|
255
|
+
# Unfortunately its very hard to know if there should be brackets in the title...
|
|
256
|
+
# We really should strip brackets... so to anything with brackets in the title: sorry =(
|
|
257
|
+
# Strip anything thats still in brackets, but backup the first case incase it IS the title...
|
|
258
|
+
m = re.search('\[([^\. ].*?)\]', filename)
|
|
259
|
+
backup_title = ''
|
|
260
|
+
if m:
|
|
261
|
+
backup_title = m.group(1)
|
|
262
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
263
|
+
else:
|
|
264
|
+
m = re.search('\(([^\. ].*?)\)', filename)
|
|
265
|
+
if m:
|
|
266
|
+
backup_title = m.group(1)
|
|
267
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
268
|
+
else:
|
|
269
|
+
m = re.search('{([^\. ].*?)}', filename)
|
|
270
|
+
if m:
|
|
271
|
+
backup_title = m.group(1)
|
|
272
|
+
filename = filename[:m.start()] + filename[m.end():]
|
|
273
|
+
filename = re.sub('(?:\[.*?\])|(?:\(.*?\))', ' ', filename)
|
|
274
|
+
filename = filename.strip(' -')
|
|
275
|
+
filename = re.sub(' (?:.*)', '', filename)
|
|
276
|
+
# Strip any unclosed brackets and anything after them
|
|
277
|
+
filename = re.sub('(.*)(?:[\(\[({].*)$', r'\1', filename)
|
|
278
|
+
self.name = filename.strip(' -')
|
|
279
|
+
if self.name == '':
|
|
280
|
+
self.name = backup_title
|
|
281
|
+
# If we have a subber but no title!? then it must have been a title...
|
|
282
|
+
if self.name == '' and self.subberTag != '':
|
|
283
|
+
self.name = self.subberTag
|
|
284
|
+
self.subberTag = ''
|
|
285
|
+
|
|
286
|
+
def _processFilename(self):
|
|
287
|
+
filename = self.originalFilename
|
|
288
|
+
filename = self.__extractExtension(filename)
|
|
289
|
+
filename = self.__cleanUpSpaces(filename)
|
|
290
|
+
filename = self.__extractSpecialTags(filename)
|
|
291
|
+
filename = self.__extractVideoProfile(filename)
|
|
292
|
+
filename = self.__extractResolution(filename)
|
|
293
|
+
filename = self.__extractHash(filename)
|
|
294
|
+
remux = self.__checkIfRemux(filename)
|
|
295
|
+
filename = self.__cleanUpBrackets(filename)
|
|
296
|
+
filename = self.__extractSubber(filename, remux)
|
|
297
|
+
filename = self.__extractVersion(filename)
|
|
298
|
+
# Store the possible length of the title
|
|
299
|
+
title_len = len(filename)
|
|
300
|
+
filename, title_len = self.__extractVolumeIfPack(filename, title_len)
|
|
301
|
+
filename = self.__extractPv(filename)
|
|
302
|
+
if self.pv == -1:
|
|
303
|
+
filename = self.__extractEpisodeNumbers(filename)
|
|
304
|
+
# Truncate remainder to title length if needed (for where volume was found)
|
|
305
|
+
filename = filename[:title_len]
|
|
306
|
+
# Strip any trailing opening brackets
|
|
307
|
+
filename = filename.rstrip('([{')
|
|
308
|
+
self.__extractShowName(filename)
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
trackma/extras/plex.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
|
|
3
|
+
import ntpath
|
|
4
|
+
import re
|
|
5
|
+
import urllib2
|
|
6
|
+
import xml.dom.minidom as xdmd
|
|
7
|
+
|
|
8
|
+
import trackma.utils as utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_config():
|
|
12
|
+
# get configs from file
|
|
13
|
+
configfile = utils.get_root_filename('config.json')
|
|
14
|
+
try:
|
|
15
|
+
config = utils.parse_config(configfile, utils.config_defaults)
|
|
16
|
+
except IOError:
|
|
17
|
+
raise utils.EngineFatal("Couldn't open config file.")
|
|
18
|
+
|
|
19
|
+
plex_host_port = config['plex_host']+":"+config['plex_port']
|
|
20
|
+
|
|
21
|
+
if config['tracker_type'] == "plex":
|
|
22
|
+
enabled = True
|
|
23
|
+
else:
|
|
24
|
+
enabled = False
|
|
25
|
+
|
|
26
|
+
return [enabled, plex_host_port]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def last_watched():
|
|
30
|
+
# returns the last watched file in plex (deprecated, playing_file() is used now)
|
|
31
|
+
hostnport = get_config()[1]
|
|
32
|
+
sections = "http://"+hostnport+"/library/sections"
|
|
33
|
+
sedoc = xdmd.parse(urllib2.urlopen(sections))
|
|
34
|
+
|
|
35
|
+
leng = int(sedoc.getElementsByTagName("MediaContainer")[0].getAttribute("size"))
|
|
36
|
+
|
|
37
|
+
# compare timestamps in the sections to get the filename
|
|
38
|
+
tstamps = []
|
|
39
|
+
for item in xrange(leng):
|
|
40
|
+
key = sedoc.getElementsByTagName("Directory")[item].getAttribute("key")
|
|
41
|
+
xd = xdmd.parse(urllib2.urlopen(sections+"/"+key+"/recentlyViewed"))
|
|
42
|
+
tstamps.append(xd.getElementsByTagName("Video")[0].getAttribute("lastViewedAt"))
|
|
43
|
+
|
|
44
|
+
key = sedoc.getElementsByTagName("Directory")[tstamps.index(max(tstamps))].getAttribute("key")
|
|
45
|
+
url = sections+"/"+key+"/recentlyViewed"
|
|
46
|
+
|
|
47
|
+
doc = xdmd.parse(urllib2.urlopen(url))
|
|
48
|
+
attr = doc.getElementsByTagName("Part")[0].getAttribute("file")
|
|
49
|
+
fname = urllib2.unquote(ntpath.basename(attr)[:-4])
|
|
50
|
+
|
|
51
|
+
return fname
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def status():
|
|
55
|
+
# returns the plex status of the first active session
|
|
56
|
+
hostnport = get_config()[1]
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
session_url = "http://"+hostnport+"/status/sessions"
|
|
60
|
+
sdoc = xdmd.parse(urllib2.urlopen(session_url))
|
|
61
|
+
except urllib2.URLError:
|
|
62
|
+
return "NOT_RUNNING"
|
|
63
|
+
|
|
64
|
+
active = int(sdoc.getElementsByTagName("MediaContainer")[0].getAttribute("size"))
|
|
65
|
+
|
|
66
|
+
if active:
|
|
67
|
+
return "ACTIVE"
|
|
68
|
+
else:
|
|
69
|
+
return "IDLE"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def timer_from_file():
|
|
73
|
+
# returns 80% of video duration for the update timer
|
|
74
|
+
hostnport = get_config()[1]
|
|
75
|
+
session_url = "http://"+hostnport+"/status/sessions"
|
|
76
|
+
sdoc = xdmd.parse(urllib2.urlopen(session_url))
|
|
77
|
+
|
|
78
|
+
if status() == "IDLE":
|
|
79
|
+
return 20
|
|
80
|
+
|
|
81
|
+
duration = int(sdoc.getElementsByTagName("Video")[0].getAttribute("duration"))
|
|
82
|
+
# voffset = int(sdoc.getElementsByTagName("Video")[0].getAttribute("viewOffset"))
|
|
83
|
+
|
|
84
|
+
return round((duration*0.80)/60000)*60
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def playing_file():
|
|
88
|
+
# returns the filename of the currently playing file
|
|
89
|
+
hostnport = get_config()[1]
|
|
90
|
+
|
|
91
|
+
if status() == "IDLE":
|
|
92
|
+
return False
|
|
93
|
+
|
|
94
|
+
session_url = "http://"+hostnport+"/status/sessions"
|
|
95
|
+
sdoc = xdmd.parse(urllib2.urlopen(session_url))
|
|
96
|
+
|
|
97
|
+
attr = sdoc.getElementsByTagName("Part")[0].getAttribute("file")
|
|
98
|
+
name = urllib2.unquote(ntpath.basename(attr)[:-4])
|
|
99
|
+
|
|
100
|
+
return name
|
trackma/extras/plex.pyc
ADDED
|
Binary file
|
trackma/lib/__init__.py
ADDED
|
File without changes
|
trackma/lib/__init__.pyc
ADDED
|
Binary file
|
trackma/lib/lib.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# This file is part of Trackma.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License
|
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
import trackma.utils as utils
|
|
18
|
+
|
|
19
|
+
class lib(object):
|
|
20
|
+
"""
|
|
21
|
+
Base interface for creating API implementations for Trackma.
|
|
22
|
+
|
|
23
|
+
messenger: Messenger object to send useful messages to
|
|
24
|
+
mediatype: String containing the media type to be used
|
|
25
|
+
"""
|
|
26
|
+
name = 'lib'
|
|
27
|
+
version = 'dummy'
|
|
28
|
+
msg = None
|
|
29
|
+
|
|
30
|
+
api_info = { 'name': 'BaseAPI', 'version': 'undefined', 'merge': False }
|
|
31
|
+
"""
|
|
32
|
+
api_info is a dictionary containing useful information about the API itself
|
|
33
|
+
name: API name
|
|
34
|
+
version: API version
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
mediatypes = dict()
|
|
38
|
+
"""
|
|
39
|
+
mediatypes is a dictionary containing the possible mediatypes for the current API.
|
|
40
|
+
An example mediatype should look like this:
|
|
41
|
+
::
|
|
42
|
+
|
|
43
|
+
mediatypes['anime'] = {
|
|
44
|
+
'has_progress': True,
|
|
45
|
+
'can_add': True,
|
|
46
|
+
'can_delete': True,
|
|
47
|
+
'can_score': True,
|
|
48
|
+
'can_status': True,
|
|
49
|
+
'can_update': True,
|
|
50
|
+
'can_play': True,
|
|
51
|
+
'status_start': 1,
|
|
52
|
+
'status_finish': 2,
|
|
53
|
+
'statuses': [1, 2, 3, 4, 6],
|
|
54
|
+
'statuses_dict': { 1: 'Watching', 2: 'Completed', 3: 'On Hold', 4: 'Dropped', 6: 'Plan to Watch' },
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
default_mediatype = None
|
|
60
|
+
|
|
61
|
+
# Supported signals for the data handler
|
|
62
|
+
signals = {
|
|
63
|
+
'show_info_changed': None,
|
|
64
|
+
'userconfig_changed': None,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
def __init__(self, messenger, account, userconfig):
|
|
68
|
+
"""Initializes the API"""
|
|
69
|
+
self.userconfig = userconfig
|
|
70
|
+
self.msg = messenger
|
|
71
|
+
self.msg.info(self.name, 'Initializing...')
|
|
72
|
+
|
|
73
|
+
if not userconfig.get('mediatype'):
|
|
74
|
+
userconfig['mediatype'] = self.default_mediatype
|
|
75
|
+
|
|
76
|
+
if userconfig['mediatype'] in self.mediatypes:
|
|
77
|
+
self.mediatype = userconfig['mediatype']
|
|
78
|
+
else:
|
|
79
|
+
raise utils.APIFatal('Unsupported mediatype %s.' % userconfig['mediatype'])
|
|
80
|
+
|
|
81
|
+
self.api_info['mediatype'] = self.mediatype
|
|
82
|
+
self.api_info['supported_mediatypes'] = self.mediatypes.keys()
|
|
83
|
+
|
|
84
|
+
def _emit_signal(self, signal, *args):
|
|
85
|
+
try:
|
|
86
|
+
if self.signals[signal]:
|
|
87
|
+
self.signals[signal](*args)
|
|
88
|
+
except KeyError:
|
|
89
|
+
raise Exception("Call to undefined signal.")
|
|
90
|
+
|
|
91
|
+
def _get_userconfig(self, key):
|
|
92
|
+
return self.userconfig.get(key)
|
|
93
|
+
|
|
94
|
+
def _set_userconfig(self, key, value):
|
|
95
|
+
self.userconfig[key] = value
|
|
96
|
+
|
|
97
|
+
def connect_signal(self, signal, callback):
|
|
98
|
+
try:
|
|
99
|
+
self.signals[signal] = callback
|
|
100
|
+
except KeyError:
|
|
101
|
+
raise utils.EngineFatal("Invalid signal.")
|
|
102
|
+
|
|
103
|
+
def check_credentials(self):
|
|
104
|
+
"""Checks if credentials are correct; returns True or False."""
|
|
105
|
+
raise NotImplementedError
|
|
106
|
+
|
|
107
|
+
def fetch_list(self):
|
|
108
|
+
"""
|
|
109
|
+
Fetches the remote list and returns a dictionary of show dictionaries.
|
|
110
|
+
|
|
111
|
+
It should return a dictionary with the show ID as the key and a show dictionary as its value.
|
|
112
|
+
You can create an empty show dictionary with the :func:`utils.show` function.
|
|
113
|
+
"""
|
|
114
|
+
raise NotImplementedError
|
|
115
|
+
|
|
116
|
+
def add_show(self, item):
|
|
117
|
+
"""
|
|
118
|
+
Adds the **item** in the remote server list. The **item** is a show dictionary passed by the Data Handler.
|
|
119
|
+
"""
|
|
120
|
+
raise NotImplementedError
|
|
121
|
+
|
|
122
|
+
def update_show(self, item):
|
|
123
|
+
"""
|
|
124
|
+
Sends the updates of a show to the remote site.
|
|
125
|
+
|
|
126
|
+
This function gets called every time a show should be updated remotely,
|
|
127
|
+
and in a queue it may be called many times consecutively, so you should
|
|
128
|
+
use a boolean (or other method) to login only once.
|
|
129
|
+
|
|
130
|
+
"""
|
|
131
|
+
raise NotImplementedError
|
|
132
|
+
|
|
133
|
+
def delete_show(self, item):
|
|
134
|
+
"""
|
|
135
|
+
Deletes the **item** in the remote server list. The **item** is a show dictionary passed by the Data Handler.
|
|
136
|
+
"""
|
|
137
|
+
raise NotImplementedError
|
|
138
|
+
|
|
139
|
+
def search(self, criteria):
|
|
140
|
+
"""
|
|
141
|
+
Called when the data handler needs a detailed list of shows from the remote server.
|
|
142
|
+
It should return a list of show dictionaries with the additional 'extra' key (which is a list of tuples)
|
|
143
|
+
containing any additional detailed information about the show.
|
|
144
|
+
"""
|
|
145
|
+
raise NotImplementedError
|
|
146
|
+
|
|
147
|
+
def request_info(self, items):
|
|
148
|
+
# Request detailed information for requested shows
|
|
149
|
+
raise NotImplementedError
|
|
150
|
+
|
|
151
|
+
def logout(self):
|
|
152
|
+
# This is called whenever the API won't be required
|
|
153
|
+
# for a good while
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
def media_info(self):
|
|
157
|
+
"""Return information about the currently selected mediatype."""
|
|
158
|
+
return self.mediatypes[self.mediatype]
|
|
159
|
+
|
|
160
|
+
def set_message_handler(self, message_handler):
|
|
161
|
+
self.msg = message_handler
|
|
162
|
+
|
trackma/lib/lib.pyc
ADDED
|
Binary file
|