Req regex help for my addon
#1
hi
im working on a addon.
i need a help on regex.

below is the source code:
<a href="/watch?v=6LDHceJ5hFQ&amp;list=PLJRM1-EkjJa6ZWkwOa3WcncGzpHeB4cpO&amp;index=2" title="Ashwini Nakshatra - 19th August 2013 - Full Episode" class="ux-thumb-wrap yt-uix-sessionlink"

i want to extract watch?v=(.+?)&amp;list and title="(.+?) - Full Episode" class
how can i extract the data after (v=) and after (title=")

i tried my best but cant get the results.
pls guide
Reply
#2
Code:
def extract(text, startText, endText):
    start = text.find(startText, 0)
    if start != -1:
        start = start + startText.__len__()
        end = text.find(endText, start + 1)
        if end != -1:
            return text[start:end]
    return None

Try that

Use the requests library to put the page into a string first

Sorry i will explain more now that im not on my phone.

1. get Requests (http://docs.python-requests.org/en/lates...l/#install)

2. Read this (http://forum.xbmc.org/showthread.php?tid=171730)

3. Code

I put this in a file named util.py
Code:
def extract(text, startText, endText):
    start = text.find(startText, 0)
    if start != -1:
        start = start + startText.__len__()
        end = text.find(endText, start + 1)
        if end != -1:
            return text[start:end]
    return None

and put this in a default.py
Code:
import requests

varShowInfo = requests.get("http://www.google.com")
varShowInfo.text
  
varEpisodeURL = util.extract(varShowInfo.text, "watch?v=", "&amp;list")

print(varEpisodeURL)

change google.com to the url the info is on

change the variable names to whatever you like.
Reply
#3
sorry giving error -
19:26:46 T:3976 NOTICE: -->Python Interpreter Initialized<--
19:26:46 T:3976 ERROR: Error Type: <type 'exceptions.ImportError'>
19:26:46 T:3976 ERROR: Error Contents: No module named requests

can we do this with regex?
Reply
#4
If there is no module named requests you skipped step 1.. im sorry I dont use regex so I dont know it.. if you need help getting requests let me know
Reply
#5
i am on windows so i skipped step1.
instead i took the tips from step2 and added request in addon.xml as mentioned in the last but one post of step2.
Reply
#6
Code:
<requires>
    <import addon="script.module.requests" version="1.1.0"/>
</requires>

that only works if your addon is in the official repo..

mine is not so I had to use this

Code:
import sys, os
import xbmc, xbmcaddon

__addon__       = xbmcaddon.Addon('script.tv.promos')

__cwd__ = xbmc.translatePath(__addon__.getAddonInfo('path')).decode("utf-8")
BASE_RESOURCE_PATH = os.path.join(__cwd__, 'resources', 'lib')
sys.path.append(BASE_RESOURCE_PATH)

import requests

#Rest of your code goes here

you can use that if you copy the requests folder into the lib directory of your addon, my addon name is 'script.tv.promos' so mine would look like this

script.tv.promos/resources/lib/requests

and if your on windows you can use this link to download the zipball: https://github.com/kennethreitz/requests/zipball/master

after you do that extract the requests folder to your python Lib folder.. in my case that is: C:\Python\33\Lib

if you still need anything just post here or let me know!
Reply
#7
(2013-08-21, 22:12)karrade Wrote:
Code:
<requires>
    <import addon="script.module.requests" version="1.1.0"/>
</requires>

that only works if your addon is in the official repo..

mine is not so I had to use this

you can use that if you copy the requests folder into the lib directory of your addon, my addon name is 'script.tv.promos' so mine would look like this

script.tv.promos/resources/lib/requests

and if your on windows you can use this link to download the zipball: https://github.com/kennethreitz/requests/zipball/master

after you do that extract the requests folder to your python Lib folder.. in my case that is: C:\Python\33\Lib

if you still need anything just post here or let me know!

that is not true!

the requires is processed at install time. so if you want to use the module for developing you must manually download and install it.
http://mirrors.xbmc.org/addons/frodo/scr....requests/

once you create an install zip of your addon for others it will be auto installed for them and will just work
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#8
when I tried to import it, it wouldnt work so I did it the other way
but now I will go back and try again.
I love learning things I didnt know, thank you Martijn!
Reply
#9
Of course requests is a very nice library with nice features and so on.

But i doubt that you use these features. If you just want to retrieve a single webpage's response text you could save you some trouble by using only python stdlib's possibilities:

Code:
import requests
varShowInfo = requests.get("http://www.google.com")
varShowInfo.text
varEpisodeURL = util.extract(varShowInfo.text, "watch?v=", "&amp;list")
print(varEpisodeURL)
Has the same result like:
Code:
from urllib2 import urlopen
html = urlopen("http://www.google.com").read()
varEpisodeURL = util.extract(html, "watch?v=", "&amp;list")
print(varEpisodeURL)
My GitHub. My Add-ons:
Image
Reply
#10
Hi,
Does a freelive.tv and flashstreaming.mobi regex exist?
Reply

Logout Mark Read Team Forum Stats Members Help
regex help for my addon0