move sys.argv hack to tubelib/youtube
[enigma2-plugins.git] / tubelib / src / youtube / VideoCategories.py
1 #enigma2
2 from Components.config import config
3 #youtube
4 from apiclient.discovery import build
5 #local
6 from YoutubeQueryBase import YoutubeQueryBase
7 from ThreadedRequest import ThreadedRequest
8
9 class VideoCategories(YoutubeQueryBase):
10         def list(self, callback, lang=None, region=None):
11                 if not lang:
12                         lang = config.plugins.mytube.search.lr.value
13                 if not region:
14                         region = lang
15                 self._args = {
16                         'part' : 'id,snippet',
17                         'hl' : lang,
18                         'regionCode' : region,
19                         'fields' : 'items(id,snippet(title))'
20                 }
21                 return self._doQuery(callback)
22
23         def _doQuery(self, callback):
24                 request = self._youtube.videoCategories().list(**self._args)
25                 return self._query(callback, request)
26
27         def _onResult(self, success, data):
28                 categories = []
29                 if success:
30                         for item in data['items']:
31                                 categories.append(VideoCategory(item))
32                 self._callback(success, categories)
33
34 class VideoCategory(object):
35         def __init__(self, entry):
36                 self._entry = entry
37
38         def getId(self):
39                 return str(self._entry["id"])
40         id = property(getId)
41
42         def getTitle(self):
43                 return str(self._entry["snippet"]["title"])
44         title = property(getTitle)