PK pžGù¥’XK K ! plugin.video.firstaddon/addon.xml
video
ADDON
en
all
PK \r!G’¤ô×â â " plugin.video.firstaddon/default.pyimport urllib,urllib2,sys,re,xbmcplugin,xbmcgui,xbmcaddon,datetime,os
ADDON = xbmcaddon.Addon(id='plugin.video.firstaddon')
AddonID = 'plugin.video.firstaddon'
Addon = xbmcaddon.Addon(AddonID)
addonDir = Addon.getAddonInfo('path').decode("utf-8")
# SHOWING A VALUE THAT IS IN THE SETTINGS
def SHOWNAME(url):
# Get The Settings V ------- V--------- With The ID myname So What Ever Is Entered In That Is Stored In The settings
# To Have The Below Value Available To All Defined Values just copy the code line bellow and put it to line 6 and remove the blank spaces
myname = ADDON.getSetting(id='myname')
# ^---- name Of Action It Can Be Anything
# Now The Below Code Can Be Written In Two Ways Like
# 1) showText(myname,'YOUR MESSAGE HERE') OR This is if you want to display the value of username in header and nothing else
# 2) showText('%s'%(myname),'YOUR MESSAGE HERE') This is so you can enter a value ether side of %s the value %s Will Be Replaced With
# The Value myname By Default Its No Name
showText('%s'%(myname),'YOUR MESSAGE HERE')
# Same Can Be Applied Below If You Want To Add WELCOME The The Users Name Were You See The Text 'NAME' change it to 'WELCOME %s'%(myname)
def CATEGORIES():
myname = ADDON.getSetting(id='myname')
addDir2('NAME','url',4,'icon')
addDir2('CHANGE NAME','url',5,'icon')
#################################################################################################################################
#################################################################################################################################
#################################################################################################################################
def CHANGENAME():
dialog = xbmcgui.Dialog()
# Shoe Dialog V-- The Header V--- The Type Of Input
d = dialog.input('Enter secret code', type=xbmcgui.INPUT_ALPHANUM)
# V -- If The Value Of d is Equal To '' So Empty
if d == '':
# The Return
return True
# But If d Has Anything But Empty Set The Settings myname To Entered value
else:
ADDON.setSetting(id='myname', value=d)
# Set Settings myname --^ ^------- To The Value Entered In d
def showText(heading, text):
id = 10147
xbmc.executebuiltin('ActivateWindow(%d)' % id)
xbmc.sleep(100)
win = xbmcgui.Window(id)
retry = 50
while (retry > 0):
try:
xbmc.sleep(10)
retry -= 1
win.getControl(1).setLabel(heading)
win.getControl(5).setText(text)
xbmcplugin.getSetting(int(sys.argv[1]), 'myname')
return
except:
pass
def OPEN_URL(url):
req = urllib2.Request(url)
req.add_header('User-Agent' , "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36")
response = urllib2.urlopen(req)
link=response.read()
response.close()
return link
#################################################################################################################################
############################## ###################################################################
############################## Read The Page ###################################################################
def REGEX(url):
# V----- This Meens It Will Read The Url In The Link Item That Was Pressed
link = OPEN_URL(url)
# V---- REGEX CODE GOES HERE
match=re.compile(' ').findall(link)
# V---- For Every (.+?) In You REGEX You Must Give It A Name so if you have 2 and its name and url put name,url
for channelid in match:
# V -- if you want the name to appper here you could remove to ' ' and just put name or you could put %s in the middle
# then after the ' put %(name) so sould look like '%s'%(name)
# V ----- this is the mode set it to the def() you wana run see bottom
addDir(' ',' ',1,'','')
#################################################################################################################################
#################################################################################################################################
#################################################################################################################################
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def addDir(name,url,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
def addDir2(name,url,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
return ok
params=get_params()
url=None
name=None
mode=None
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
#################################################################################################################################
############################## ###################################################################
############################## DEFINING YOUR DEF () FUNCTIONS ###################################################################
if mode==None or url==None or len(url)<1:
print ""
CATEGORIES()
# V ----- GIVE YOU MODE A NUMBER
elif mode==1:
# V ---- Then The Name Of A def name() you have made
INDEX(url)
# ^------- and witch bit you want to keep so you want it to remember the name in addDir so put name
elif mode==4:
# V ---- Then The Name Of A def name() you have made
SHOWNAME(url)
# ^------- and witch bit you want to keep so you want it to remember the name in addDir so put name
elif mode==5:
# V ---- Then The Name Of A def name() you have made
CHANGENAME()
# ^------- and witch bit you want to keep so you want it to remember the name in addDir so put name
xbmcplugin.endOfDirectory(int(sys.argv[1]))
#################################################################################################################################
#################################################################################################################################
#################################################################################################################################
PK …‰Gå+ä plugin.video.firstaddon/icon.png‰PNG
IHDR A -
Äø sRGB ®Îé gAMA ±üa pHYs Ä Ä•+ bKGD ÿ ÿ ÿ ½§“ tIMEÜ!
$Ê% tEXtComment Created with GIMPW \IDATx^íÔ1 À°ÏÀ‹&Otg ¢ö/@’ i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&¤™ f‚@š i&„Í\^¯ü=)¹® IEND®B`‚PK ŠG%–D=d d # plugin.video.firstaddon/LICENSE.txtThis 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 3 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 .
PK ܑ!G茟Ns" s" ! plugin.video.firstaddon/readme.mdOK LETS READ A PAGE
So you get used to it we will start small, so pick your page you want to read. im going to pick the kodi fourms.
http://forum.kodi.tv/forumdisplay.php?fid=26
Once on the page right click and view source now this may look hard but this is the code of the website HTML normaly.
click ctrl F and type in the text you are trying to find mine is your first add-on it should now hight light the txt
now the left and right there will be code you want to select the whole line now copy it
Your First Add-On: Hello World!
now regex has special code to indicate that this is the text you want and to ignore the rest the code is
EXAMPLES OF REGEX CODE
Read This ---> (.+?)
Ignore This ---> .+?
read this numbers ---> (\d\d) the \d stands for number so for each \d is one number so (\d\d) would read 2 numbers
a new line ----> \n
before this ---> \b
so look at the code you have copyed
Your First Add-On: Hello World!
Now you need to grab the txt that will change but still match what you are trying to grab so
Your First Add-On: Hello World!
^^^^^^ ^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
where you see ^ is text that will change on each post so we will start with the name of the post
"Your First Add-On Hello World"
now like in the regex examples we want to read this so what we do is remove the text "Your First Add-On Hello World"
and put (.+?) the tell regex that we want this code now you code should look like
(.+?)
now the code will fetch the name but as you will see this will only fetch one item becouse
showthread.php?tid=209948 tid_209948 subject_new
these 3 items can change on each post so to do this i want to add
.+?
this tell regex to ignore this text so lets change it
FROM (.+?)
TO (.+?)
Now the reason why i have kept the text showthread.php?tid= is becouse i dont want it to read every link just the posts
Now you see where it says PUT REGEX CODE you want to copy
(.+?)
and paste it in there now we need to tell kodi that we have one item and that we want it to be the name so to do this
look bellow see where it says GIVE IT A NAME change the text channelid to name all this is a defining the read text nw that we have given it a name we also need to say add a director each time you read the name so bellow that you should see
addDir('','',10,'')
let me break it down for you
addDir('1','2',3,'4')
1. THE NAME
2. THE URL
3. THE MODE
4. THE ICON
So with kodi you want to remember this bit of code
%s
This meens put it here basically but how does kodi know what to put there this is dont by adding
%(name)
^--- Put The name Of The Fuction Defined Earlier here
So now it meens put the text
(.+?)
^------- FROM HERE
AND
addDir('','',10,'')
PUT IT HERE ----^
but make sure that the %(name)is after the comma so it should look like
addDir('%s'%(name),'',10,'')
the %s will now put the name there now you can experiment just say you want som text befor the name you can do
addDir('ANY TXT HERE %s OR HERE'%(name),'',,'')
now if you plan on having nothing either side you can do this
addDir(name,'',10,'')
all i have done is removed the '' and put name this tells kodi like the other examples to put the name here now there are
other cool exanples you can use to play with the text these are
CHANGE THE COLOR ----> [COLOR yellow]TXT HERE[/COLOR] SO IN YOUR CODE ----> addDir('[COLOR yellow]%s[/COLOR]'%(name),'',10,'')
BOLD TEXT -----> [B]TXT HERE[/B] SO IN YOUR CODE ----> addDir('[B]%s[/B]'%(name),'',10,'')
Now the code should look like
def REGEX(url):
link = OPEN_URL(url)
match=re.compile('(.+?)').findall(link)
for name in match:
addDir('%s'%(name),'',10,'')
if you want to read 2 items from the code lets say you want to know if its a new or old item so if you go back to the first time you copyed the code you will see that after class=" it says subject_new or will be subject_old to do this just change
class=".+?"
to
class="(.+?)"
just put brackets around .+?
now like befor we give it a name il give this newold now look at where its position is in your regxex the first (.+?) is or new old so we want to change
for name in match:
TO
for newold,name in match:
this tells kodi that the first (.+?) is the newold and the second (.+?) Is The name now we want it to show up in the name of or addDir so change
addDir('%s'%(name),'',10,'')
TO
addDir('%s %s'%(newold,name),'',10,'')
let me break it down for you
addDir('%s %s'%(newold,name),'',10,'')
^ | ^ ^
| |_____|_____|
| |
>------->^
Now The Complete Code Should Look Like
def REGEX(url):
link = OPEN_URL(url)
match=re.compile('(.+?)').findall(link)
for newold,name in match:
addDir('%s %s'%(newold,name),'',10,'')
########################################################### UPDATE ###########################################################################
########################################################### UPDATE ###########################################################################
Now To Scrape Two Items You must add another
match=re.compile('(.+?)').findall(link)
under the first one and change match for match2
also you need to add a second
V---------- CHANGED TO match2
for newold,name in match2:
addDir('%s %s'%(newold,name),'',10,'')
and insert this bellow your
addDir('%s %s'%(newold,name),'',10,'')
and inline with
for newold,name in match:
so the complete code is
def REGEX(url):
link = OPEN_URL(url)
match=re.compile('(.+?)').findall(link)
match2=re.compile('(.+?)').findall(link)
for newold,name in match:
addDir('%s %s'%(newold,name),'',10,'')
for newold,name in match2:
addDir('%s %s'%(newold,name),'',10,'')
to add just a directorty handy is you want to add a search button just add
addDir('name','url',10,'icon')
at the top like
def REGEX(url):
addDir('name','url',10,'icon')
link = OPEN_URL(url)
match=re.compile('(.+?)').findall(link)
match2=re.compile('(.+?)').findall(link)
for newold,name in match:
addDir('%s %s'%(newold,name),'',10,'')
for newold,name in match2:
addDir('%s %s'%(newold,name),'',10,'')
########################################################### UPDATE ###########################################################################
########################################################### UPDATE ###########################################################################
Common errors can be a result of spaces or indentations python requires 4 spaces between lines here is an example
def REGEX(url):
<--8--->link = OPEN_URL(url)
<--8--->match=re.compile('(.+?)').findall(link)
<--8--->for newold,name in match:
<--12------>addDir('%s %s'%(newold,name),'',10,'')
the next error can be due having 2 (.+?) and not giving the names in
for newold,name in match:
the next error is having the names
for newold,name in match:
and not putting them in your addDir('','',10,'')
PK ¬‚G Ÿæ@ @ . plugin.video.firstaddon/resources/settings.xml
PK pžGù¥’XK K ! ¶ plugin.video.firstaddon/addon.xmlPK \r!G’¤ô×â â " ¶Š plugin.video.firstaddon/default.pyPK …‰Gå+ä ¶¬# plugin.video.firstaddon/icon.pngPK ŠG%–D=d d # ¶û' plugin.video.firstaddon/LICENSE.txtPK Ü‘!G茟Ns" s" ! ¶ * plugin.video.firstaddon/readme.mdPK ¬‚G Ÿæ@ @ . ¶RM plugin.video.firstaddon/resources/settings.xmlPK é ÞR