Open UlisesGascon opened 8 years ago
gracias por la info @UlisesGascon, no conocia esa API pero tiene muy buena pinta, le echaré un vistazo! :+1:
y como soy bastante vago para hacer el parseado xml a json manualmente, he encontrado: https://davidwalsh.name/convert-xml-json
voy a ver si encuentro alguna API pública al que le envie el xml y me devuelva la llamada en .json jeje
hahahaha! Más fácil... te paso un borrador que puede servirte, al final solo necesitas la url :+1:
function peticionAJAX(imbdID) {
var peticion = new XMLHttpRequest();
peticion.onreadystatechange = function() {
if (peticion.readyState == 4 && peticion.status == 200) {
var trailerURL = dameTrailer(peticion.responseText);
console.log(trailerURL);
document.body.innerHTML = '<iframe src="http://' + trailerURL + '" height="100%" width="100%"></iframe>';
}
};
peticion.open("GET", "http://crossorigin.me/http://api.traileraddict.com/?imdb=" + imbdID + "&count=4&width=680", true);
peticion.send();
}
function dameTrailer(datosXML) {
var datosConvertidos;
if (window.DOMParser) {
var parser = new DOMParser();
datosConvertidos = parser.parseFromString(datosXML, "text/xml");
} else {
// IE
datosConvertidos = new ActiveXObject("Microsoft.XMLDOM");
datosConvertidos.async = false;
datosConvertidos.loadXML(datosXML);
}
datosConvertidos = datosConvertidos.getElementsByTagName("embed")[0].childNodes[0].nodeValue;
var inicio = datosConvertidos.indexOf('//');
var fin = datosConvertidos.indexOf('"', inicio);
return datosConvertidos.substring(inicio, fin);
}
peticionAJAX(3083008);
Hola @xDae!
Estoy pensando que podría ser muy interesante incluir los trailers de las películas.
He visto que utilizas el IMBD ID en MovieCard.vue para realizar la petición de posters usando fanArt.
Podrías usar la misma variable para cargar el trailer usando el API de traileraddict.
Te paso un ejemplo:
Aunque esto tiene un par de complicaciones... por un lado que el formato es xml. Este formato se puede parsear fácilmente.
XML parseado.
Por otro lado traileraddict unicamente entiende como ID valores numéricos. En algunos casos IMBD asigna IDs no numéricas. Esto se puede solucionar usando parseInt() para eliminar los elementos no numéricos.
¿ @xDae ... que opinas?
Un abrazo!