Archived
Merge branch 'wikipedia'
This commit is contained in:
Generated
+20
@@ -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",
|
||||||
@@ -15009,6 +15024,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",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "latest",
|
"axios": "latest",
|
||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
|
"@c0b41/ytclear": "^1.0.0",
|
||||||
"bootstrap": "^4.1.3",
|
"bootstrap": "^4.1.3",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"lodash-id": "^0.14.0",
|
"lodash-id": "^0.14.0",
|
||||||
@@ -17,6 +18,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
@@ -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>
|
||||||
|
|||||||
+14
-4
@@ -178,9 +178,19 @@ class VideoInfo extends Component {
|
|||||||
</ul>
|
</ul>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab eventKey={4} title="Wikipedia">
|
<Tab eventKey={4} title="Wikipedia">
|
||||||
<div>
|
<Wikipedia
|
||||||
|
title={
|
||||||
</div>
|
this.props.location.state
|
||||||
|
? this.props.location.state.title
|
||||||
|
: this.state.others.title
|
||||||
|
}
|
||||||
|
artist={
|
||||||
|
this.props.location.state
|
||||||
|
? this.props.location.state.artist
|
||||||
|
: this.state.others.artist
|
||||||
|
}
|
||||||
|
videoId={this.props.match.params.id}
|
||||||
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -197,4 +207,4 @@ VideoInfo.propTypes = {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default VideoInfo;
|
export default VideoInfo;
|
||||||
|
|||||||
+5
-6
@@ -125,12 +125,11 @@ class VideoList extends React.Component {
|
|||||||
{items.map(item => (
|
{items.map(item => (
|
||||||
<Col key={item.videoID} lg={{ span: 3 }} md="6">
|
<Col key={item.videoID} lg={{ span: 3 }} md="6">
|
||||||
<Card className="my-1 carta">
|
<Card className="my-1 carta">
|
||||||
<Link
|
<Link to={{
|
||||||
to={{
|
pathname: '/video/' + item.videoID,
|
||||||
pathname: '/video/' + item.videoID,
|
state: {
|
||||||
state: {
|
artist: item.artist,
|
||||||
artist: item.artist,
|
title: item.title
|
||||||
title: item.title
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
+175
-71
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user