-
Notifications
You must be signed in to change notification settings - Fork 16
/
library.py
67 lines (49 loc) · 1.94 KB
/
library.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
from section import Section
from episode import Episode
from show import Show
from movie import Movie
class Library(object):
def __init__(self, server):
self.server = server
def __str__(self):
return "<Library: %s>" % self.server
def __repr__(self):
return "<Library: %s>" % self.server
@property
def sections(self):
""" returns a list of all sections. """
elem = self.server.query("/library/sections")
seclist = [Section(e, self.server) for e in elem]
return seclist
@property
def shows(self):
""" returns a list of all sections with type 'show'. """
elem = self.server.query("/library/sections")
seclist = [Section(e, self.server) for e in elem if e.attrib['type'] == 'show']
return seclist
@property
def movies(self):
""" returns a list of all sections with type 'movie'. """
elem = self.server.query("/library/sections")
seclist = [Section(e, self.server) for e in elem if e.attrib['type'] == 'movie']
return seclist
def findAll(self, name, type=None):
query = "/search?query=%s" % name.replace(" ", "%20")
element = self.server.query(query)
items = []
for e in element:
if type and e.attrib['type'] != type:
continue
if e.attrib['type'] == 'show':
items.append(Show(e, self.server))
elif e.attrib['type'] == 'movie':
items.append(Movie(e, self.server))
elif e.attrib['type'] == 'episode':
items.append(Episode(e, self.server))
return items
def findShows(self, name):
return self.findAll(name, type='show')
def findMovies(self, name):
return self.findAll(name, type='movie')
def findEpisodes(self, name):
return self.findAll(name, type='episode')