2018-03-02, 21:57
I Wrote this guide about a year ago and i'm donating it here hoping to help out those trying to learn.
unfortunately all of the code wont fit here as it has the documentation written inside
these are the imported modules that you must use
unfortunately all of the code wont fit here as it has the documentation written inside
these are the imported modules that you must use
first half[/i]python:
import xbmc,xbmcaddon,xbmcplugin,xbmcgui,os,base64,re,urllib,json,requests,urlparse,sys,webbrowser,fnmatch,feedparser,pytz,time
from bs4 import BeautifulSoup as BS
from datetime import date, datetime, timedelta
from urllib import urlencode
try:from DateTime import DateTime
except:pass
[i]
[/i]python:
#==#######################################################################################################################==#
#==################################## Logging ##########################################################==#
#==#######################################################################################################################==#
Log = lambda x: xbmc.log(str(x),2) #
#===========================================================================================================================#
#== Description # Send Strings, Lists, Tuplies, Dictionarys To The Log ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== Log(MYSTRING) # NOTICE: This is a String ==#
#== Log(MYLIST) # NOTICE: [Item1,Item2,Item3,Item4] ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Execute Builtin ###########################################################==#
#==#######################################################################################################################==#
Exe = xbmc.executebuiltin #
#===========================================================================================================================#
#== Description # Executes a built in Kodi function. ==#
#===========================================================================================================================#
#== Website # http://kodi.wiki/view/List_of_Built_In_Functions ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== Exe("PlayMedia(E:/mov.mp4)") # Plays The Video ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## RunScript ##########################################################==#
#==#######################################################################################################################==#
RunScript = lambda x: Exe('RunScript(%s)'%(x)) #
#===========================================================================================================================#
#== Description # Runs the python script. You must specify the full path to the script. ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== RunScript("path/script.py") # ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Check For Addons New Addons ########################################################==#
#==#######################################################################################################################==#
#== Checks For Any New Addons In The Addons Folder ==#
#==_______________________________________________________________________________________________________________________==#
UpdateAddons = lambda: Exe('UpdateLocalAddons') #
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#==UpdateAddons() # This is a String ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Check For Addons New Addons ########################################################==#
#==#######################################################################################################################==#
#== Checks For Any New Addons In The Addons Folder ==#
#==_______________________________________________________________________________________________________________________==#
Fresh = lambda: Exe("XBMC.Container.Refresh") #
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#==UpdateAddons() # This is a String ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Action ##########################################################==#
#==#######################################################################################################################==#
#==_______________________________________________________________________________________________________________________==#
Action = lambda x: Exe('Action(%s)'%(x)) #
#===========================================================================================================================#
#== Description # Sends An Action To Kodi ==#
#== Website # https://codedocs.xyz/xbmc/xbmc/group__ko...__ids.html ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Reload Keymaps ##########################################################==#
#==#######################################################################################################################==#
#==_______________________________________________________________________________________________________________________==#
ReloadKeymaps = lambda: Action('reloadkeymaps') #
#===========================================================================================================================#
#== Description # Reloads Any Keymap Configurations ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Activate Window ##########################################################==#
#==#######################################################################################################################==#
#== Activates A Window With The Given Name Or ID ==#
#==_______________________________________________________________________________________________________________________==#
Win = lambda x:Exe('ActivateWindow(%s)'%x) #
#===========================================================================================================================#
#== Website # http://kodi.wiki/view/Window_IDs ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== Win('systemsettings') # Opens System Settings ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Play A File ##########################################################==#
#==#######################################################################################################################==#
Play = xbmc.Player().play #
#===========================================================================================================================#
#== Description # Plays A File ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== Play("http://website/file.mp4") # ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Playlist ##########################################################==#
#==#######################################################################################################################==#
Playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) #
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Translate Path ##########################################################==#
#==#######################################################################################################################==#
TranslatePath = xbmc.translatePath #
#===========================================================================================================================#
#== Description # Translates Kodi Paths Like Special To Their Real Definitions ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== TranslatePath('special://home') # c://users/username/appdata/kodi/ ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Sleep ##########################################################==#
#==#######################################################################################################################==#
def Sleep(s=None,m=None,h=None):
s = int(s)*1000 if s else 0
m = int(m)*1000*60 if m else 0
h = int(h)*1000*60*60 if m else 0
xbmc.sleep(s+m+h)
def Sleep2(s=None,m=None,h=None):
s = int(s) if s else 0
m = int(m)*60 if m else 0
h = int(h)*60*60 if m else 0
time.sleep(s+m+h)
#===========================================================================================================================#
#== Description # Allows Time To Pass Before Your Plugin Continues ==#
#===========================================================================================================================#
#== Sleep # Allows WindowXMLDialog and WindowXML Events to Still Be Processed ==#
#== Sleep2 # Allows Nothing To Process While Waiting ==#
#===========================================================================================================================#
##= Usage # Result ==#
#===========================================================================================================================#
#== Sleep(1) or Sleep(m=1) or Sleep(h=1) # Waits 1 Second, Waits 1 Minute, Waits 1 Hour ==#
#== Sleep2(1) or Sleep2(m=1) or Sleep2(h=1) # Waits 1 Second, Waits 1 Minute, Waits 1 Hour ==#
#===========================================================================================================================#
#==#######################################################################################################################==#
#==################################## Auto Play ##########################################################==#
#==#######################################################################################################################==#
# Auto Plays From A List #
def AutoPlay(List):
Playlist.clear()
for i in List:
Playlist.add(i)
Play(Playlist) #
#===========================================================================================================================#
#== Description # Translates Kodi Paths Like Special To Their Real Definitions ==#
#===========================================================================================================================#
#== Usage # Result ==#
#===========================================================================================================================#
#== TranslatePath('special://home') # c://users/username/appdata/kodi/ ==#
#===========================================================================================================================#
Resolved = lambda x,y:xbmcplugin.setResolvedUrl(int(x), True, y)
#############################################################################################################################
Addon = lambda x=None: xbmcaddon.Addon(x) if x else xbmcaddon.Addon() #
#===========================================================================================================================#
# Description # Associates The Given Addon ID To The Addon Class #
# # NOTE: If No ID Given Then Your Plugin ID Will Be Used #
#===========================================================================================================================#
#############################################################################################################################
##################################### Get Addon Info #############################################################
#############################################################################################################################
AddonInfo = xbmcaddon.Addon().getAddonInfo #
#===========================================================================================================================#
## Description # Values #
#===========================================================================================================================#
# Returns the value of an # author, changelog, description, disclaimer, fanart. #
# addon property as a string. # icon, id, name, path,profile, stars, summary, type, version #
#===========================================================================================================================#
## Usage # Result #
#===========================================================================================================================#
# AddonID = AddonInfo('id') # plugin.video.youraddonid #
# AddonName = AddonInfo('name') # your addon name #
#===========================================================================================================================#
#############################################################################################################################
##################################### Get Localized String #############################################################
#############################################################################################################################
AddonString = xbmcaddon.Addon().getLocalizedString #
#===========================================================================================================================#
## Description # Returns Your Addons String #
#===========================================================================================================================#
## Usage # Result #
#===========================================================================================================================#
# AddonString(1000) # This is a String #
#===========================================================================================================================#
#############################################################################################################################
##################################### Get Setting #############################################################
#############################################################################################################################
GetSetting = xbmcaddon.Addon().getSetting #
#===========================================================================================================================#
## Description # Gets The Value Of Your Addons Setting #
#===========================================================================================================================#
## Usage # Result #
#===========================================================================================================================#
# GetSetting("mySettingID") # This my setting value #
#===========================================================================================================================#
#############################################################################################################################
##################################### Set Setting #############################################################
#############################################################################################################################
SetSetting = xbmcaddon.Addon().setSetting #
#===========================================================================================================================#
## Description # Sets A Setting Of Your Addon #
#===========================================================================================================================#
## Usage # Result #
#===========================================================================================================================#
# SetSetting("SettingID",Value) # This is a String #
#===========================================================================================================================#
#############################################################################################################################
##################################### Open Settings #############################################################
#############################################################################################################################
OpenSetting = xbmcaddon.Addon().openSettings #
#===========================================================================================================================#
## Description # Opens Your Addons Settings Menu #
#===========================================================================================================================#
## Usage # Result #
#===========================================================================================================================#
# # This is a String #
# OpenSettings() # [Item1,Item2,Item3,Item4] #
#===========================================================================================================================#
#############################################################################################################################
##################################### Dialog Class #############################################################
#############################################################################################################################
Dialog = xbmcgui.Dialog() #
#===========================================================================================================================#
#############################################################################################################################
##################################### OK Dialog #############################################################
#############################################################################################################################
Ok = lambda x,y=AddonInfo('name'): xbmcgui.Dialog().ok(y,x) if y else Dialog.ok(AddonInfo('name'),x) #
#===========================================================================================================================#
## Description # Gives An Ok Dialog ##
#===========================================================================================================================#
## Usage # Result ##
#===========================================================================================================================#
# Ok("This Message Will Appear") # Will Have Your Addons Name As The Title #
# Ok("New Title","This Message Will Appear") # Will Have "New Title" As The Windows Title #
#===========================================================================================================================#
#############################################################################################################################
##################################### Yes No Dialog #########################################################
#############################################################################################################################
YesNo = lambda message,title=AddonInfo('name'),line2=None,Line3=None,no="NO",yes="YES": xbmcgui.Dialog().yesno(title,message,line2=line2,line3=line3,nolabel=no,yeslabel=yes)
#===========================================================================================================================#
## Description # Gives A Yes No Type Dialog ##
#===========================================================================================================================#
## Usage # YesNo("Would You Like To Close Kodi?") ##
#===========================================================================================================================#
## Result # When The User Presses Yes, True Is Returned ##
#===========================================================================================================================#
#############################################################################################################################
##################################### Input Dialog #########################################################
#############################################################################################################################
Input = lambda title=AddonInfo('name'): xbmcgui.Dialog().input(title,type=type, option=option)
#===========================================================================================================================#
## Description ### Allows The User To Type A Value In The Keyboard ##
#===========================================================================================================================#
#===========================================================================================================================#
## Usage ### Input("Enter Username") ##
#===========================================================================================================================#
## Result ### Returns Whatever The User Enters ##
#===========================================================================================================================#
## Types ### ##
#===========================================================================================================================#
# xbmcgui.INPUT_ALPHANUM (standard keyboard) #
# xbmcgui.INPUT_NUMERIC (format: #) #
# xbmcgui.INPUT_DATE (format: DD/MM/YYYY) #
# xbmcgui.INPUT_TIME (format: HH:MM) #
# xbmcgui.INPUT_IPADDRESS (format: #.#.#.#) #
# xbmcgui.INPUT_PASSWORD (return md5 hash of input, input is masked) #
#===========================================================================================================================#
#############################################################################################################################
##################################### Select Dialog #########################################################
#############################################################################################################################
Select = lambda x,y: xbmcgui.Dialog().select(x,y)
#===========================================================================================================================#
## Description ### Allows The User To Select A Value From A List ##
#===========================================================================================================================#
## Usage ### Select("Select Quality",['1080p','720p','480p','360']) ##
#===========================================================================================================================#
## Result ### Returns Whatever The User Selects ##
#===========================================================================================================================#
#############################################################################################################################
##################################### List Item #########################################################
#############################################################################################################################
ListItem = lambda x,y=xbmcaddon.Addon().getAddonInfo('icon'): xbmcgui.ListItem(x,thumbnailImage=y)
#===========================================================================================================================#
## Description ### Allows The User To Select A Value From A List ##
#===========================================================================================================================#
## Usage ### Select("Select Quality",['1080p','720p','480p','360']) ##
#===========================================================================================================================#
## Result ### Returns Whatever The User Selects ##
#===========================================================================================================================#
#############################################################################################################################
##################################### Web Request #############################################################
#############################################################################################################################
# Returns The Text From A Url #
#___________________________________________________________________________________________________________________________#
Get = lambda x:requests.get(x).text #
GetLines = lambda x:requests.get(x, stream=True).iter_lines() #
Post = lambda x,y: requests.post(x, data = y).text #
PostLines = lambda x,y: requests.post(x, data = y,stream=True).iter_lines() #
#===========================================================================================================================#
# Usage # Result #
#===========================================================================================================================#
# Get('http://website.com') # Returns The text In Full #
# GetLines('http://website.com') # Grabs Every Line Seperately And Returns It Into A List #
# Post('http://website.com',{'user':'user'}) # Returns The text In Full #
# PostLines('http://website.com',{'user':'user'})# Grabs Every Line Seperately And Returns It Into A List #
#===========================================================================================================================#
#############################################################################################################################
##################################### Web Browser #############################################################
#############################################################################################################################
# Opens Default Web Browser To Specified Page #
#___________________________________________________________________________________________________________________________#
Browser = lambda x: webbrowser.open(x) #
#===========================================================================================================================#
# Usage # Result #
#===========================================================================================================================#
# Get('http://website.com') # Returns The text In Full #
# GetLines('http://website.com') # Grabs Every Line Seperately And Returns It Into A List #
# Post('http://website.com',{'user':'user'}) # Returns The text In Full #
# PostLines('http://website.com',{'user':'user'})# Grabs Every Line Seperately And Returns It Into A List #
#===========================================================================================================================#
#############################################################################################################################
##################################### Download (With Progress) #############################################################
#############################################################################################################################
# Found This In The Aftermath Wizard But Most Of It Is Actually Pretty Popular Outside Of Kodi #
# Downloads A Url With Progress Bar #
#___________________________________________________________________________________________________________________________#
def DL(url, dest=TranslatePath(xbmcaddon.Addon().getAddonInfo('profile')), dp = None):
if not dp:
dp = xbmcgui.DialogProgress()
dp.create(addon('id'),"Downloading Content",' ', ' ')
dp.update(0)
start_time=time.time()
urllib.urlretrieve(url, dest, lambda nb, bs, fs: _pbhook(nb, bs, fs, dp, start_time))
def _pbhook(numblocks, blocksize, filesize, dp, start_time):
try:
percent = min(numblocks * blocksize * 100 / filesize, 100)
currently_downloaded = float(numblocks) * blocksize / (1024 * 1024)
kbps_speed = numblocks * blocksize / (time.time() - start_time)
if kbps_speed > 0 and not percent == 100:
eta = (filesize - numblocks * blocksize) / kbps_speed
else:
eta = 0
kbps_speed = kbps_speed / 1024
type_speed = 'KB'
if kbps_speed >= 1024:
kbps_speed = kbps_speed / 1024
type_speed = 'MB'
total = float(filesize) / (1024 * 1024)
mbs = '[COLOR red]Size: [COLOR green]%.02f[/COLOR] MB of [COLOR green]%.02f[/COLOR] MB[/COLOR]'%(currently_downloaded, total)
e = '[COLOR red]Speed: [COLOR green]%.02f [/COLOR]%s/s ' % (kbps_speed, type_speed)
e += 'ETA: [COLOR green]%02d:%02d[/COLOR][/COLOR]' % divmod(eta, 60)
dp.update(percent, '', mbs, e)
except Exception, e:
return str(e)
if dp.iscanceled():
dp.close()
sys.exit()
#===========================================================================================================================#
# Usage # Result #
#===========================================================================================================================#
# Link = 'http://website.com/myfile.zip' # #
# DL(Link) # Downloads To Addon Data #
# DL(Link,'c://folder/file.zip') # Downloads to Specified Folder & Filename #
#===========================================================================================================================#
[i]