From 2bca56b881ff637fcc42954c21e31afc39a1fcac Mon Sep 17 00:00:00 2001 From: matteo Date: Sat, 1 Dec 2018 03:04:08 +0100 Subject: [PATCH 1/5] bobbe malle --- src/areainfo/Wikipedia.js | 144 +++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/src/areainfo/Wikipedia.js b/src/areainfo/Wikipedia.js index b0b47f6..6c11a29 100644 --- a/src/areainfo/Wikipedia.js +++ b/src/areainfo/Wikipedia.js @@ -3,92 +3,94 @@ import React, { Component } from 'react'; import wikijs from 'wikijs'; class Wikipedia extends Component { - constructor(props) { - super(props); - this.state = { - data: {}, - infobox: {}, - error: null, - isLoaded: false - }; -this.getWikiBox = this.getWikiBox.bind(this); -this.raffina = this.raffina.bind(this); - } + constructor(props) { + super(props); + this.state = { + data: {}, + infobox: {}, + error: null, + isLoaded: false + }; + this.getWikiBox = this.getWikiBox.bind(this); + this.raffina = this.raffina.bind(this); + } - getWikiBox(name){ - wikijs() - .page(name) - .then(page => page.fullInfo()) - .then(infobox => console.log('infobox', infobox) - //this.setState({ infobox }) - ); - //console.log('infobox', this.state.infobox) - } + getWikiBox(name) { + wikijs() + .page(name) + .then(page => page.fullInfo()) + .then( + infobox => console.log('infobox', infobox) + //this.setState({ infobox }) + ); + //console.log('infobox', this.state.infobox) + } - raffina(results){ - console.log('raffina',results); - return results[0]; - } + raffina(results) { + console.log('raffina', results); + return results[0]; + } - // componentWillMount() { + // componentWillMount() { - // } + // } - componentWillMount() { - wikijs().find(this.props.query, this.raffina).then(data => { - this.setState({ - data, - isLoaded: true - }); - console.log(data.html()); - //this.getWikiBox(data.results[0]); - }, error => { - console.error(error); - this.setState({ - isLoaded: true, - error - }); - }); - } + componentWillMount() { + wikijs() + .find(this.props.query, this.raffina) + .then( + data => { + this.setState({ + data, + isLoaded: true + }); + console.log(data.html()); + //this.getWikiBox(data.results[0]); + }, + error => { + console.error(error); + this.setState({ + isLoaded: true, + error + }); + } + ); + } - // componentWillReceiveProps(nextProps) { + // componentWillReceiveProps(nextProps) { - // } + // } - // shouldComponentUpdate(nextProps, nextState) { + // shouldComponentUpdate(nextProps, nextState) { - // } + // } - // componentWillUpdate(nextProps, nextState) { + // componentWillUpdate(nextProps, nextState) { - // } + // } - // componentDidUpdate(prevProps, prevState) { + // componentDidUpdate(prevProps, prevState) { - // } + // } - // componentWillUnmount() { + // componentWillUnmount() { - // } + // } - render() { - const { data, error, isLoaded } = this.state; - if (error) { - return ( - - Error: {error.message} -- Cannot get {error.config.url} - - ); - } else if (!isLoaded) { - return Loading...; - } else { - return ( -
- {/*

risultato ricerca wikipedia: { data.results[0] }

*/} -
- ); - } - } + render() { + const { data, error, isLoaded } = this.state; + if (error) { + return Error: {error.message}; + } else if (!isLoaded) { + return Loading...; + } else { + return ( +
+ {/*

risultato ricerca wikipedia: { data.results[0] }

*/} +
+ ); + } + } } -export default Wikipedia; \ No newline at end of file +export default Wikipedia; From ea18c649258392c3425a9c456f8ebacd942bca74 Mon Sep 17 00:00:00 2001 From: matteo Date: Tue, 11 Dec 2018 03:56:13 +0100 Subject: [PATCH 2/5] ricerca wikidata con id youtube --- package-lock.json | 61 ++++++++++++++++++------------------ package.json | 2 ++ src/VideoInfo.js | 8 +++-- src/VideoList.js | 2 +- src/areainfo/Wikipedia.js | 65 ++++++++++++++++++++++++++------------- 5 files changed, 83 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index ee5ab49..05c6472 100644 --- a/package-lock.json +++ b/package-lock.json @@ -839,6 +839,21 @@ "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": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@csstools/convert-colors/-/convert-colors-1.4.0.tgz", @@ -5488,8 +5503,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -5507,13 +5521,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5526,18 +5538,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -5640,8 +5649,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -5651,7 +5659,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5664,20 +5671,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -5694,7 +5698,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -5767,8 +5770,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -5778,7 +5780,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -5854,8 +5855,7 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -5885,7 +5885,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5903,7 +5902,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5942,13 +5940,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.2", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -14968,6 +14964,11 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "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": { "version": "4.8.1", "resolved": "https://registry.npmjs.org/wikijs/-/wikijs-4.8.1.tgz", diff --git a/package.json b/package.json index dedacce..6dea5d2 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "@c0b41/ytclear": "^1.0.0", "axios": "^0.18.0", "bootstrap": "^4.1.3", "express": "^4.16.4", @@ -13,6 +14,7 @@ "react-router-dom": "^4.3.1", "react-scripts": "2.1.1", "react-youtube": "^7.8.0", + "wikidata-sdk": "^5.15.9", "wikijs": "^4.8.1" }, "scripts": { diff --git a/src/VideoInfo.js b/src/VideoInfo.js index 1dc6f4a..6829f8b 100644 --- a/src/VideoInfo.js +++ b/src/VideoInfo.js @@ -3,6 +3,7 @@ import Wikipedia from './areainfo/Wikipedia'; import { Col, Tabs, Tab } from 'react-bootstrap'; import axios from 'axios'; + const ytclear = require('@c0b41/ytclear'); class VideoInfo extends Component { constructor(props) { @@ -88,10 +89,13 @@ {/* codice per tabs reccomenders */} - + -

{}

+

{ ytclear(this.state.VideoDetails.snippet.title)}

C

diff --git a/src/VideoList.js b/src/VideoList.js index c098398..3331893 100644 --- a/src/VideoList.js +++ b/src/VideoList.js @@ -129,7 +129,7 @@ class VideoList extends React.Component { pathname: '/video/' + item.videoID, state: { artist: item.artist, - title: item.title +' '+ item.artist + title: item.title } }}> {/* {item.artist} - {item.title} {item.videoID} {item.category} */} diff --git a/src/areainfo/Wikipedia.js b/src/areainfo/Wikipedia.js index 6c11a29..13fecba 100644 --- a/src/areainfo/Wikipedia.js +++ b/src/areainfo/Wikipedia.js @@ -1,13 +1,16 @@ import React, { Component } from 'react'; // import PropTypes from 'prop-types'; import wikijs from 'wikijs'; +import wdk from 'wikidata-sdk'; +import axios from 'axios'; class Wikipedia extends Component { constructor(props) { super(props); this.state = { - data: {}, - infobox: {}, + wikidata: null, + wikipedia: null, + spareobj: {}, error: null, isLoaded: false }; @@ -36,25 +39,42 @@ class Wikipedia extends Component { // } componentWillMount() { - wikijs() - .find(this.props.query, this.raffina) - .then( - data => { - this.setState({ - data, - isLoaded: true - }); - console.log(data.html()); - //this.getWikiBox(data.results[0]); - }, - error => { - console.error(error); - this.setState({ - isLoaded: true, - error - }); + // wikijs() + // .find(this.props.query, this.raffina) + // .then( + // data => { + // this.setState({ + // data, + // isLoaded: true + // }); + // console.log(data.html()); + // //this.getWikiBox(data.results[0]); + // }, + // 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({ + isLoaded: true, + wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]] + }); + console.info('wikidata baby',this.state.wikidata); + }); + } else { + console.log('oof'); } - ); + }); + } // componentWillReceiveProps(nextProps) { @@ -78,7 +98,7 @@ class Wikipedia extends Component { // } render() { - const { data, error, isLoaded } = this.state; + const { wikidata, error, isLoaded } = this.state; if (error) { return Error: {error.message}; } else if (!isLoaded) { @@ -86,7 +106,8 @@ class Wikipedia extends Component { } else { return (
- {/*

risultato ricerca wikipedia: { data.results[0] }

*/} +

risultato ricerca wikipedia:

+
{  }
); } From b0dbba7673387408eb2862b22561f8789c9f4d6c Mon Sep 17 00:00:00 2001 From: matteo Date: Tue, 11 Dec 2018 19:48:04 +0100 Subject: [PATCH 3/5] wikidata wikipedia musicbrainz --- public/index.html | 2 +- src/VideoInfo.js | 227 +++++++++++++++++++++----------------- src/areainfo/Wikipedia.js | 104 ++++++++++------- 3 files changed, 191 insertions(+), 142 deletions(-) diff --git a/public/index.html b/public/index.html index faa86e6..542ad55 100644 --- a/public/index.html +++ b/public/index.html @@ -19,7 +19,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - react-4 + HazeTv