-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugintools.py
131 lines (103 loc) · 4.15 KB
/
plugintools.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
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
# -*- coding: utf-8 -*-
#---------------------------------------------------------------------------
# Plugin Tools v1.0.2
#---------------------------------------------------------------------------
# License: GPL (http://www.gnu.org/licenses/gpl-3.0.html)
# Based on code from youtube and parsedom addons
# Author:
# http://www.mimediacenter.info/plugintools
#---------------------------------------------------------------------------
# Changelog:
# 1.0.0
# - First release
# 1.0.1
# - If find_single_match can't find anything, it returns an empty string
# - Remove addon id from this module, so it remains clean
# 1.0.2
# - Added parameter on "add_item" to say that item is playable
#---------------------------------------------------------------------------
import xbmc
import xbmcplugin
import xbmcaddon
import xbmcgui
import urllib
import urllib2
import re
import sys
module_log_enabled = False
# Write something on XBMC log
def log(message):
xbmc.log("AVEZY " + message)
# Write this module messages on XBMC log
def debug(message):
debug_enabled = getSetting('debug_enabled')
if debug_enabled == 'true':
xbmc.log("AVEZY [DEBUG] "+message)
def getSetting(settingName):
settingValue = xbmcaddon.Addon().getSetting(settingName)
return settingValue
# Write this module messages on XBMC log
def _log(message):
if module_log_enabled:
xbmc.log("plugintools."+message)
# Parse XBMC params - based on script.module.parsedom addon
def get_params():
_log("get_params")
param_string = sys.argv[2]
_log("get_params "+str(param_string))
commands = {}
if param_string:
split_commands = param_string[param_string.find('?') + 1:].split('&')
for command in split_commands:
_log("get_params command="+str(command))
if len(command) > 0:
if "=" in command:
split_command = command.split('=')
key = split_command[0]
value = urllib.unquote_plus(split_command[1])
commands[key] = value
else:
commands[command] = ""
_log("get_params "+repr(commands))
return commands
# Fetch text content from an URL
def read(url):
_log("read "+url)
f = urllib2.urlopen(url)
data = f.read()
f.close()
return data
# Parse string and extracts multiple matches using regular expressions
def find_multiple_matches(text,pattern):
_log("find_multiple_matches pattern="+pattern)
matches = re.findall(pattern,text,re.DOTALL)
return matches
# Parse string and extracts first match as a string
def find_single_match(text,pattern):
_log("find_single_match pattern="+pattern)
result = ""
try:
matches = re.findall(pattern,text, flags=re.DOTALL)
result = matches[0]
except:
result = ""
return result
def add_item( action="" , title="" , plot="" , url="" ,thumbnail="" , isPlayable = False, folder=True ):
_log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] folder=["+str(folder)+"]")
listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
listitem.setInfo( "video", { "Title" : title, "FileName" : title, "Plot" : plot } )
if url.startswith("plugin://") or isPlayable:
itemurl = url
listitem.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=folder)
else:
itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&plot=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( plot ))
xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=folder)
def close_item_list():
_log("close_item_list")
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
def play_resolved_url(url):
_log("play_resolved_url ["+url+"]")
listitem = xbmcgui.ListItem(path=url)
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)