Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: http request help

  1. #1
    Join Date
    Mar 2005
    Posts
    724

    Default http request help

    ok i found a old post that was basically part of what I am trying to do but i am getting no reaction to the code on girder or XBMC

    require ('socket.http')

    function VolumeUp()

    PostAddress = "http://192.168.1.4:8800/xbmcCmds/xbmcHttp?command=setvolume&parameter="

    Body = socket.http.request("http://192.168.1.4:8800/xbmcCmds/xbmcHttp?command=getvolume")

    CurrentVolume = string.sub(Body, string.find(Body, '%d%d'))

    NewVolume = CurrentVolume - 50

    SendUrl = PostAddress .. NewVolume

    socket.http.request(SendUrl)

    end

    Thanks

  2. #2
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,125

    Default

    First a couple of questions.

    1. Is that code in a scripting action? If so, could you copy/paste the exact code?
    2. If that is the exact code, you have defined the function VolumeUP but have not called it. You need to do something like this.
    Code:
    function VolumeUp()
        print ('VolumeUp')
    end
    
    VolumeUp()
    Rick

    Girder 6.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote - BlueIris DVR
    Girder 6 Plugins - Elk M1/EZ8, Pushover Connector and more on the way.


    Visit My Showcase

  3. #3
    Join Date
    Mar 2005
    Posts
    724

    Default

    thanks for the help i had forgot to call the function

    I have one other issue if you can help me with it I am now working on a way to read the contents farther down a page below is the layout of the page and the order is static that will be the same always
    Code:
    <html>
    <li>Filename:C:\Users\Reg\Videos\Batgirl.mpg
    <li>PlayStatus:Playing
    <li>VideoNo:-1
    <li>Type:Video
    <li>Title:Batgirl
    <li>Genre:short
    <li>Plotoutline:At the Gotham City library, Barbara Gordon helps Bruce Wayne find a book on butterflies so he can prove a point to a friend, a millionaire explorer. As Bruce and his youthful ward, Dick Grayson, are leaving they spot the villainous Killer Moth and three of his henchmen and, suspecting they are up to no good, determine to return as their superhero alter-egos, Batman and Robin. While the Caped Crusaders are donning their costumes, the criminal quartet knock out the millionaire, lock Barbara in an alcove and prepare to spirit their victim away. When the Dynamic Duo attempt to capture the crooks, they are encased in Killer Moth's silk cocoon. Is this the end of our Gotham City heroes? And why does a beautiful librarian have a cowl and a cape hanging in a convenient closet?
    <li>Plot:At the Gotham City library, Barbara Gordon helps Bruce Wayne find a book on butterflies so he can prove a point to a friend, a millionaire explorer. As Bruce and his youthful ward, Dick Grayson, are leaving they spot the villainous Killer Moth and three of his henchmen and, suspecting they are up to no good, determine to return as their superhero alter-egos, Batman and Robin. While the Caped Crusaders are donning their costumes, the criminal quartet knock out the millionaire, lock Barbara in an alcove and prepare to spirit their victim away. When the Dynamic Duo attempt to capture the crooks, they are encased in Killer Moth's silk cocoon. Is this the end of our Gotham City heroes? And why does a beautiful librarian have a cowl and a cape hanging in a convenient closet?
    <li>Rating:7.0 ( votes)
    <li>Year:1967
    <li>Thumb:special://masterprofile/profiles/yonu/Thumbnails/Video/3/auto-3fb6b47b.tbn
    <li>Time:00:31
    <li>Duration:07:25
    <li>Percentage:7
    <li>File size:154631988
    <li>Changed:False</html>
    I am at a loss of how to pull say the line for Duration I would assume I would use the string.find but the syntax has me lost

    Thanks,
    Yonu

  4. #4
    Join Date
    Jul 2005
    Location
    Uithuizen, The Netherlands
    Posts
    576

    Default

    try patern matching like this:

    Code:
    source = [["<html> 
    <li>Filename:C:\Users\Reg\Videos\Batgirl.mpg <li>PlayStatus:Playing
    <li>VideoNo:-1
    <li>Type:Video
    <li>Title:Batgirl
    <li>Genre:short
    <li>Plotoutline:At the Gotham City library, Barbara Gordon helps Bruce Wayne find a book on butterflies so he can prove a point to a friend, a millionaire explorer. As Bruce and his youthful ward, Dick Grayson, are leaving they spot the villainous Killer Moth and three of his henchmen and, suspecting they are up to no good, determine to return as their superhero alter-egos, Batman and Robin. While the Caped Crusaders are donning their costumes, the criminal quartet knock out the millionaire, lock Barbara in an alcove and prepare to spirit their victim away. When the Dynamic Duo attempt to capture the crooks, they are encased in Killer Moth's silk cocoon. Is this the end of our Gotham City heroes? And why does a beautiful librarian have a cowl and a cape hanging in a convenient closet?
    <li>Plot:At the Gotham City library, Barbara Gordon helps Bruce Wayne find a book on butterflies so he can prove a point to a friend, a millionaire explorer. As Bruce and his youthful ward, Dick Grayson, are leaving they spot the villainous Killer Moth and three of his henchmen and, suspecting they are up to no good, determine to return as their superhero alter-egos, Batman and Robin. While the Caped Crusaders are donning their costumes, the criminal quartet knock out the millionaire, lock Barbara in an alcove and prepare to spirit their victim away. When the Dynamic Duo attempt to capture the crooks, they are encased in Killer Moth's silk cocoon. Is this the end of our Gotham City heroes? And why does a beautiful librarian have a cowl and a cape hanging in a convenient closet?
    <li>Rating:7.0 ( votes)
    <li>Year:1967
    <li>Thumb:special://masterprofile/profiles/yonu/Thumbnails/Video/3/auto-3fb6b47b.tbn
    <li>Time:00:31
    <li>Duration:07:25
    <li>Percentage:7
    <li>File size:154631988
    <li>Changed:False</html>
    "]]
    
    _, _, time, percentage = string.find(source, "Time:(.-)\n.-Percentage:(.-)\n")
    print(time)
    print(percentage)
    
    _, _, rating = string.find(source, "Rating:(.-)%s")
    print(rating)
    Last edited by blubberhoofd; October 6th, 2010 at 09:03 AM.

  5. #5
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok thank you very much for the code but I have to ask how do I use it i under stand that this section is the part that does the searching but how do i use it
    Code:
    _, _, time, percentage = string.find(source, "Time:(.-)\n.-Percentage:(.-)\n")
    print(time)
    print(percentage)
    I am sorry for the stupid question but I am new to lua

  6. #6
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok I got the code sorted out but for instance the result I get for time and percentage is 1851 and 1898 could it be something I screwed up when i added the code?

    Thanks,
    Reg

  7. #7
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok I tried doing title and it gives me a result of 109 any idea would be great here is the code I have so far source is the same I posted before
    Code:
    require ('socket.http')
    
    function Title()
    
    --PostAddress = "http://192.168.1.141:8800/xbmcCmds/xbmcHttp?command=setvolume&parameter="
    
    Body = socket.http.request("http://192.168.1.141:8800/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying")
    print(Body)
    --CurrentTitle = string.sub(Body, string.find(Body, "title"))
    print(CurrentTitle)
    --NewVolume = CurrentVolume + 50
    --print (NewVolume)
    --SendUrl = PostAddress .. NewVolume
    --print (SendUrl)
    --socket.http.request(SendUrl)
    time, percentage = string.find(Body, "Time:(.-)\n.-Percentage:(.-)\n")
    print(time)
    print(percentage)
    Title = string.find(Body, "Title:(.-)\n.")
    print(Title)
    end
    
    Title()

  8. #8
    Join Date
    Jul 2005
    Location
    Uithuizen, The Netherlands
    Posts
    576

    Default

    try:
    Code:
    require ('socket.http')
    
    Body = socket.http.request("http://192.168.1.141:8800/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying")
    print(Body)
    
    if Body ~= nil then
    _, _, time, percentage = string.find(Body, "Time:(.-)\n.-Percentage:(.-)\n")
    print(time)
    print(percentage)
    _, _, Title = string.find(Body, "Title:(.-)\n.")
    print(Title)
    end
    Last edited by blubberhoofd; October 7th, 2010 at 03:08 AM.

  9. #9
    Join Date
    Mar 2005
    Posts
    724

    Default

    thanks I think I am getting the hang of this now one simple question

    If I use this piece of code
    Code:
    _, _, showTitle = string.find(Body, "Show%sTitle:(.-)\n.")
    print(showTitle)
    with this source should it extract the show title field? the reason I ask is it gives me the same result for title and showtitle fields
    Code:
    <html>
    <li>Filename:smb:\\192.168.1.4\cartoons\Naruto Shippuuden\[DB]_Naruto_Shippuuden_004_[394C745F].avi
    <li>PlayStatus:Paused
    <li>VideoNo:-1
    <li>Type:Video
    <li>Show Title:Naruto: Shipp├╗den
    <li>Title:Naruto Shipp┼źden 4: The Lost Tower
    <li>Season:0
    <li>Thumb:special://masterprofile/profiles/yonu/Thumbnails/Video/0/0807425b.tbn
    <li>Time:00:03
    <li>Duration:23:04
    <li>Percentage:0
    <li>File size:152143164
    <li>Changed:False</html>
    Thanks,
    Reg

  10. #10
    Join Date
    Jul 2005
    Location
    Uithuizen, The Netherlands
    Posts
    576

    Default

    use this:
    Code:
    _, _, showTitle = string.find(Body, "Show%sTitle:(.-)\n") 
    print(showTitle)
    
    _, _, Title = string.find(Body, ">Title:(.-)\n") 
    print(Title)
    Last edited by blubberhoofd; October 8th, 2010 at 03:02 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •