move sys.argv hack to tubelib/youtube
[enigma2-plugins.git] / tubelib / src / youtube / YoutubeQueryBase.py
1 from ThreadedRequest import ThreadedRequest
2
3 class YoutubeQueryBase(object):
4         def __init__(self, youtube):
5                 self._youtube = youtube
6                 self._callback = None
7                 self._request = None
8                 self._data = None
9                 self._args = {}
10
11         def _query(self, callback, query, subquery=None):
12                 self._callback = callback
13                 self._request = ThreadedRequest(query, self.__onResult, subquery=subquery)
14                 return self._request
15
16         def __onResult(self, success, data):
17                 if success:
18                         self._data = data
19                 else:
20                         self._data = {}
21                 self._onResult(success, data)
22
23         def getData(self):
24                 return self._data
25         data = property(getData)
26
27         def hasNextPage(self):
28                 return self._data.has_key("nextPageToken")
29
30         def nextPage(self):
31                 if self.hasNextPage():
32                         self._args['pageToken'] = self._data['nextPageToken']
33                         self._doQuery(self._callback)
34                         return True
35                 return False
36
37         def hasPrevPage(self):
38                 return self._data.has_key("prevPageToken")
39
40         def prevPage(self):
41                 if self.hasPrevPage():
42                         self._args['pageToken'] = self._data['prevPageToken']
43                         self._doQuery(self._callback)
44                         return True
45                 return False
46
47         def getTotalResults(self):
48                 if not self._data.has_key("pageInfo"):
49                         return 0
50                 return self._data["pageInfo"]["totalResults"] or 0
51
52         def _doQuery(self, callback):
53                 raise Exception("Not Implemented")
54
55         def _onResult(self, success, data):
56                 raise Exception("Not Implemented")