Kodi Community Forum

Full Version: Scrape only when item is clicked
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello I'm using parsedom to scrape an m3u8 link and I managed to make it work just fine and I also can make it with urllib2 and beautifulsoup but the issue I'm having is that I believe the scraping happens multiple times as I run my addon, so for example when I open my addon it does the scraping, then also when I enter a category and finally when I click the item so I'm wondering how I can only do the scraping only when I click the item.

I'm using the basic addon example from here: HOW-TO:Video_addon (wiki)

And what I'm doing is something like this:

Code:
someurl= 'https://www.someurl.com/'
someRegex = 'someregex'

result = common.fetchPage({'link': someurl})

if result['status'] == 200:
    regex = re.compile(someRegex).findall(result['content'])

for item in regex:
    myLink= ''.join(map(str, item))]

Then I take myLink and simply put it inside the category item like this:

Code:
{'name': 'ChannelName',
'thumb': 'special://home/addons/plugin.video.myplugin/resources/media/logos/logo.png',
'video': myLink,
'genre': 'Channels'},

So that's the issue, the code gets called multiple times, I have tried converting it into a function and then call it as the 'video' item but it's the same, the function gets called multiple times so I wonder is there's a way to do a simple onClick event or anything else to make it run only when needed.

Edit: Other things I've tried is using "if", so that the page gets scraped only IF the "result" variable is empty but it's the same, looks like it all gets reloaded every time I make a click so it's useless.

Also tried this:

Code:

doOnce = 0
while doOnce == 0:
    result = common.fetchPage({'link': someurl})
    doOnce = 1

I'm thinking that maybe the scraper has to run in a separate module? But it may not make any difference.