Help with my First Add on
#1
Hi, im trying to build my First Add on, and editing the add on that already installed in my kodi
html code can be found in the next post, im trying to replace it with the new target source

Code:
def INDEX(url):
        link = GetContent(url)
        try:
            link=link.encode("UTF-8")
        except:pass
        link = ''.join(link.splitlines()).replace('\t','')
        soup = BeautifulSoup(link)
        vidcontent=soup.findAll('div', {"id" : "archive-posts"})
        
        if(len(vidcontent)==0):
            vidcontent=soup.findAll('div', {"id" : "content"})
        viditems=vidcontent[0].findAll('div', {"class" : "entry-thumbnails"})
        if(len(viditems)>0):
            for item in viditems:
                vimg=""
                if(len(item('a'))>0):
                    linkobj=item('a')[0]
                    if(linkobj.img!=None):
                        vimg=linkobj.img["src"]
                        vname=linkobj.img["title"]
                    vurl=linkobj["href"]
                    try:
                        vname=vname.encode("utf-8","ignore")
                    except: pass
                    addDir(vname.replace("–","-").replace("’","'"),vurl,4,vimg.replace("http://","//").replace("//","http://"))
        else:
            for item in vidcontent[0].findAll('li'):
                vimg=""
                linkobj=item('a')[0]
                vname=linkobj.contents[0].encode("utf-8","ignore")
                vurl=linkobj["href"]
                try:
                    vname=vname.encode("utf-8","ignore")
                except: pass
                addDir(vname.replace("–","-").replace("’","'"),vurl,4,vimg.replace("http://","//").replace("//","http://"))
Reply
#2
What's the question?

Sent from my SM-G935T
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#3
Code:
Here's the target source of the add on
SOURCE

<li class="clearfix post-119838 post type-post status-publish format-standard
has-post-thumbnail hentry category-encantadia tag-encantadia">
    <div class="entry-thumbnails">
    <a class="entry-thumbnails-link" href="source link">
      <img src="JPG source"
              alt="April 11 2017 DESCRIPTION" title="Title and Date">
             <span class="entry-meta">
                <span class="entry-comments">0</span>
                    <abbr class="published" title="2017-04-11T20:34:16+00:00">April 11, 2017</abbr>
            </span>
    </a>
    </div>
    <h3 class="entry-title">
    <a href="Link Source" rel="bookmark">Title April 11 2017
    </a>
    </h3>    
</li>

NEW TARGET SOURCE
TARGET
NOTE : div ID =summary...numbers are changing
<div class="post-body entry-content">
    <div id="summary3058643188314806359">
        <div>
            <a href="Link Source">
                <img src="jpg source"
                    width="192px" height="120px">
            </a>
        </div>
    </div>
    <script type="text/javascript">
        createSummaryAndThumb("summary3058643188314806359","Link.html");
    </script>
    <h2 class="post-title entry-title">
        <a href="Link.html">Title</a>
    </h2>
Reply
#4
(2017-04-11, 18:34)Lunatixz Wrote: What's the question?

Sent from my SM-G935T (typie typie)

Lunatixz , Im trying to replace it with new source,
Reply
#5
(2017-04-11, 18:39)pinoytracker Wrote:
(2017-04-11, 18:34)Lunatixz Wrote: What's the question?

Sent from my SM-G935T (typie typie)

Lunatixz , Im trying to replace it with new source,

You can't just point an add-on at a different source. Different pages are constructed differently. You probably need to read up on scraping web pages with python.
Kodi Matrix on Dell Optiplex 980 Lubuntu 22.04 | Kodi Matrix on HTPC Lubuntu 20.04 | My Add-ons | Legacy Repo | Matrix Repo
>>>>> Newest MetalChris Addons: Local Now | Redbox | NEWSnet| NHL Radio | Weather Unlocked
Reply
#6
Thanks Lunatixz,

I've already found the source, and having difficulty with the target source because one of the ex. ID=summary +random number
so im having difficulty on how to make a loop with that ID
Reply
#7
try regex
Code:
import re

def FindFirstPattern(text,pattern):
    result = ""
    try:    
        matches = re.findall(pattern,text, flags=re.DOTALL)
        result = matches[0]
    except:
        result = ""

    return result
    
def regex_get_all(text, start_with, end_with):
    start_with = re.escape(start_with)
    end_with = re.escape(end_with)
    r = re.findall("(?i)(" + start_with + "[\S\s]+?" + end_with + ")", text)
    return r                

def regex_from_to(text, from_string, to_string, excluding=True):
    from_string = re.escape(from_string)
    to_string = re.escape(to_string)
    
    if excluding:
       try: r = re.search("(?i)" + from_string + "([\S\s]+?)" + to_string, text).group(1)
       except: r = ''
    else:
       try: r = re.search("(?i)(" + from_string + "[\S\s]+?" + to_string + ")", text).group(1)
       except: r = ''
    return r
Reply
#8
trying a new simple regex, but is not simple as i thought, i cant display the Directory list
Code:
OPEN = Open_Url(url)
    Regex = re.compile('<a class="thumbx" href="(.+?)" title="(.+?)">.+?<img alt=".+?class="post-thumbnail" src="(.+?)">.+?
         </a>',re.DOTALL).findall(OPEN)    
    for url,name,icon, in Regex:
    addDir('[B][COLOR white]%s[/COLOR][/B]' %name,url,'',icon,FANART,'')

here is the html code im trying to display
Code:
<article class="post hentry grid" id="5927553623363793230">
  <a class="thumbx" href="http://www.kapuso.me/2017/04/idol-sa-kusina-april-12-2017.html" title="Idol sa Kusina – April 12, 2017"><img alt="Idol sa
      Kusina – April 12, 2017" class="post-thumbnail" src="https://2.bp.blogspot.com/-
      rxukPaBX7eQ/WHUdsMaKuQI/AAAAAAAAA38/xiZcgAvVMZw7BuePd2DFwLmY0Pam5sWwgCLcB/s200-c/isk.jpg" width="200"></a>
<h2 class="post-title entry-title">
  <a href="http://www.kapuso.me/2017/04/idol-sa-kusina-april-12-2017.html" title="Idol sa Kusina – April 12, 2017">Idol sa Kusina – April 12, 2017</a>
</h2>
Reply
#9
Try to use the beautifulsoup4 script:

In the file 'addon.xml', example:
Code:
<requires>
    <import addon="xbmc.python" version="2.1.0"/>
    <import addon="script.module.urlresolver" version="2.10.0"/>
    <import addon="script.module.beautifulsoup4" version="4.3.1"/>
    <import addon="script.module.html5lib" />
    <import addon="script.module.requests" />
  </requires>

In the file 'addon.py', simple example:
Code:
#!/usr/bin/env python
# -*- coding: cp1252 -*-
import urllib, urllib2, re, HTMLParser, os
import html5lib
from bs4 import BeautifulSoup

G_header = 'Addon Name'

def list_movies(url):
    content = []
    try:
        soup = BeautifulSoup(open_url(url))
        content = BeautifulSoup(soup.find('div', { 'class' : 'blog-posts hfeed' }).prettify())
    except:
        msg('An error occurred in the html code!')
        pass
    
    exists_result = len(content)
    if exists_result == 1 :
        
        films = content('a', { 'class' : 'thumbx' })

        numFilms =  len(films)
        i = 0
        while i < numFilms :
            myName = films[i]['title'].strip().encode('utf-8')
            myUrl = films[i]['href'].strip().encode('utf-8')
            myImg = films[i].img['src'].strip().encode('utf-8')
          
            try:
                addDir(myName, myUrl, 13, myImg)
            except:
                msg('Error adding movie: ' + myName)
            
            i += 1
    
        
def open_url(url):
    link = ''
    req = urllib2.Request(url)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36')
    try:
        response = urllib2.urlopen(req)
        link = response.read().decode('utf-8' , 'ignore')
        response.close()
    except urllib2.URLError, e:
        if hasattr(e, 'code'):
            msg('HTTP error : ' + str(e.code))
        elif hasattr(e, 'reason'):
            msg(str(e.reason))
    return link


def msg(Notice):
    dialog = xbmcgui.Dialog()
    ok = dialog.ok(G_header, Notice)

def addDir(..........bla, bla, bla
...............
................

######################################################################################
url = 'http://www.kapuso.me/search/label/GMA?&max-results=24'
list_movies(url)

----------------
In the code above the result of the variable 'myUrl' will be:
Code:
http://www.kapuso.me/2017/04/son-of-god-tagalog-dubbed.html
http://www.kapuso.me/2017/04/idol-sa-kusina-april-12-2017.html
http://www.kapuso.me/2017/04/tunay-na-buhay-april-12-2017.html
http://www.kapuso.me/2017/04/saksi-april-12-2017.html
http://www.kapuso.me/2017/04/scarlet-heart-april-12-2017.html
http://www.kapuso.me/2017/04/meant-to-be-april-12-2017.html
http://www.kapuso.me/2017/04/destined-to-be-yours-april-12-2017.html
http://www.kapuso.me/2017/04/encantadia-april-12-2017.html
http://www.kapuso.me/2017/04/24-oras-april-12-2017.html
http://www.kapuso.me/2017/04/wowowin-april-12-2017.html
http://www.kapuso.me/2017/04/pinulot-ka-lang-sa-lupa-finale-april-12.html
http://www.kapuso.me/2017/04/gma-news-tv-live-april-12-2017.html
http://www.kapuso.me/2017/04/legally-blind-april-12-2017.html
http://www.kapuso.me/2017/04/ika-6-na-utos-april-12-2017.html
http://www.kapuso.me/2017/04/kaibigan-eat-bulagas-lenten-special.html
http://www.kapuso.me/2017/04/mansyon-eat-bulagas-lenten-special.html
http://www.kapuso.me/2017/04/trops-april-12-2017.html
http://www.kapuso.me/2017/04/good-news-april-11-2017.html
http://www.kapuso.me/2017/04/alisto-april-11-2017.html
http://www.kapuso.me/2017/04/saksi-april-11-2017.html
http://www.kapuso.me/2017/04/scarlet-heart-april-11-2017.html
http://www.kapuso.me/2017/04/meant-to-be-april-11-2017.html
http://www.kapuso.me/2017/04/destined-to-be-yours-april-11-2017.html
http://www.kapuso.me/2017/04/encantadia-april-11-2017.html

I think this is what you need
Reply
#10
I'll leave the code I use to create my addons from a third-party website, it might be useful for you.

site base: http://www.filmeseseriesonline.net

My addon:
http://www.mediafire.com/file/1jd8yr5bld...ne.net.zip

urlresolver:
http://www.mediafire.com/file/2578iqw0zb...solver.zip
Reply
#11
Thanks anttrax, I'll will take a look at it now
Reply
#12
Hi anntrax, tried your addin but getting a blank screen
Reply
#13
I use Kodi 16, on kodi 17 I did not test.
Reply
#14
btw, thanks i manage to display now all the names and thumbnails Big Grin, trying to display now the next page Big Grin
Reply
#15
The reasoning is the same, just understand the nodes of html

Code:
def list_movies(url):
     content = []
     try:
         soup = BeautifulSoup(open_url(url))

        ## BeautifulSoup to main content
        content = BeautifulSoup(soup.find('div', { 'class' : 'blog-posts hfeed' }).prettify())

        ## BeautifulSoup to next page
        content2 = BeautifulSoup(soup.find('span', { 'id' : 'blog-pager-older-link' }).prettify())

     except:
         msg('An error occurred in the html code!')
         pass
    
     exists_result = len(content)
     if exists_result == 1 :
        
         films = content('a', { 'class' : 'thumbx' })

         numFilms =  len(films)
         i = 0
         while i < numFilms :
             myName = films[i]['title'].strip().encode('utf-8')
             myUrl = films[i]['href'].strip().encode('utf-8')
             myImg = films[i].img['src'].strip().encode('utf-8')
            
             try:
                 addDir(myName, myUrl, 13, myImg)
             except:
                 msg('Error adding movie: ' + myName)
              
             i += 1

        ## code to next page
        try:
            next_page = content2('a')

            if len(next_page) == 1:
                link_pg = next_page[0]['href'].strip().encode('utf-8')
                
                addDir('Next Page >>' , link_pg, 12, 'next.png')

        except:
            pass


Code:
if mode == None or url == None or len(url) < 1 :
    #mainMenu()
    pass
    
elif mode == 12 :
    list_movies(url)

elif mode == 13 :
    #open_video(url)
    pass
Reply

Logout Mark Read Team Forum Stats Members Help
Help with my First Add on0