Archived
wikipedia finito
This commit is contained in:
+51
-105
@@ -6,6 +6,7 @@ import axios from 'axios';
|
|||||||
import { Table, Col } from 'react-bootstrap';
|
import { Table, Col } from 'react-bootstrap';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import "./css/Wikipedia.css"
|
import "./css/Wikipedia.css"
|
||||||
|
/*eslint no-console: ["error", { allow: ["warn", "error"] }] */
|
||||||
|
|
||||||
class Wikipedia extends Component {
|
class Wikipedia extends Component {
|
||||||
|
|
||||||
@@ -48,18 +49,17 @@ class Wikipedia extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// P175 = artist
|
|
||||||
// P361 = album
|
|
||||||
getMusicBrainz = (P175, P361, ) => {
|
getMusicBrainzFromWData = (P175, P435=undefined) => { // P175 = artist P435 = workid
|
||||||
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
|
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
|
||||||
let artist = this.props.artist || this.props.artist2;
|
let artist = this.props.artist || this.props.artist2;
|
||||||
let title = this.props.title || this.props.title2;
|
let title = this.props.title || this.props.title2;
|
||||||
console.log('accipicchia', P175.toLowerCase(), artist.trim().toLowerCase(), P175.toLowerCase() === artist.trim().toLowerCase())
|
|
||||||
if (P175.toLowerCase() === artist.trim().toLowerCase()) {
|
if (P175.toLowerCase() === artist.trim().toLowerCase()) {
|
||||||
axios
|
axios
|
||||||
.get(`https://musicbrainz.org/ws/2/recording`, {
|
.get(`https://musicbrainz.org/ws/2/recording`, {
|
||||||
params: {
|
params: {
|
||||||
'query': `${title.trim()} AND artistname:${artist.trim()} AND release:${P361}`,
|
'query': `${title.trim()} AND artistname:${artist.trim()}`, //AND release:${P361}
|
||||||
'limit': 1,
|
'limit': 1,
|
||||||
'fmt': 'json'
|
'fmt': 'json'
|
||||||
}
|
}
|
||||||
@@ -73,20 +73,28 @@ class Wikipedia extends Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(resRecordingQuery => {
|
.then(resRecordingQuery => {
|
||||||
let x = resRecordingQuery.data.relations.map(x => x['target-type'] === 'work' ? x.work.id : "").toString();
|
let musicbrainzWorkId = resRecordingQuery.data.relations.map(x => x['target-type'] === 'work' ? x.work.id : "").toString() || P435;
|
||||||
console.log(x, 'resRecordingQuery.data true', resRecordingQuery.data)
|
axios.get(`${musicbrainzBaseUrl}/work/${musicbrainzWorkId}`, {
|
||||||
|
params:{
|
||||||
|
'inc': 'artist-rels url-rels',
|
||||||
|
'limit': 1,
|
||||||
|
'offset': 0,
|
||||||
|
'fmt': 'json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(musicbrainzWorkRes => {
|
||||||
|
this.setState({ musicbrainz: musicbrainzWorkRes.data, isMBLoaded: true })
|
||||||
|
},
|
||||||
|
error => console.error(error))
|
||||||
}, err => { console.error(err) })
|
}, err => { console.error(err) })
|
||||||
}
|
}
|
||||||
, err => console.error(err))
|
, err => console.error(err))
|
||||||
}
|
}
|
||||||
else if (P175.toLowerCase() === title.trim().toLowerCase()) { // video title was title - artist
|
else if (P175.toLowerCase() === title.trim().toLowerCase()) { // video title was title - artist
|
||||||
// axios
|
|
||||||
// .get(`${musicbrainzBaseUrl}/release-group/`)
|
|
||||||
// .then(res => { }, err => { })
|
|
||||||
axios
|
axios
|
||||||
.get(`https://musicbrainz.org/ws/2/recording`, {
|
.get(`https://musicbrainz.org/ws/2/recording`, {
|
||||||
params: {
|
params: {
|
||||||
'query': `"${artist.trim()}" AND artistname:"${title.trim()}"`, //rgid:${res.data.}
|
'query': `"${artist.trim()}" AND artistname:"${title.trim()}"`, //AND release:${P361}
|
||||||
'limit': 1,
|
'limit': 1,
|
||||||
'fmt': 'json'
|
'fmt': 'json'
|
||||||
}
|
}
|
||||||
@@ -100,8 +108,19 @@ class Wikipedia extends Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(resRecordingQuery => {
|
.then(resRecordingQuery => {
|
||||||
let x = resRecordingQuery.data.relations.map(x => x['target-type'] === 'work' ? x.work.id : "").toString();
|
let musicbrainzWorkId = resRecordingQuery.data.relations.map(x => x['target-type'] === 'work' ? x.work.id : "").toString() || P435;
|
||||||
console.log(x, 'resRecordingQuery.data false', resRecordingQuery.data)
|
axios.get(`${musicbrainzBaseUrl}/work/${musicbrainzWorkId}`, {
|
||||||
|
params:{
|
||||||
|
'inc': 'artist-rels url-rels',
|
||||||
|
'limit': 1,
|
||||||
|
'offset': 0,
|
||||||
|
'fmt': 'json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(musicbrainzWorkRes => {
|
||||||
|
this.setState({ musicbrainz: musicbrainzWorkRes.data, isMBLoaded: true })
|
||||||
|
},
|
||||||
|
error => console.error(error))
|
||||||
}, err => { console.error(err) })
|
}, err => { console.error(err) })
|
||||||
}
|
}
|
||||||
, err => console.error(err))
|
, err => console.error(err))
|
||||||
@@ -129,9 +148,8 @@ class Wikipedia extends Component {
|
|||||||
wikidataQ: resQ.data.entities,
|
wikidataQ: resQ.data.entities,
|
||||||
isWDataLoaded: true
|
isWDataLoaded: true
|
||||||
})
|
})
|
||||||
this.getMusicBrainz(resQ.data.entities[wikidatatmp.claims.P175[0].mainsnak.datavalue.value.id].labels.en.value,
|
this.getMusicBrainzFromWData(resQ.data.entities[wikidatatmp.claims.P175[0].mainsnak.datavalue.value.id].labels.en.value,
|
||||||
resQ.data.entities[wikidatatmp.claims.P361[0].mainsnak.datavalue.value.id].labels.en.value);
|
wikidatatmp.claims.P435[0].mainsnak.datavalue.value);
|
||||||
|
|
||||||
}))
|
}))
|
||||||
if (wikidatatmp.sitelinks.enwiki)
|
if (wikidatatmp.sitelinks.enwiki)
|
||||||
wikijs()
|
wikijs()
|
||||||
@@ -146,7 +164,6 @@ class Wikipedia extends Component {
|
|||||||
isWikiLoaded: true
|
isWikiLoaded: true
|
||||||
}))
|
}))
|
||||||
else {
|
else {
|
||||||
console.info('called here')
|
|
||||||
this.findWikiPage();
|
this.findWikiPage();
|
||||||
}
|
}
|
||||||
}, error => console.error(error))
|
}, error => console.error(error))
|
||||||
@@ -157,14 +174,11 @@ class Wikipedia extends Component {
|
|||||||
return wikijs()
|
return wikijs()
|
||||||
.find(wikiquery)
|
.find(wikiquery)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// return Promise.all([res.fullInfo(), res.links(), res.backlinks()]);
|
|
||||||
return Promise.all([res.fullInfo()]);
|
return Promise.all([res.fullInfo()]);
|
||||||
}) // find by props.title (props.artist song)
|
}) // find by props.title (props.artist song)
|
||||||
.then(wikipediaRes => this.setState({
|
.then(wikipediaRes => this.setState({
|
||||||
wikipedia: {
|
wikipedia: {
|
||||||
"info": wikipediaRes[0].general
|
"info": wikipediaRes[0].general
|
||||||
// ,"links": wikipediaRes[1],
|
|
||||||
// "backlinks": wikipediaRes[2]
|
|
||||||
},
|
},
|
||||||
wikipediakeys: Object.keys(wikipediaRes[0].general),
|
wikipediakeys: Object.keys(wikipediaRes[0].general),
|
||||||
isWikiLoaded: true
|
isWikiLoaded: true
|
||||||
@@ -172,100 +186,32 @@ class Wikipedia extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
|
|
||||||
let timerId1;
|
let timerId1;
|
||||||
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
|
||||||
.then(() => {
|
|
||||||
/* if (this.state.wikidata.claims.P435) { // p435 == musicbrainzWorkId
|
|
||||||
axios.get(`${musicbrainzBaseUrl}/work/${this.state.wikidata.claims.P435[0].mainsnak.datavalue.value}`, { // get musicbrainz info
|
|
||||||
params: {
|
|
||||||
'inc': 'artist-rels url-rels',
|
|
||||||
'limit': 15,
|
|
||||||
'offset': 0,
|
|
||||||
'fmt': 'json'
|
|
||||||
}
|
|
||||||
}).then(
|
|
||||||
musicbrainzRes1 =>
|
|
||||||
this.setState({ musicbrainz: musicbrainzRes1.data, isMBLoaded: true })
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {//oof P435 not found in wikidata
|
|
||||||
axios.get(`${musicbrainzBaseUrl}/work`, { // search on mb by wikidata title
|
|
||||||
params: {
|
|
||||||
'query': `work:${this.state.wikidata.labels.en.value}`,
|
|
||||||
'limit': 1,
|
|
||||||
'offset': 0,
|
|
||||||
'fmt': 'json'
|
|
||||||
}
|
|
||||||
}).then(musicbrainzRes2 => {
|
|
||||||
axios.get(`${musicbrainzBaseUrl}/work/${musicbrainzRes2.data.works[0].id}`,
|
|
||||||
{ // get musicbrainz info on track by previous id
|
|
||||||
params: {
|
|
||||||
'inc': 'artist-rels url-rels',
|
|
||||||
'limit': 15,
|
|
||||||
'fmt': 'json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
(musicbrainzWorkRes2) =>
|
|
||||||
this.setState({ musicbrainz: musicbrainzWorkRes2.data, isMBLoaded: true })
|
|
||||||
);
|
|
||||||
});
|
|
||||||
} */
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else { //oof -- no P1651 :(
|
else { //oof -- no P1651 :(
|
||||||
// eslint-disable-next-line no-lone-blocks
|
let title = this.props.title || this.props.title2;
|
||||||
{/* axios.get(`${musicbrainzBaseUrl}/work`, {
|
axios.get(wdk.searchEntities(`${title.trim()}`))
|
||||||
params: {
|
.then(wikidataSearchRes => {
|
||||||
'query': 'undefined' === typeof this.props.title ? ('undefined' === typeof this.props.title2 ? this.props.artist2 : this.props.title2) : this.props.title,
|
this.getWikidataPage(wikidataSearchRes.data.search[0].title)
|
||||||
'limit': 1,
|
})
|
||||||
'offset': 0,
|
|
||||||
'fmt': 'json'
|
|
||||||
}
|
|
||||||
}).then(musicbrainzRes => {
|
|
||||||
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}`, { // get musicbrainz info
|
|
||||||
params: {
|
|
||||||
'inc': 'artist-rels url-rels',
|
|
||||||
'limit': 15,
|
|
||||||
'fmt': 'json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]).then(
|
|
||||||
axios.spread((wikidataP435Res, musicbrainzWorkRes) => {
|
|
||||||
this.setState({
|
|
||||||
musicbrainz: musicbrainzWorkRes.data,
|
|
||||||
isMBLoaded: true
|
|
||||||
});
|
|
||||||
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 wikidataUrl = 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(wikidataUrl.url.resource))
|
|
||||||
}
|
|
||||||
else { // oof
|
|
||||||
this.findWikiPage()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}) */}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
timerId1 = window.setInterval(() => {
|
timerId1 = window.setInterval(() => {
|
||||||
if (this.state.wikidataQ == undefined || this.state.wikidata == undefined) { }
|
if (this.state.wikidataQ == undefined || this.state.wikidata == undefined) { }
|
||||||
else
|
else{
|
||||||
resolve({
|
try {
|
||||||
artist: this.state.wikidataQ[this.state.wikidata.claims["P175"][0].mainsnak.datavalue.value.id].labels.en.value.toString(),
|
resolve({
|
||||||
genre: this.state.wikidataQ[this.state.wikidata.claims["P136"][0].mainsnak.datavalue.value.id].labels.en.value.toString()
|
artist: this.state.wikidataQ[this.state.wikidata.claims["P175"][0].mainsnak.datavalue.value.id].labels.en.value.toString(),
|
||||||
})
|
genre: this.state.wikidataQ[this.state.wikidata.claims["P136"][0].mainsnak.datavalue.value.id].labels.en.value.toString()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
resolve({ artist: null, genre: null })
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
})
|
})
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user