diff --git a/src/VideoInfo.js b/src/VideoInfo.js
index fcb9159..91e687e 100644
--- a/src/VideoInfo.js
+++ b/src/VideoInfo.js
@@ -50,6 +50,9 @@ class VideoInfo extends React.Component {
comments: commentThreadResponse.data.items,
isLoaded: true
});
+ let index = videosResponse.data.items[0].topicDetails.relevantTopicIds.indexOf('/m/04rlf');
+ videosResponse.data.items[0].topicDetails.relevantTopicIds.splice(index, 1);
+ localStorage.setItem('lastTopic',videosResponse.data.items[0].topicDetails.relevantTopicIds);
}), error => {
console.error(error);
this.setState({
diff --git a/src/Wikipedia.js b/src/Wikipedia.js
index ba61a56..743e857 100644
--- a/src/Wikipedia.js
+++ b/src/Wikipedia.js
@@ -38,13 +38,73 @@ class Wikipedia extends Component {
case "P2624": // metrolyrics id
return ({`${value}`})
case "P1651": // youtubeid
- return ( {`${value}`})
+ return ({`${value}`})
case "P2581":
- return ({`${value}`})
- case "P1827":
- return ({`${value}`})
+ return ({value})
+ case "P1827":
+ return ({value})
default:
- return(`${value}`)
+ return (`${value}`);
+ }
+ }
+
+ // P175 = artist
+ // P361 = album
+ getMusicBrainz = (P175, P361, ) => {
+ const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable
+ let artist = this.props.artist || this.props.artist2;
+ let title = this.props.title || this.props.title2;
+ console.log('porcodio', P175.toLowerCase(), artist.trim().toLowerCase(), P175.toLowerCase() === artist.trim().toLowerCase())
+ if (P175.toLowerCase() === artist.trim().toLowerCase()) {
+ axios
+ .get(`https://musicbrainz.org/ws/2/recording`, {
+ params: {
+ 'query': `${title.trim()} AND artistname:${artist.trim()} AND release:${P361}`,
+ 'limit': 1,
+ 'fmt': 'json'
+ }
+ })
+ .then(resP175EqArtist => {
+ axios
+ .get(`${musicbrainzBaseUrl}/recording/${resP175EqArtist.data.recordings[0].id}`, {
+ params: {
+ 'inc': 'work-rels+artists+releases',
+ 'fmt': 'json'
+ }
+ })
+ .then(resRecordingQuery => {
+ let x = resRecordingQuery.data.relations.map(x => x['target-type'] === 'work' ? x.work.id : "").toString();
+ console.log(x,'resRecordingQuery.data true', resRecordingQuery.data)
+ }, err => { console.error(err) })
+ }
+ , err => console.error(err))
+ }
+ else if (P175.toLowerCase() === title.trim().toLowerCase()) { // video title was title - artist
+ // axios
+ // .get(`${musicbrainzBaseUrl}/release-group/`)
+ // .then(res => { }, err => { })
+ axios
+ .get(`https://musicbrainz.org/ws/2/recording`, {
+ params: {
+ 'query': `"${artist.trim()}" AND artistname:"${title.trim()}"`, //rgid:${res.data.}
+ 'limit': 1,
+ 'fmt': 'json'
+ }
+ })
+ .then(resP175EqTitle => {
+ axios
+ .get(`${musicbrainzBaseUrl}/recording/${resP175EqTitle.data.recordings[0].id}`, {
+ params: {
+ 'inc': 'work-rels+artists+releases',
+ 'fmt': 'json'
+ }
+ })
+ .then(resRecordingQuery => {
+ let x = resRecordingQuery.data.relations.map(x => x['target-type'] === 'work' ? x.work.id : "").toString();
+ console.log(x, 'resRecordingQuery.data false', resRecordingQuery.data)
+ }, err => { console.error(err) })
+ }
+ , err => console.error(err))
}
}
@@ -62,20 +122,24 @@ class Wikipedia extends Component {
.map(x => wikidatatmp.claims[x][0].mainsnak.datavalue.value.id)
.filter(x => typeof x === 'string'), 'en'))
])
- .then(axios.spread((resKey, resQ) => {
- this.setState({
- wikidatakeys: Object.entries(resKey.data.entities),
- wikidataQ: resQ.data.entities,
- isWDataLoaded: true
- })
- }))
+ .then(
+ axios.spread((resKey, resQ) => {
+ this.setState({
+ wikidatakeys: Object.entries(resKey.data.entities),
+ wikidataQ: resQ.data.entities,
+ isWDataLoaded: true
+ })
+ this.getMusicBrainz(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);
+
+ }))
if (wikidatatmp.sitelinks.enwiki)
wikijs()
.page(wikidatatmp.sitelinks.enwiki.title)
- .then(page => Promise.all([page.fullInfo(), page.summary()]))
+ .then(page => Promise.all([page.fullInfo()]))
.then(wikipediaRes => this.setState({
wikipedia: {
- "desc": wikipediaRes[1],
+ // "desc": wikipediaRes[1],
"info": wikipediaRes[0].general
},
wikipediakeys: Object.keys(wikipediaRes[0].general),
@@ -115,46 +179,47 @@ class Wikipedia extends Component {
if (wikidataP1651Res.data.results.bindings.length) { // got a match
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 })
- );
- });
- }
+ /* 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
- axios.get(`${musicbrainzBaseUrl}/work`, {
+ else { //oof -- no P1651 :(
+ // eslint-disable-next-line no-lone-blocks
+ {/* axios.get(`${musicbrainzBaseUrl}/work`, {
params: {
'query': 'undefined' === typeof this.props.title ? ('undefined' === typeof this.props.title2 ? this.props.artist2 : this.props.title2) : this.props.title,
'limit': 1,
@@ -189,16 +254,20 @@ class Wikipedia extends Component {
}
})
)
- })
+ }) */}
+
+
}
- return new Promise ((resolve,reject) => {
- timerId1 = window.setInterval(()=>{
- if((this.state.wikipedia !== 'undefined') && (this.state.wikidataQ !== 'undefined') && (this.state.wikidata !== 'undefined'))
+ return new Promise((resolve, reject) => {
+ timerId1 = window.setInterval(() => {
+ if (this.state.wikidataQ == undefined || this.state.wikidata == undefined) { }
+ else {
resolve({
- artist: this.state.wikipedia.info.artist.toString(),
- 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()
})
- }, 700)
+ }
+ }, 1000)
})
}).then((res) => {
let tmp = JSON.parse(localStorage['currentVideoInfo']);
@@ -208,9 +277,9 @@ class Wikipedia extends Component {
artist: res.artist,
genre: res.genre
}
- localStorage.setItem('currentVideoInfo',JSON.stringify(tmp));
+ localStorage.setItem('currentVideoInfo', JSON.stringify(tmp));
})
- .finally(()=>this.setState({ isLoaded: true }));
+ .finally(() => this.setState({ isLoaded: true }));
}
@@ -233,8 +302,8 @@ class Wikipedia extends Component {
return
| {
typeof wikidata.claims[key[0]][0].mainsnak.datavalue.value === "string" ? // wikidata external
- this.getExternalLink(key[0],wikidata.claims[key[0]][0].mainsnak.datavalue.value) :
+ this.getExternalLink(key[0], wikidata.claims[key[0]][0].mainsnak.datavalue.value) :
typeof wikidata.claims[key[0]][0].mainsnak.datavalue.value.id === "string" ? // wikidata Q
<>
{`${this.state.wikidataQ[wikidata.claims[key[0]][0].mainsnak.datavalue.value.id].labels.en ?
diff --git a/src/index.js b/src/index.js
index ac22ee3..45b6ce9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -18,6 +18,7 @@ localStorage['currentVideoInfo']? function(){}() : localStorage.setItem('current
'artist':'Seven Nation Army',
'genre':'Rock'
}));
+localStorage['lastTopic']? function(){}() : localStorage.setItem('lastTopic','/m/04rlf');
ReactDOM.render( |