-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
215 lines (185 loc) · 8.97 KB
/
main.py
File metadata and controls
215 lines (185 loc) · 8.97 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import os
import sys
import requests
import xbmc
from urlparse import parse_qsl
import xbmcgui
import xbmcplugin
import resources.lib.playerfactory_handler as pf
__url__ = sys.argv[0]
__handle__ = int(sys.argv[1])
def get_videos():
"""
Get the list of videofiles/streams
:return: list
"""
dc = xbmcplugin.getSetting(__handle__, "dc")
kodi_token = xbmcplugin.getSetting(__handle__, "token")
headers = {'content-type': 'application/json', 'kodi_token': kodi_token}
with requests.get(dc, headers=headers) as response:
if response.status_code != 200:
return False
data = response.json()
collection = []
user = None
if 'user_name' in data['user_details'] and data['user_details']['user_name'] is not None:
user = data['user_details']['user_name']
elif 'f_name' in data['user_details']:
user = data['user_details']['f_name']
xbmc.executebuiltin("Notification(BaivaruTV,Welcome back %s)" % user)
for item in data['playlist']:
_data = {
'name': item['name'],
'thumb': item['poster'],
'video': item['location'],
'genre': str(item['genre']),
"cast": item['cast'],
"director": item['director'],
"tagline": item['tagline'],
"year": item['year'],
"rating": item['imdbrating']
}
collection.append(_data)
VIDEOS = {'movies': collection}
return VIDEOS['movies']
def play_video(path):
"""
Play a video by the provided path.
:param path: str
:return: None
"""
play_item = xbmcgui.ListItem(path=path)
xbmc.Player().play(play_item, True)
# xbmcplugin.setResolvedUrl(__handle__, True, listitem=play_item)
def list_videos():
"""
Create the list of playable videos in the Kodi interface.
:return: None
"""
videos = get_videos()
if not videos:
xbmc.executebuiltin("Notification(BaivaruTV,Unauthorized. Please use a valid token)")
else:
listing = []
for video in videos:
list_item = xbmcgui.ListItem(label=video['name'], thumbnailImage=video['thumb'])
list_item.setProperty('fanart_image', video['thumb'])
list_item.setInfo('video', {'title': video['name'], 'genre': video['genre'], 'cast': list(video['cast']),
'director': video['director'], 'tagline': video['tagline'],
'year': video['year'], 'rating': video['rating']})
list_item.setProperty('IsPlayable', 'true')
# Example: plugin://plugin.video.example/?action=play&video=http://www.vidsplay.com/vids/crab.mp4
# url = '{0}?action=play&video={1}'.format(__url__, video['video'])
url = video['video']
is_folder = False
listing.append((url, list_item, is_folder))
xbmcplugin.addDirectoryItems(__handle__, listing, len(listing))
xbmcplugin.setContent(__handle__, 'Movies')
xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_VIDEO_TITLE)
xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_VIDEO_RATING)
xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.endOfDirectory(__handle__)
def router(paramstring):
"""
Router function that calls other functions
depending on the provided paramstring, also creates the playercorefactory file
:param paramstring:
:return:
"""
player_core_path = xbmc.translatePath('special://userdata/playercorefactory.xml')
external_player = xbmcplugin.getSetting(__handle__, "external_player")
# xbmc.executebuiltin("Notification(BaivaruTV,%s)" % external_player)
if external_player == "1":
if xbmc.getCondVisibility('system.platform.linux') and xbmc.getCondVisibility('system.platform.android'):
if not os.path.exists(player_core_path):
pf.create_adroid_vlc(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if read_lines[3] != "<filename>org.videolan.vlc</filename>":
pf.create_adroid_vlc(player_core_path)
if xbmc.getCondVisibility('system.platform.linux') and not xbmc.getCondVisibility(
'system.platform.android'):
if not os.path.exists(player_core_path):
pf.create_linux(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if read_lines[3] != "<filename>/usr/bin/vlc</filename>":
pf.create_linux(player_core_path)
elif xbmc.getCondVisibility('system.platform.windows'):
if os.path.exists("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe"):
if not os.path.exists(player_core_path):
pf.create_win32(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if read_lines[3] != "<filename>C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe</filename>":
pf.create_win32(player_core_path)
elif os.path.exists("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"):
if not os.path.exists(player_core_path):
pf.create_win64(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if read_lines[3] != "<filename>C:\\Program Files\\VideoLAN\\VLC\\vlc.exe</filename>":
pf.create_win64(player_core_path)
elif xbmc.getCondVisibility("system.platform.osx"):
if not os.path.exists(player_core_path):
pf.create_osx(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if read_lines[3] != "<filename>/Applications/VLC.app/Contents/MacOS/VLC</filename>":
pf.create_osx(player_core_path)
elif external_player == "2":
if not os.path.exists(player_core_path):
if xbmc.getCondVisibility('system.platform.linux') and xbmc.getCondVisibility('system.platform.android'):
pf.create_android_mxplayer_free(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if xbmc.getCondVisibility('system.platform.linux') and xbmc.getCondVisibility('system.platform.android'):
if read_lines[3] != "<filename>com.mxtech.videoplayer.ad</filename>":
pf.create_android_mxplayer_free(player_core_path)
elif external_player == "3":
if not os.path.exists(player_core_path):
if xbmc.getCondVisibility('system.platform.linux') and xbmc.getCondVisibility('system.platform.android'):
pf.create_android_mxplayer_pro(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if xbmc.getCondVisibility('system.platform.linux') and xbmc.getCondVisibility('system.platform.android'):
if read_lines[3] != "<filename>com.mxtech.videoplayer.pro</filename>":
pf.create_android_mxplayer_pro(player_core_path)
elif external_player == "4":
if not os.path.exists(player_core_path):
if xbmc.getCondVisibility('system.platform.windows'):
if os.path.exists("C:\\Program Files (x86)\\DAUM\\PotPlayer\\PotPlayerMini.exe"):
pf.create_win32_pot_player(player_core_path)
elif os.path.exists("C:\\Program Files\\DAUM\\PotPlayer\\PotPlayerMini64.exe"):
pf.create_win64_pot_player(player_core_path)
else:
file = open(player_core_path)
read_lines = file.readlines()
if xbmc.getCondVisibility('system.platform.windows'):
if os.path.exists("C:\\Program Files (x86)\\DAUM\\PotPlayer\\PotPlayerMini.exe"):
if read_lines[3] != "<filename>C:\\Program Files (x86)\\DAUM\\PotPlayer\\PotPlayerMini.exe</filename>":
pf.create_win32_pot_player(player_core_path)
elif os.path.exists("C:\\Program Files\\DAUM\\PotPlayer\\PotPlayerMini64.exe"):
if read_lines[3] != "<filename>C:\\Program Files\\DAUM\\PotPlayer\\PotPlayerMini64.exe</filename>":
pf.create_win64_pot_player(player_core_path)
elif external_player == "0":
if os.path.exists(player_core_path):
try:
os.remove(player_core_path)
except:
pass
params = dict(parse_qsl(paramstring[1:]))
if params:
if params['action'] == 'play':
play_video(params['video'])
else:
list_videos()
if __name__ == '__main__':
router(sys.argv[2])