diff --git a/src/VideoPlayer.js b/src/VideoPlayer.js
index 26f00a0..4849a3a 100644
--- a/src/VideoPlayer.js
+++ b/src/VideoPlayer.js
@@ -19,8 +19,8 @@ class VideoPlayer extends React.Component {
origin//: 'http://site1854.tw.cs.unibo.it'
}
},
- promise1: null,
- promise2: null,
+ promise1: Promise,
+ promise2: Promise,
outsideReject1: null,
outsideReject2: null
};
@@ -65,7 +65,7 @@ class VideoPlayer extends React.Component {
default:
break;
}
- }, 500);
+ }, 1500);
this.setState({ outsideReject2: reject });
})
});
@@ -77,49 +77,49 @@ class VideoPlayer extends React.Component {
promise1: new Promise((resolve, reject) => {
timerId1 = window.setInterval(() => {
if (event.target.getCurrentTime() > 15)
- resolve(event.target.j.videoData.video_id);
- }, 1000);
+ resolve(event.target.getVideoData().video_id);
+ }, 1200);
this.setState({ outsideReject1: reject });
})
});
this.state.promise1
- .then(
- videoIdWatched => {
- // post request to local db
- axios
- .post('http://site1854.tw.cs.unibo.it/videotrack', {
- id: videoIdWatched.toString()
- })
- .then(
- response => console.info(response.data),
- error => this.setState({error})//console.error(error, videoIdWatched.toString())
- );
- // local storage logic for recent reccomender//tmp è il video che devo inserire sulla lista
- let tmp = JSON.parse(localStorage.getItem('lastWatched'))
- let j=tmp.findIndex(el=>el.id.toString()===videoIdWatched.toString())
- if (j<0){
- tmp.push({
- 'id': videoIdWatched.toString(),
- 'lastWatched' : new Date(),
- 'timesWatched' : 1
- });}
- else {
- tmp[j].timesWatched++;
- tmp[j].lastWatched= new Date();
- }
-
- tmp.sort((a, b) => new Date(b.lastWatched).getTime() - new Date(a.lastWatched).getTime());
-
-
-
- localStorage.setItem('lastWatched', JSON.stringify(tmp));
- //.finally(()=>{})
- clearInterval(timerId1);
- },
- error => console.error(error)
- )
-
- .finally(() => this.setState({ promise1: null, outsideReject1: null }));
+ .then(
+ videoIdWatched => {
+ // post request to local db
+ let reason = new URLSearchParams(this.props.location.search).get("ref");
+ axios
+ .post('http://site1854.tw.cs.unibo.it/videotrack', {
+ id: videoIdWatched.toString(),
+ reason: reason || undefined
+ })
+ .then(
+ response => console.info(response.data),
+ error => this.setState({error})//console.error(error, videoIdWatched.toString())
+ );
+ // local storage logic for recent reccomender//tmp è il video che devo inserire sulla lista
+ let tmp = JSON.parse(localStorage.getItem('lastWatched'))
+ let j=tmp.findIndex(el=>el.id.toString()===videoIdWatched.toString())
+ if (j<0){
+ tmp.push({
+ 'id': videoIdWatched.toString(),
+ 'lastWatched' : new Date(),
+ 'timesWatched' : 1
+ });}
+ else {
+ tmp[j].timesWatched++;
+ tmp[j].lastWatched= new Date();
+ }
+ tmp.sort((a, b) => new Date(b.lastWatched).getTime() - new Date(a.lastWatched).getTime());
+
+
+ localStorage.setItem('lastWatched', JSON.stringify(tmp));
+ //.finally(()=>{})
+ clearInterval(timerId1);
+ return new Promise ((resolve,reject) => resolve(videoIdWatched))
+ },
+ error => console.error(error)
+ )
+ .finally((id) => this.setState({ promise1: null, outsideReject1: null }));
break;
case 5:
if (this.state.promise1)
diff --git a/src/Wikipedia.js b/src/Wikipedia.js
index cdc4326..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/reccomenders/fvitali.js b/src/reccomenders/fvitali.js
index eb8afb7..2ee9c7f 100644
--- a/src/reccomenders/fvitali.js
+++ b/src/reccomenders/fvitali.js
@@ -111,6 +111,33 @@ class fvitali extends React.Component {
);
+ // }else{
+ // return(
+ //
{item.name}+ //{item.lastSelected} + //Reccomender: fvitali + // |