ricerca wikidata con id youtube

This commit is contained in:
matteo
2018-12-11 04:01:03 +01:00
parent 2bca56b881
commit ea18c64925
5 changed files with 83 additions and 55 deletions
+31 -30
View File
@@ -839,6 +839,21 @@
"to-fast-properties": "^2.0.0" "to-fast-properties": "^2.0.0"
} }
}, },
"@c0b41/ytclear": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@c0b41/ytclear/-/ytclear-1.0.0.tgz",
"integrity": "sha512-XRlrOlcUZhFURt6x1G1q40Oq4SvYr3j0NAcZeahx4N3em8eAY8831jPjeRBT+nQd762yYINanlfUX2uaG3UaaA==",
"requires": {
"minimist": "^1.1.1"
},
"dependencies": {
"minimist": {
"version": "1.2.0",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
}
}
},
"@csstools/convert-colors": { "@csstools/convert-colors": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz", "resolved": "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz",
@@ -5488,8 +5503,7 @@
}, },
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@@ -5507,13 +5521,11 @@
}, },
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@@ -5526,18 +5538,15 @@
}, },
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@@ -5640,8 +5649,7 @@
}, },
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@@ -5651,7 +5659,6 @@
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@@ -5664,20 +5671,17 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@@ -5694,7 +5698,6 @@
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@@ -5767,8 +5770,7 @@
}, },
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@@ -5778,7 +5780,6 @@
"once": { "once": {
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@@ -5854,8 +5855,7 @@
}, },
"safe-buffer": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"bundled": true, "bundled": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@@ -5885,7 +5885,6 @@
"string-width": { "string-width": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@@ -5903,7 +5902,6 @@
"strip-ansi": { "strip-ansi": {
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@@ -5942,13 +5940,11 @@
}, },
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.2", "version": "3.0.2",
"bundled": true, "bundled": true
"optional": true
} }
} }
}, },
@@ -14968,6 +14964,11 @@
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz",
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho="
}, },
"wikidata-sdk": {
"version": "5.15.9",
"resolved": "https://registry.npmjs.org/wikidata-sdk/-/wikidata-sdk-5.15.9.tgz",
"integrity": "sha512-I40/v7vW3gw1aLZ9/Yao4+I5ETPoOgE+3dt4rQxJkS510ow4nPb6DTtvA95zppmtDMDSNCNA1a7HN6FNRtAFQg=="
},
"wikijs": { "wikijs": {
"version": "4.8.1", "version": "4.8.1",
"resolved": "https://registry.npmjs.org/wikijs/-/wikijs-4.8.1.tgz", "resolved": "https://registry.npmjs.org/wikijs/-/wikijs-4.8.1.tgz",
+2
View File
@@ -3,6 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@c0b41/ytclear": "^1.0.0",
"axios": "^0.18.0", "axios": "^0.18.0",
"bootstrap": "^4.1.3", "bootstrap": "^4.1.3",
"express": "^4.16.4", "express": "^4.16.4",
@@ -13,6 +14,7 @@
"react-router-dom": "^4.3.1", "react-router-dom": "^4.3.1",
"react-scripts": "2.1.1", "react-scripts": "2.1.1",
"react-youtube": "^7.8.0", "react-youtube": "^7.8.0",
"wikidata-sdk": "^5.15.9",
"wikijs": "^4.8.1" "wikijs": "^4.8.1"
}, },
"scripts": { "scripts": {
+6 -2
View File
@@ -3,6 +3,7 @@
import Wikipedia from './areainfo/Wikipedia'; import Wikipedia from './areainfo/Wikipedia';
import { Col, Tabs, Tab } from 'react-bootstrap'; import { Col, Tabs, Tab } from 'react-bootstrap';
import axios from 'axios'; import axios from 'axios';
const ytclear = require('@c0b41/ytclear');
class VideoInfo extends Component { class VideoInfo extends Component {
constructor(props) { constructor(props) {
@@ -88,10 +89,13 @@
{/* codice per tabs reccomenders */} {/* codice per tabs reccomenders */}
<Tabs defaultActiveKey="a" id="uncontrolled-tab-example"> <Tabs defaultActiveKey="a" id="uncontrolled-tab-example">
<Tab eventKey="a" title="A"> <Tab eventKey="a" title="A">
<Wikipedia query={ this.props.location.state ? this.props.location.state.title : VideoDetails.snippet.title } /> <Wikipedia title={ this.props.location.state ? this.props.location.state.title : VideoDetails.snippet.title }
artist={ this.props.location.state ? this.props.location.state.artist : '' }
videoId={ this.props.match.params.id}
/>
</Tab> </Tab>
<Tab eventKey="b" title="B"> <Tab eventKey="b" title="B">
<p>{}</p> <p>{ ytclear(this.state.VideoDetails.snippet.title)}</p>
</Tab> </Tab>
<Tab eventKey="c" title="C"> <Tab eventKey="c" title="C">
<p>C</p> <p>C</p>
+1 -1
View File
@@ -129,7 +129,7 @@ class VideoList extends React.Component {
pathname: '/video/' + item.videoID, pathname: '/video/' + item.videoID,
state: { state: {
artist: item.artist, artist: item.artist,
title: item.title +' '+ item.artist title: item.title
} }
}}> }}>
{/* {item.artist} - {item.title} {item.videoID} {item.category} */} {/* {item.artist} - {item.title} {item.videoID} {item.category} */}
+40 -19
View File
@@ -1,13 +1,16 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
// import PropTypes from 'prop-types'; // import PropTypes from 'prop-types';
import wikijs from 'wikijs'; import wikijs from 'wikijs';
import wdk from 'wikidata-sdk';
import axios from 'axios';
class Wikipedia extends Component { class Wikipedia extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
data: {}, wikidata: null,
infobox: {}, wikipedia: null,
spareobj: {},
error: null, error: null,
isLoaded: false isLoaded: false
}; };
@@ -36,25 +39,42 @@ class Wikipedia extends Component {
// } // }
componentWillMount() { componentWillMount() {
wikijs() // wikijs()
.find(this.props.query, this.raffina) // .find(this.props.query, this.raffina)
.then( // .then(
data => { // data => {
this.setState({ // this.setState({
data, // data,
isLoaded: true // isLoaded: true
}); // });
console.log(data.html()); // console.log(data.html());
//this.getWikiBox(data.results[0]); // //this.getWikiBox(data.results[0]);
}, // },
error => { // error => {
console.error(error); // console.error(error);
// this.setState({
// isLoaded: true,
// error
// });
// }
// );
axios
.get(wdk.getReverseClaims('P1651', this.props.videoId)) // P1651 is youtube_video_id property
.then(wikidataSearchRes => {
if (wikidataSearchRes.data.results.bindings.length) {
axios.get(wdk.getEntities(wdk.simplify.sparqlResults(wikidataSearchRes.data), 'en'))
.then(wikidataPage => {
this.setState({ this.setState({
isLoaded: true, isLoaded: true,
error wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]]
}); });
console.info('wikidata baby',this.state.wikidata);
});
} else {
console.log('oof');
} }
); });
} }
// componentWillReceiveProps(nextProps) { // componentWillReceiveProps(nextProps) {
@@ -78,7 +98,7 @@ class Wikipedia extends Component {
// } // }
render() { render() {
const { data, error, isLoaded } = this.state; const { wikidata, error, isLoaded } = this.state;
if (error) { if (error) {
return <React.Fragment>Error: {error.message}</React.Fragment>; return <React.Fragment>Error: {error.message}</React.Fragment>;
} else if (!isLoaded) { } else if (!isLoaded) {
@@ -86,7 +106,8 @@ class Wikipedia extends Component {
} else { } else {
return ( return (
<div> <div>
{/* <p>risultato ricerca wikipedia: { data.results[0] }</p> */} <p>risultato ricerca wikipedia:</p>
<pre>{ }</pre>
</div> </div>
); );
} }