Author SHA1 Message Date
matteo c7b4f0c347 mi sono perso per strada 2018-12-15 16:48:19 +01:00
matteo 2b58b105dd visualizza infobox wikipedia e propieta wikidata 2018-12-12 19:16:18 +01:00
matteo b0dbba7673 wikidata wikipedia musicbrainz 2018-12-11 19:48:04 +01:00
matteo ea18c64925 ricerca wikidata con id youtube 2018-12-11 04:01:03 +01:00
matteo 2bca56b881 bobbe malle 2018-12-01 03:04:08 +01:00
6 changed files with 319 additions and 203 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": {
+1 -1
View File
@@ -19,7 +19,7 @@
work correctly both with client-side routing and a non-root public URL. 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`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>react-4</title> <title>HazeTv</title>
</head> </head>
<body> <body>
<noscript> <noscript>
+107 -98
View File
@@ -1,114 +1,123 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
// import PropTypes from 'prop-types'; // import PropTypes from 'prop-types';
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) {
super(props); super(props);
this.state={ this.state = {
error: null, error: null,
isLoaded: false, isLoaded: false,
VideoDetails: {}, VideoDetails: {},
videoId: '0J2QdDbelmY' videoId: '0J2QdDbelmY',
}; others: {}
};
}
} componentWillMount() {
if (this.props.match.params.id) {
if (this.props.match.params.id === this.state.videoId) {
} else {
this.setState({ videoId: this.props.match.params.id });
}
}
}
componentWillMount() { componentDidMount() {
if(this.props.match.params.id){ axios
if(this.props.match.params.id === this.state.videoId){} .get('https://www.googleapis.com/youtube/v3/videos', {
else{ params: {
this.setState({videoId: this.props.match.params.id}); part: 'snippet,contentDetails,statistics,topicDetails',
} id: this.state.videoId,
} key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
} }
})
.then(
response => {
this.setState((state, props) => {
return {
VideoDetails: response.data.items[0],
isLoaded: true,
others: {
artist: ytclear(response.data.items[0].snippet.title).split('-')[0],
title: ytclear(response.data.items[0].snippet.title).split('-')[1]
}
};
});
},
error => {
console.error(error);
this.setState({
isLoaded: true,
error
});
}
);
}
componentDidMount() { // componentWillReceiveProps(nextProps) {
axios.get('https://www.googleapis.com/youtube/v3/videos', {
params: {
'part': 'snippet,contentDetails,statistics,topicDetails',
'id': this.state.videoId,
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
}
}).then(response => {
this.setState({
VideoDetails: response.data.items[0],
isLoaded: true});
}, error => {
console.error(error);
this.setState({
isLoaded: true,
error
});
});
}
// componentWillReceiveProps(nextProps) { // }
// } // shouldComponentUpdate(nextProps, nextState) {
// shouldComponentUpdate(nextProps, nextState) { // }
// } componentWillUpdate(nextProps, nextState) {
// console.info('nextProps',nextProps);
// console.info('nextState',nextState);
if (nextProps.match.params.id === this.state.videoId) {
} else if (nextProps.match.params.id) {
this.setState({ videoId: nextProps.match.params.id });
}
}
componentWillUpdate(nextProps, nextState) { componentDidUpdate(prevProps, prevState) {
// console.info('nextProps',nextProps); // console.info('prevProps',prevProps);
// console.info('nextState',nextState); // console.info('prevState',prevState);
if(nextProps.match.params.id === this.state.videoId){} }
else if( nextProps.match.params.id){
this.setState({videoId: nextProps.match.params.id});
}
}
componentDidUpdate(prevProps, prevState) { // componentWillUnmount() {
// console.info('prevProps',prevProps);
// console.info('prevState',prevState);
}
// componentWillUnmount() { // }
// } render() {
const { error, isLoaded, VideoDetails } = this.state;
if (error) {
return (
<React.Fragment>
Error: {error.message} -- Cannot get {error.config.url}
</React.Fragment>
);
} else if (!isLoaded) {
return <React.Fragment>Loading...</React.Fragment>;
} else {
return (
<React.Fragment>
render() { <Wikipedia
const { error, isLoaded, VideoDetails } = this.state; title={
if (error) { this.props.location.state
return ( ? this.props.location.state.title
<React.Fragment> : this.state.others.title
Error: {error.message} -- Cannot get {error.config.url} }
</React.Fragment> artist={
); this.props.location.state
} else if (!isLoaded) { ? this.props.location.state.artist
return <React.Fragment>Loading...</React.Fragment>; : this.state.others.artist
} else { }
return ( videoId={this.props.match.params.id}
<React.Fragment> />
<Col className='border border-dark' lg={{span:7}}>
{/* codice per tabs reccomenders */}
<Tabs defaultActiveKey="a" id="uncontrolled-tab-example">
<Tab eventKey="a" title="A">
<Wikipedia query={ this.props.location.state ? this.props.location.state.title : VideoDetails.snippet.title } />
</Tab>
<Tab eventKey="b" title="B">
<p>{}</p>
</Tab>
<Tab eventKey="c" title="C">
<p>C</p>
</Tab>
</Tabs>
</Col>
<Col className='border border-dark' lg={{span:4, offset:1}}>
<p>2</p>
</Col>
</React.Fragment>
);
}
}
}
VideoInfo.propTypes = { </React.Fragment>
);
}
}
}
}; VideoInfo.propTypes = {};
export default VideoInfo; export default VideoInfo;
+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} */}
+174 -70
View File
@@ -1,94 +1,198 @@
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';
import { Table } from 'react-bootstrap';
import moment from 'moment';
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,
error: null, musicbrainz: null,
isLoaded: false spareobj: {},
}; error: null,
this.getWikiBox = this.getWikiBox.bind(this); isLoaded: false
this.raffina = this.raffina.bind(this); };
} this.filterWikipediaRes = this.filterWikipediaRes.bind(this);
this.ISO_8601toYYYY = this.ISO_8601toYYYY.bind(this);
this.getWikidataPage = this.getWikidataPage.bind(this);
}
getWikiBox(name){ ISO_8601toYYYY(a) {
wikijs() return moment(a, [moment.ISO_8601, 'YYYY']).format('YYYY');
.page(name) }
.then(page => page.fullInfo())
.then(infobox => console.log('infobox', infobox)
//this.setState({ infobox })
);
//console.log('infobox', this.state.infobox)
}
raffina(results){ filterWikipediaRes(results) {
console.log('raffina',results); console.log('filterWikipediaRes', results);
return results[0]; return results[0];
} }
// componentWillMount() { getWikidataPage(wikidataPXXXXResID) {
return axios.get(wdk.getEntities(wikidataPXXXXResID, 'en'))
.then(wikidataPage => {
this.setState({
wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]]
})
}, error => console.error(error))
.finally(() => {
console.log(this.state.wikidata)
if (this.state.wikidata.sitelinks.enwiki)
wikijs()
.page(this.state.wikidata.sitelinks.enwiki.title)
.then(page => Promise.all([page.fullInfo(), page.summary()]))
.then(wikipediaRes => this.setState({
wikipedia: {
"desc": wikipediaRes[1],
"info": wikipediaRes[0].general
}
}))
.finally(() => console.log(this.state.wikipedia));
});
}
// } componentWillMount() {
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
axios.get(wdk.getReverseClaims('P1651', this.props.videoId)) // P1651 is youtube_video_id property
.then(wikidataP1651Res => {
if (wikidataP1651Res.data.results.bindings.length) { // got a match
this.getWikidataPage(wdk.simplify.sparqlResults(wikidataP1651Res.data))// set in state wikidata
.then(() => {
console.log(this.state.wikidata.claims.P435[0].mainsnak.datavalue.value)
axios.get(`${musicbrainzBaseUrl}/work/${this.state.wikidata.claims.P435[0].mainsnak.datavalue.value}`, { // get musicbrainz info
params: {
'inc': 'artist-rels url-rels',
'limit': 1,
'offset': 0,
'fmt': 'json'
}
}).then(musicbrainzRes1 => this.setState({ isLoaded: true, musicbrainz: musicbrainzRes1.data }));
});
componentWillMount() { } else { //oof
wikijs().find(this.props.query, this.raffina).then(data => { axios.get(`${musicbrainzBaseUrl}/work`, {
this.setState({ params: {
data, 'query': this.props.title,
isLoaded: true 'limit': 1,
}); 'offset': 0,
console.log(data.html()); 'fmt': 'json'
//this.getWikiBox(data.results[0]); }
}, error => { }).then(musicbrainzRes => {
console.error(error); this.setState({ musicbrainz: musicbrainzRes.data.works[0] });
this.setState({ axios.all([
isLoaded: true, axios.get(wdk.getReverseClaims('P435', musicbrainzRes.data.works[0].id)), // P435 is musicbrainz id
error axios.get(`${musicbrainzBaseUrl}/work/${musicbrainzRes.data.works[0].id}`, { // get musicbrainz info
}); params: {
}); 'inc': 'artist-rels url-rels',
} 'fmt': 'json'
}
})
]).then(
axios.spread((wikidataP435Res, musicbrainzWorkRes) => {
if (wikidataP435Res.data.results.bindings.length) // found a match
this.getWikidataPage(wdk.simplify.sparqlResults(wikidataP435Res.data)); // set the result in the state
else if (musicbrainzWorkRes.data.relations.find(currentRel => currentRel.type === "wikidata")) { // found wikidata on music brainz
let a = musicbrainzWorkRes.data.relations.find(currentRel => currentRel.type === "wikidata");
let wikidataEntityRegEx = new RegExp("[^/]+$"); // match last part of url https://regex101.com/r/0wCQHY/1
this.getWikidataPage(wikidataEntityRegEx.exec(a.url.resource)).then(() => this.setState({ isLoaded: true }));
}
else { // oof
wikijs().find(this.props.title).then(data => console.log('asd', data)) // find by props.title
}
})
)
})
}
});
// componentWillReceiveProps(nextProps) { }
// } componentDidMount() {
}
// shouldComponentUpdate(nextProps, nextState) { // componentWillReceiveProps(nextProps) {
// } // }
// componentWillUpdate(nextProps, nextState) { // shouldComponentUpdate(nextProps, nextState) {
// } // }
// componentDidUpdate(prevProps, prevState) { // componentWillUpdate(nextProps, nextState) {
// } // }
// componentWillUnmount() { // componentDidUpdate(prevProps, prevState) {
// } // }
render() { // componentWillUnmount() {
const { data, error, isLoaded } = this.state;
if (error) { // }
return (
<React.Fragment> render() {
Error: {error.message} -- Cannot get {error.config.url} const { wikidata, wikipedia, musicbrainz, error, isLoaded } = this.state;
</React.Fragment> const ISO_8601toYYYY = this.ISO_8601toYYYY;
); if (error) {
} else if (!isLoaded) { return <React.Fragment>Error: {error.message}</React.Fragment>;
return <React.Fragment>Loading...</React.Fragment>; } else if (!isLoaded) {
} else { return <React.Fragment>Loading...</React.Fragment>;
return ( } else {
<div> let keys = {
{/* <p>risultato ricerca wikipedia: { data.results[0] }</p> */} wikipedia: Object.keys(this.state.wikipedia.info),
</div> wikidata: Object.keys(this.state.wikidata.claims)
); }
} return (
} <Table striped bordered hover size="sm">
<tbody>
{
keys.wikipedia.map(key => (
<tr>
<td>{key}</td>
<td>{wikipedia.info[key].toLocaleString()}</td>
</tr>
))
}
{
keys.wikidata.map(key => (
<tr>
<td>{`${key} - ${wikidata.claims[key][0].mainsnak.datatype}`}</td>
<td>{
typeof wikidata.claims[key][0].mainsnak.datavalue.value === "string" ?
wikidata.claims[key][0].mainsnak.datavalue.value :
typeof wikidata.claims[key][0].mainsnak.datavalue.value.id === "string" ?
wikidata.claims[key][0].mainsnak.datavalue.value.id :
typeof wikidata.claims[key][0].mainsnak.datavalue.value.time === "string" ?
ISO_8601toYYYY(wikidata.claims[key][0].mainsnak.datavalue.value.time.toString()) :
""
}</td>
</tr>
))
}
{
musicbrainz.relations.map(relation => {
if (relation["target-type"] === "artist")
return (<tr>
<td>{relation.type}</td>
<td>{relation.artist.name}</td>
</tr>);
else if (relation["target-type"] === "url")
return (<tr>
<td>{relation.type}</td>
<td><a href={relation.url.resource}>{relation.type}</a></td>
</tr>)
else
return ("");
})
}
</tbody>
</Table>
);
}
}
} }
export default Wikipedia; export default Wikipedia;