Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: aca5538984
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 34 lines (28 sloc) 1.196 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?xml version="1.0" encoding="UTF-8" ?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
  <meta>
    <sampleQuery>select * from {table} where movieid="27205"</sampleQuery>
    <description>Retrieve movie title and year from TMDB. See http://stackoverflow.com/questions/3292899/tailoring-the-output-of-yql</description>
    <author>Peter Cowburn</author>
  </meta>
  <bindings>
    <select itemPath="movie" produces="XML">
      <inputs>
        <key id="movieid" type="xs:string" paramType="variable" required="true"/>
      </inputs>
      <execute><![CDATA[
var query = 'select content from html where url="http://www.themoviedb.org/movie/'
+ movieid + '" and xpath=\\'//h3[@id="year"]|//h2[@id="title"]/a\\'';

var result = y.query(query).results;
var movie = <movie/>;

// The title can span multiple lines, lets remove breaks.
var title = result.a.text().toString().replace(/\\s+/g, ' ');

// The year has parentheses around it, let's remove those.
var year = result.h3.text().toString().replace(/^\\(|\\)$/g, '');

movie.node += <title>{title}</title>;
movie.node += <year>{year}</year>;

response.object = movie;
]]></execute>
    </select>
  </bindings>
</table>
Something went wrong with that request. Please try again.