Archived
mi sono perso per strada
This commit is contained in:
+2
-18
@@ -97,10 +97,7 @@ class VideoInfo extends Component {
|
||||
} else {
|
||||
return (
|
||||
<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
|
||||
title={
|
||||
this.props.location.state
|
||||
@@ -114,20 +111,7 @@ class VideoInfo extends Component {
|
||||
}
|
||||
videoId={this.props.match.params.id}
|
||||
/>
|
||||
</Tab>
|
||||
<Tab eventKey="b" title="B">
|
||||
<p>{this.state.others.artist}</p>
|
||||
<p>{this.state.others.title}</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>
|
||||
);
|
||||
}
|
||||
|
||||
+97
-72
@@ -4,6 +4,7 @@ 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 {
|
||||
constructor(props) {
|
||||
@@ -16,81 +17,90 @@ class Wikipedia extends Component {
|
||||
error: null,
|
||||
isLoaded: false
|
||||
};
|
||||
this.getWikiBox = this.getWikiBox.bind(this);
|
||||
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) {
|
||||
wikijs()
|
||||
.page(name)
|
||||
.then(page => page.fullInfo())
|
||||
.then(
|
||||
infobox => console.log('infobox', infobox)
|
||||
//this.setState({ infobox })
|
||||
);
|
||||
//console.log('infobox', this.state.infobox)
|
||||
ISO_8601toYYYY(a) {
|
||||
return moment(a, [moment.ISO_8601, 'YYYY']).format('YYYY');
|
||||
}
|
||||
|
||||
raffina(results) {
|
||||
console.log('raffina', results);
|
||||
filterWikipediaRes(results) {
|
||||
console.log('filterWikipediaRes', results);
|
||||
return results[0];
|
||||
}
|
||||
|
||||
getWikidataPage(wikidataPXXXXResID){
|
||||
return axios.get(wdk.getEntities(wikidataPXXXXResID, 'en'))
|
||||
.then(wikidataPage => {
|
||||
this.setState({
|
||||
wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]]
|
||||
});// onReject todo
|
||||
})
|
||||
.finally(()=>{
|
||||
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({ isLoaded: true,
|
||||
wikipedia: wikipediaRes}));
|
||||
});
|
||||
}
|
||||
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
|
||||
else { //oof
|
||||
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
|
||||
axios.get(musicbrainzBaseUrl+"/work",{
|
||||
params:{
|
||||
'query':this.props.title,
|
||||
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 }));
|
||||
});
|
||||
|
||||
} else { //oof
|
||||
axios.get(`${musicbrainzBaseUrl}/work`, {
|
||||
params: {
|
||||
'query': this.props.title,
|
||||
'limit': 1,
|
||||
'offset': 0,
|
||||
'fmt':'json'
|
||||
'fmt': 'json'
|
||||
}
|
||||
}).then(musicbrainzRes=> {
|
||||
// console.log(musicbrainzRes.data.works[0],musicbrainzRes.data.works[0].id)
|
||||
}).then(musicbrainzRes => {
|
||||
this.setState({ musicbrainz: musicbrainzRes.data.works[0] });
|
||||
axios.all([
|
||||
axios.get(wdk.getReverseClaims('P435', musicbrainzRes.data.works[0].id)), // P435 is musicbrainz id
|
||||
axios.get(musicbrainzBaseUrl+"/work/"+musicbrainzRes.data.works[0].id,{ //
|
||||
params:{
|
||||
'inc':'url-rels',
|
||||
'fmt':'json'
|
||||
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) => {
|
||||
// console.info(wikidataP435Res.data,musicbrainzWorkRes.data)
|
||||
if(wikidataP435Res.data.results.bindings.length) // found a match
|
||||
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
|
||||
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));
|
||||
}
|
||||
else{ // oof
|
||||
wikijs().find(this.props.title).then(data=>console.log('asd',data)) // find by props.title
|
||||
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
|
||||
}
|
||||
})
|
||||
)
|
||||
@@ -100,6 +110,9 @@ class Wikipedia extends Component {
|
||||
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
}
|
||||
|
||||
// componentWillReceiveProps(nextProps) {
|
||||
|
||||
// }
|
||||
@@ -122,50 +135,62 @@ class Wikipedia extends Component {
|
||||
|
||||
render() {
|
||||
const { wikidata, wikipedia, musicbrainz, error, isLoaded } = this.state;
|
||||
|
||||
const ISO_8601toYYYY = this.ISO_8601toYYYY;
|
||||
if (error) {
|
||||
return <React.Fragment>Error: {error.message}</React.Fragment>;
|
||||
} else if (!isLoaded) {
|
||||
return <React.Fragment>Loading...</React.Fragment>;
|
||||
} else {
|
||||
let keys = {wikipedia : Object.keys(this.state.wikipedia[0].general),
|
||||
wikidata :Object.keys(this.state.wikidata.claims)}
|
||||
let keys = {
|
||||
wikipedia: Object.keys(this.state.wikipedia.info),
|
||||
wikidata: Object.keys(this.state.wikidata.claims)
|
||||
}
|
||||
return (
|
||||
// <div>
|
||||
// <p>risultato ricerca wikidata:</p>
|
||||
// { wikidata && <div>
|
||||
// <p>{ wikidata.labels.en.value }</p>
|
||||
// <p>{ wikidata.id }</p>
|
||||
// { wikidata.sitelinks.enwiki && <p>{ wikidata.sitelinks.enwiki.title} </p>}
|
||||
// </div> }
|
||||
// <p>wikipedia summary:</p>
|
||||
// {this.state.wikipedia && <p>{ this.state.wikipedia[1]}</p>}
|
||||
// </div>
|
||||
//
|
||||
// <React.Fragment>
|
||||
<Table striped bordered hover size="sm">
|
||||
<tbody>
|
||||
{
|
||||
keys.wikipedia.map(key => (
|
||||
<tr>
|
||||
<td>{key}</td>
|
||||
<td> {wikipedia[0].general[key].toLocaleString()}</td>
|
||||
<td>{wikipedia.info[key].toLocaleString()}</td>
|
||||
</tr>
|
||||
))
|
||||
}
|
||||
{
|
||||
keys.wikidata.map(key => (
|
||||
<tr>
|
||||
<td>{key}</td>
|
||||
<td> {wikidata.claims[key][0].mainsnak.datavalue.value.toLocaleString()}</td>
|
||||
<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>
|
||||
// </React.Fragment>
|
||||
// </Table>
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user