-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpwebFileInfo.py
71 lines (51 loc) · 1.6 KB
/
vpwebFileInfo.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'kovtash'
POSTER_DIR = '/Users/kovtash/vpweb/poster'
import os,re
class vpwebFileInfo():
def __init__(self,filePath):
self._name=None
self._season=None
self._episode=None
fileName=os.path.splitext(os.path.basename(filePath))[0]
patterns=[re.compile('(?P<name>.*)S(?P<season>[\d]+)E(?P<episode>[\d]+)'),
re.compile('(?P<name>.*)S(?P<season>[\d]+).*'),
re.compile('(?P<name>.*)E(?P<episode>[\d]+).*')]
fileInfo =None
for pattern in patterns:
fileInfo=pattern.search(fileName)
if fileInfo is not None:
break
if fileInfo is not None:
name=fileInfo.group('name')
try:
self._season=fileInfo.group('season')
except IndexError:
pass
try:
self._episode=fileInfo.group('episode')
except IndexError:
pass
else:
name=fileName
currentName=str(name)
currentName=currentName.replace('_',' ')
currentName=currentName.strip(' ')
self._name=currentName
@property
def name(self):
return self._name
@property
def season(self):
return self._season
@property
def episode(self):
return self._episode
@property
def poster(self):
posterPath=os.path.join(POSTER_DIR,self.name.replace(' ','_'))
if os.path.exists(posterPath):
return posterPath
else:
return None