Author Topic: Code / Script conversion or port?  (Read 7459 times)

0 Members and 1 Guest are viewing this topic.

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Code / Script conversion or port?
« on: August 29, 2012, 12:50:20 PM »
Someone posted on XBMC forums this script that leveraged free API for XBOX live status.
https://github.com/bstrdsmkr/service.XBLFriends

It apparently was not coded cleanly and making a LOT of extraneous calls to the API...and then  I noticed completely stopped working. Finally looked at logs and manually access url to find I was IP blocked due to automated responses to anti spam. Contacted API owner and provided the following
https://github.com/xboxapi/XboxAPI-Scraper-Lib/blob/master/XboxAPI_Scraper.Lib.php

I don't really know JSON or Python nor PHP, but anybody know how to slap these together cleanly so if I can get unbanned script wont reinduce same bad behavoiur....this was a really handy script for me :P

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Code / Script conversion or port?
« Reply #1 on: August 29, 2012, 01:34:32 PM »
Hi vulcanjedi

It's highly unlikely you will find someone here, to "slap" it together for you. I dont think there are many coders in this forum. Your best bet is the xbmc forum.
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #2 on: August 29, 2012, 04:17:09 PM »
sorry, not interested.  :'(

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #3 on: August 29, 2012, 04:48:11 PM »
OK.  I just had a quick look at the addon code.  If you already have it installed and it was working except for you getting cut off after too many calls I may be able to help.

I think you are only allowed to make a maximum of 150 calls per day.  This script seems to call every 180 seconds, which means you'll use up your quota after it runs for about 3.75 hours.

Looking at the code the main thing I would try changing is the value of 180.  You may have to wait until tomorrow to try it, or you may be able to fix it by getting a new IP address if you can do that (sometimes you can reboot your modem to get a new IP, depends on your ISP etc.)

The other thing which is really stupid, unless I am reading this thing wrong is that it is looping constantly once every second.

I would change the sleep line to 30000 (30 seconds)
and I would change the 180 to 300 (5 minutes).

or course it might make more sense to just increase the sleep to 5 minutes:  xbmc.sleep(300000)

I hope it helps.  Here's the original code (from the file: service.py) with extra stuff removed to make it easier to see what I'm talking about.  Just go into the addons folder, find this file and edit it using notepad or something, then restart XBMC.

...
...
class XBLMonitor:            
   def runProgram(self):
      self.last_run = 0
      seconds = 180
      ...
            now = time.time()
            if now > (self.last_run + seconds):
               gamerTag = ADDON.getSetting('gamertag')
               ......
            xbmc.log('XBLFriends: Monitoring disabled')
            break
         xbmc.sleep(1000)
      xbmc.log('XBLFriends: Notification service ending...')
...
« Last Edit: August 29, 2012, 04:51:45 PM by jitterjames »

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Code / Script conversion or port?
« Reply #4 on: August 29, 2012, 05:15:47 PM »
Thanks for the quick look james, i just figured Id get on and see if any experts were bored enough :) Im going to see at least in interim if I can get unblocked and maybe just go with trying to update enough to run as an ON DEMAND command vs how this 'currently' configured as a 'service'
Going to implement your suggestions as well.

I also think this
Code: [Select]
except:
data = {'Success':False, 'Reason':'Failed to connect to url'}
self.last_run = self.last_run - 120 #In effect, wait 1 minute and try again.
except construct is flawed as it keeps resetting the time increment backwards if the URL is deemed unreached, and I think contributes to all the extra calls
« Last Edit: August 29, 2012, 05:19:22 PM by vulcanjedi »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #5 on: August 29, 2012, 05:22:41 PM »
could be.  If it really does fail to connect then I don't think it should "count" against you,

but you could try removing the line:

self.last_run = self.last_run - 120 #In effect, wait 1 minute and try again.

this way it would just keep pinging away at the normal rate.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #6 on: August 29, 2012, 05:29:55 PM »
by the way it looks like it would be fairly easy to use this api to create a voice command for VoxCommando that would tell you which of your friends were online.  Only useful if you have a limited number of friends online at once, otherwise it would be pretty annoying if using TTS to list them all.

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Code / Script conversion or port?
« Reply #7 on: August 29, 2012, 05:34:27 PM »
I was using the script to do such a thing but if I could bypass it and direct w/ VC that'd be fine w/ me too. Ill explore that approach as well.
Normally I stick to the baked in addon/plugins with XBMC but I really liked this functionality and never used a 'service' before.
I guess would be ultimately nice if the 'service' worked safely w/o VC. But really whats 'critically' desired is just ondemand status and if w/ VC that works for me as I'd be more apt to use that way anyways.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #8 on: August 29, 2012, 05:40:19 PM »
just realized that the api limit is actually 150 calls per hour.  So I'm not too sure why you are being blocked.

If you go to this url does it work?

https://xboxapi.com/index.php/friends/vulcanjedi/

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Code / Script conversion or port?
« Reply #9 on: August 29, 2012, 06:07:51 PM »
just realized that the api limit is actually 150 calls per hour.  So I'm not too sure why you are being blocked.

If you go to this url does it work?

https://xboxapi.com/index.php/friends/vulcanjedi/

No, not from home thats where I found out I was getting IP blocked.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #10 on: August 29, 2012, 06:10:49 PM »
you can try this command.  I think you only have 4 friends and they are all offline at the moment, unless there is another VulcanJedi on xbox live.

To show friends that are offline you can change the regex from

... "IsOnline":true
to
..."IsOnline":false

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Code / Script conversion or port?
« Reply #11 on: August 29, 2012, 06:11:28 PM »
No, not from home thats where I found out I was getting IP blocked.
And it does not reset after an hour?  So you got blacklisted permanently?

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Code / Script conversion or port?
« Reply #12 on: August 29, 2012, 06:15:34 PM »
That I can't affirm, it was blocked all last night. I emailed the support email and received contact, it was an automated block response, but the staff seemed receptive to unblocking me. I just want to make sure it doesnt happen again.

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Code / Script conversion or port?
« Reply #13 on: August 29, 2012, 06:20:45 PM »
And it does not reset after an hour?  So you got blacklisted permanently?
Just accessed home env and still blocked.
my gamertag is different and too cheap to pay to change it! :) Cool I will try the VC xml when I get the opportunity!

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Code / Script conversion or port?
« Reply #14 on: December 04, 2013, 09:37:56 PM »
I tried to to install this script today. it seems to be running, not sure if any friends got on since boot but it worked on boot up but failing to get the ondemand use working like I did in Eden?
RunPlugin(plugin://service.XBLFriends/?mode=ondemand) worked in eden as well as auto spawning my video plugins like youtube...etc

Addons.Executeaddon   "addonid":"service.XBLFriends/?mode=ondemand)
(i used template from youtube addon launch, that works)
I've tried various combinations of it I haven't been successful.
Addons.Executeaddon   "addonid":"service.XBLFriends/"   ?mode=ondemand
...etc
I also opened the service.py and affirmed the addonid is service.XBLFriends even though the parent folders are suffixed w/ '-master'
And although its a 'service' or 'script'
The existing XBMC Subtitles plugin seems labeled/organized the same way but works so I think its this parameterization? Insights?
I liked and actually preferred being able to use on demand and say 'any friends on Live' or something and such cause I never get on to play unless other friends available.