Updating Database with a Python script
#1
Hi,

I'm trying to update one field of the database with a new information.

Explanation: I'm updating the Filmaffinity scraper. Trailers are youtube urls (not playable with XBMC) but time ago there was a webpage that returned FLV urls with the youtube id. Now I want to change all the urls (http://www.yobajo.com/&watch="YOUTUBEID") to plugin://youtubeplugin...)

This is what I've done, but I don't know how to perform the UPDATE SQL consults.

Please, anyone can help meHuh

Quote:import xbmc
import xbmcgui
from urllib import quote_plus, unquote_plus
import re
import sys
import os
import random

class Main:
def __init__( self ):
finalurl = ""
Youcode = ""
consulta= "SELECT movie.c19 FROM movie"
consulta_xml= xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( consulta ), )
urls = re.findall("<record>(.+?)</record>", consulta_xml)
for trailerurl in urls:
YouCode = re.search('http://www.yobajo.com/watch?v=(.*?)', trailerurl)
finalurl += "plugin://plugin.video.youtube/?action=play_video&videoid="
finalurl += Youcode
nuevaconsulta = "UPDATE movie SET movie.c19 ='" + finalurl + "' WHERE movie.c19 = '" + trailerurl + "'"
escribir_consulta= xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( nuevaconsulta ), )


if ( __name__ == "__main__" ):
Main()

This is the error it returns:

Quote:16:28:27 T:3352 M:382279680 ERROR: SQL: MUST be select SQL!
16:28:27 T:3352 M:382279680 ERROR: CVideoDatabase::GetArbitraryQuery failed

Thanks!
Image
Reply
#2
A query cannot do an update. You want to be able to execute a command, which we have support for but you shouldn't be relying on (said support will go away). See the ExecVideoDatabase or whatever it is.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
If ExecVideoDatabase support will go away, how can I do this having a "long" time support command?
Image
Reply
#4
You'd have to wait until something is implemented for the JSON-RPC stuff.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
OK, then I'm going to use it as a temporal script (this is for not having to rescrape all the library again to fix one only field)
Image
Reply
#6
I'd think the easiest way to do this is to have the plugin/script call an outside program that manipulates the database directly with SQLite. Sure it's a bit more risky, but it will do exactly what you want it too.
Reply
#7
I have finished the script. More than a safe thing I want an easy thing that average user can use without having to install anything.

Here is the script if anyone is interested in:

Quote:import xbmc
import xbmcgui
from urllib import quote_plus, unquote_plus
import re
import sys
import os
import random

class Main:
def __init__( self ):
finalurl = ""
Youcode = ""
consulta= "SELECT movie.c19 FROM movie"
consulta_xml= xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( consulta ), )
urls = re.findall("<record>(.+?)</record>", consulta_xml)
for trailerurl in urls:
temporal = re.findall('<field>(.+?)</field>',trailerurl)
YouCode = re.findall('http...http://www.yobajo.com/watch\?v=(.*)\'',str(temporal))
if len(YouCode) > 0:
if len(str(YouCode[0])) >= 1:
print "URL Anterior:" + temporal[0]
finalurl = "plugin://plugin.video.youtube/?action=play_video&videoid=" + str(YouCode[0])
print "URL Nueva:" + finalurl
nuevaconsulta = "UPDATE movie SET c19 ='" + finalurl + "' WHERE c19 = '" + temporal[0] + "'"
escribir_consulta= xbmc.executehttpapi( "ExecVideoDatabase(%s)" % quote_plus( nuevaconsulta ), )
print "Datos actualizados correctamente."
xbmc.executebuiltin('Notification('"DBUpdater"','"Actualización Completa."')')

if ( __name__ == "__main__" ):
Main()
Image
Reply

Logout Mark Read Team Forum Stats Members Help
Updating Database with a Python script0