summaryrefslogtreecommitdiff
path: root/plugin.video.montreal.greek-tv/resources/lib/directory.py
blob: 3ae0b049c8a940f6fca1067a34dd50e5cf487fcb (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# -*- coding: utf-8 -*-

'''
    Tulip routine libraries, based on lambda's lamlib
    Author Twilight0

        License summary below, for more details please read license.txt file

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 2 of the License, or
        (at your option) any later version.
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

import sys
import urllib
import control



def add(items, cacheToDisc=True, content=None, mediatype=None, infotype='video'):

    if items is None or len(items) == 0:
        return

    sysicon = control.join(control.addonInfo('path'), 'resources', 'media')
    sysimage = control.addonInfo('icon')
    sysfanart = control.addonInfo('fanart')

    for i in items:
        try:
            try:
                label = control.lang(i['title']).encode('utf-8')
            except:
                label = i['title']

            if 'label' in i and not i['label'] == '0':
                label = i['label']

            if 'image' in i and not i['image'] == '0':
                image = i['image']
            elif 'poster' in i and not i['poster'] == '0':
                image = i['poster']
            elif 'icon' in i and not i['icon'] == '0':
                image = control.join(sysicon, i['icon'])
            else:
                image = sysimage

            if 'banner' in i and not i['banner'] == '0':
                banner = i['banner']
            elif 'fanart' in i and not i['fanart'] == '0':
                banner = i['fanart']
            else:
                banner = image

            fanart = i['fanart'] if 'fanart' in i and not i['fanart'] == '0' else sysfanart

            isFolder = False if 'isFolder' in i and not i['isFolder'] == '0' else True

            url = '%s?action=%s' % (sys.argv[0], i['action'])

            try:
                url += '&url=%s' % urllib.quote_plus(i['url'])
            except:
                pass
            try:
                url += '&image=%s' % urllib.quote_plus(i['image'])
            except:
                pass

            cm = []
            menus = i['cm'] if 'cm' in i else []

            for menu in menus:
                try:
                    try:
                        tmenu = control.lang(menu['title']).encode('utf-8')
                    except:
                        tmenu = menu['title']
                    qmenu = urllib.urlencode(menu['query'])
                    cm.append((tmenu, 'RunPlugin(%s?%s)' % (sys.argv[0], qmenu)))
                except:
                    pass

            meta = dict((k, v) for k, v in i.iteritems() if not k == 'cm' and not v == '0')
            if mediatype is not None:
                meta['mediatype'] = mediatype

            item = control.item(label=label, iconImage=image, thumbnailImage=image)

            item.setArt({'icon': image, 'thumb': image, 'poster': image, 'tvshow.poster': image, 'season.poster': image, 'banner': banner, 'tvshow.banner': banner, 'season.banner': banner})

            item.setProperty('Fanart_Image', fanart)

            item.addContextMenuItems(cm)
            item.setInfo(type=infotype, infoLabels = meta)
            if not isFolder:
                item.setProperty('IsPlayable', 'true')

            control.addItem(handle=int(sys.argv[1]), url=url, listitem=item, isFolder=isFolder)
        except:
            pass

    try:
        i = items[0]
        if i['next'] == '':
            raise Exception()

        url = '%s?action=%s&url=%s' % (sys.argv[0], i['nextaction'], urllib.quote_plus(i['next']))
        icon = i['nexticon'] if 'nexticon' in i else control.join(sysicon, 'next.png')
        fanart = i['nextfanart'] if 'nextfanart' in i else sysfanart
        try:
            label = control.lang(i['nextlabel']).encode('utf-8')
        except:
            label = 'next'

        item = control.item(label=label, iconImage=icon, thumbnailImage=icon)
        item.setArt({'icon': icon, 'thumb': icon, 'poster': icon, 'tvshow.poster': icon, 'season.poster': icon, 'banner': icon, 'tvshow.banner': icon, 'season.banner': icon})
        item.setProperty('Fanart_Image', fanart)
        control.addItem(handle=int(sys.argv[1]), url=url, listitem=item, isFolder=True)
    except:
        pass

    if not content is None:
        control.content(int(sys.argv[1]), content)

    control.directory(int(sys.argv[1]), cacheToDisc=cacheToDisc)


def resolve(url, meta=None, icon=None):

    item = control.item(path=url)

    if not icon is None:
        item.setArt({'icon': icon, 'thumb': icon})

    if not meta is None:
        item.setInfo(type='Video', infoLabels=meta)

    control.resolve(int(sys.argv[1]), True, item)