Archived
mi sono perso per strada
This commit is contained in:
+1
-17
@@ -97,10 +97,7 @@ class VideoInfo extends Component {
|
|||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<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
|
<Wikipedia
|
||||||
title={
|
title={
|
||||||
this.props.location.state
|
this.props.location.state
|
||||||
@@ -114,20 +111,7 @@ class VideoInfo extends Component {
|
|||||||
}
|
}
|
||||||
videoId={this.props.match.params.id}
|
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>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-71
@@ -4,6 +4,7 @@ import wikijs from 'wikijs';
|
|||||||
import wdk from 'wikidata-sdk';
|
import wdk from 'wikidata-sdk';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Table } from 'react-bootstrap';
|
import { Table } from 'react-bootstrap';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
class Wikipedia extends Component {
|
class Wikipedia extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -16,81 +17,90 @@ class Wikipedia extends Component {
|
|||||||
error: null,
|
error: null,
|
||||||
isLoaded: false
|
isLoaded: false
|
||||||
};
|
};
|
||||||
this.getWikiBox = this.getWikiBox.bind(this);
|
this.filterWikipediaRes = this.filterWikipediaRes.bind(this);
|
||||||
this.raffina = this.raffina.bind(this);
|
this.ISO_8601toYYYY = this.ISO_8601toYYYY.bind(this);
|
||||||
this.getWikidataPage = this.getWikidataPage.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];
|
||||||
}
|
}
|
||||||
|
|
||||||
getWikidataPage(wikidataPXXXXResID){
|
getWikidataPage(wikidataPXXXXResID) {
|
||||||
return axios.get(wdk.getEntities(wikidataPXXXXResID, 'en'))
|
return axios.get(wdk.getEntities(wikidataPXXXXResID, 'en'))
|
||||||
.then(wikidataPage => {
|
.then(wikidataPage => {
|
||||||
this.setState({
|
this.setState({
|
||||||
wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]]
|
wikidata: wikidataPage.data.entities[Object.keys(wikidataPage.data.entities)[0]]
|
||||||
});// onReject todo
|
})
|
||||||
})
|
}, error => console.error(error))
|
||||||
.finally(()=>{
|
.finally(() => {
|
||||||
if(this.state.wikidata.sitelinks.enwiki)
|
console.log(this.state.wikidata)
|
||||||
wikijs()
|
if (this.state.wikidata.sitelinks.enwiki)
|
||||||
.page(this.state.wikidata.sitelinks.enwiki.title)
|
wikijs()
|
||||||
.then(page => Promise.all([page.fullInfo(),page.summary()]))
|
.page(this.state.wikidata.sitelinks.enwiki.title)
|
||||||
.then(wikipediaRes => this.setState({ isLoaded: true,
|
.then(page => Promise.all([page.fullInfo(), page.summary()]))
|
||||||
wikipedia: wikipediaRes}));
|
.then(wikipediaRes => this.setState({
|
||||||
});
|
wikipedia: {
|
||||||
}
|
"desc": wikipediaRes[1],
|
||||||
|
"info": wikipediaRes[0].general
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.finally(() => console.log(this.state.wikipedia));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
|
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
|
||||||
axios.get(wdk.getReverseClaims('P1651', this.props.videoId)) // P1651 is youtube_video_id property
|
axios.get(wdk.getReverseClaims('P1651', this.props.videoId)) // P1651 is youtube_video_id property
|
||||||
.then(wikidataP1651Res => {
|
.then(wikidataP1651Res => {
|
||||||
if (wikidataP1651Res.data.results.bindings.length) // got a match
|
if (wikidataP1651Res.data.results.bindings.length) { // got a match
|
||||||
this.getWikidataPage(wdk.simplify.sparqlResults(wikidataP1651Res.data)); // set in state wikidata
|
this.getWikidataPage(wdk.simplify.sparqlResults(wikidataP1651Res.data))// set in state wikidata
|
||||||
else { //oof
|
.then(() => {
|
||||||
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
|
console.log(this.state.wikidata.claims.P435[0].mainsnak.datavalue.value)
|
||||||
axios.get(musicbrainzBaseUrl+"/work",{
|
axios.get(`${musicbrainzBaseUrl}/work/${this.state.wikidata.claims.P435[0].mainsnak.datavalue.value}`, { // get musicbrainz info
|
||||||
params:{
|
params: {
|
||||||
'query':this.props.title,
|
'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,
|
'limit': 1,
|
||||||
'offset': 0,
|
'offset': 0,
|
||||||
'fmt':'json'
|
'fmt': 'json'
|
||||||
}
|
}
|
||||||
}).then(musicbrainzRes=> {
|
}).then(musicbrainzRes => {
|
||||||
// console.log(musicbrainzRes.data.works[0],musicbrainzRes.data.works[0].id)
|
|
||||||
this.setState({ musicbrainz: musicbrainzRes.data.works[0] });
|
this.setState({ musicbrainz: musicbrainzRes.data.works[0] });
|
||||||
axios.all([
|
axios.all([
|
||||||
axios.get(wdk.getReverseClaims('P435', musicbrainzRes.data.works[0].id)), // P435 is musicbrainz id
|
axios.get(wdk.getReverseClaims('P435', musicbrainzRes.data.works[0].id)), // P435 is musicbrainz id
|
||||||
axios.get(musicbrainzBaseUrl+"/work/"+musicbrainzRes.data.works[0].id,{ //
|
axios.get(`${musicbrainzBaseUrl}/work/${musicbrainzRes.data.works[0].id}`, { // get musicbrainz info
|
||||||
params:{
|
params: {
|
||||||
'inc':'url-rels',
|
'inc': 'artist-rels url-rels',
|
||||||
'fmt':'json'
|
'fmt': 'json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
]).then(
|
]).then(
|
||||||
axios.spread((wikidataP435Res,musicbrainzWorkRes) => {
|
axios.spread((wikidataP435Res, musicbrainzWorkRes) => {
|
||||||
// console.info(wikidataP435Res.data,musicbrainzWorkRes.data)
|
if (wikidataP435Res.data.results.bindings.length) // found a match
|
||||||
if(wikidataP435Res.data.results.bindings.length) // found a match
|
|
||||||
this.getWikidataPage(wdk.simplify.sparqlResults(wikidataP435Res.data)); // set the result in the state
|
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 a = musicbrainzWorkRes.data.relations.find(currentRel => currentRel.type === "wikidata");
|
||||||
let wikidataEntityRegEx = new RegExp("[^/]+$"); // match last part of url https://regex101.com/r/0wCQHY/1
|
let wikidataEntityRegEx = new RegExp("[^/]+$"); // match last part of url https://regex101.com/r/0wCQHY/1
|
||||||
this.getWikidataPage(wikidataEntityRegEx.exec(a.url.resource));
|
this.getWikidataPage(wikidataEntityRegEx.exec(a.url.resource)).then(() => this.setState({ isLoaded: true }));
|
||||||
}
|
}
|
||||||
else{ // oof
|
else { // oof
|
||||||
wikijs().find(this.props.title).then(data=>console.log('asd',data)) // find by props.title
|
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) {
|
// componentWillReceiveProps(nextProps) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
@@ -122,50 +135,62 @@ class Wikipedia extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { wikidata, wikipedia, musicbrainz, error, isLoaded } = this.state;
|
const { wikidata, wikipedia, musicbrainz, error, isLoaded } = this.state;
|
||||||
|
const ISO_8601toYYYY = this.ISO_8601toYYYY;
|
||||||
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) {
|
||||||
return <React.Fragment>Loading...</React.Fragment>;
|
return <React.Fragment>Loading...</React.Fragment>;
|
||||||
} else {
|
} else {
|
||||||
let keys = {wikipedia : Object.keys(this.state.wikipedia[0].general),
|
let keys = {
|
||||||
wikidata :Object.keys(this.state.wikidata.claims)}
|
wikipedia: Object.keys(this.state.wikipedia.info),
|
||||||
|
wikidata: Object.keys(this.state.wikidata.claims)
|
||||||
|
}
|
||||||
return (
|
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">
|
<Table striped bordered hover size="sm">
|
||||||
<tbody>
|
<tbody>
|
||||||
{
|
{
|
||||||
keys.wikipedia.map(key => (
|
keys.wikipedia.map(key => (
|
||||||
<tr>
|
<tr>
|
||||||
<td>{key}</td>
|
<td>{key}</td>
|
||||||
<td> {wikipedia[0].general[key].toLocaleString()}</td>
|
<td>{wikipedia.info[key].toLocaleString()}</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
keys.wikidata.map(key => (
|
keys.wikidata.map(key => (
|
||||||
<tr>
|
<tr>
|
||||||
<td>{key}</td>
|
<td>{`${key} - ${wikidata.claims[key][0].mainsnak.datatype}`}</td>
|
||||||
<td> {wikidata.claims[key][0].mainsnak.datavalue.value.toLocaleString()}</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>
|
</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>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
// </React.Fragment>
|
);
|
||||||
// </Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user