cambiata api key

This commit is contained in:
matteo
2019-02-14 15:03:45 +01:00
parent 407a6c18cc
commit 146e59fbed
10 changed files with 97 additions and 59 deletions
+1 -1
View File
@@ -1 +1 @@
AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg'
+1 -1
View File
@@ -1,5 +1,5 @@
process.env['NODE_ENV'] = 'production'; process.env['NODE_ENV'] = 'production';
process.env.APIKEY = 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'; 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' = 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg';
const express = require('express'); const express = require('express');
const compression = require('compression') const compression = require('compression')
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
+10 -10
View File
@@ -8,8 +8,6 @@ import Card from "react-bootstrap/lib/Card";
import moment from 'moment'; import moment from 'moment';
import momentDurationFormat from 'moment-duration-format'; //eslint-disable-line no-unused-vars import momentDurationFormat from 'moment-duration-format'; //eslint-disable-line no-unused-vars
import './css/VideoInfo.scss'; import './css/VideoInfo.scss';
const ytclear = require('@c0b41/ytclear'); const ytclear = require('@c0b41/ytclear');
class VideoInfo extends React.Component { class VideoInfo extends React.Component {
@@ -79,39 +77,35 @@ class VideoInfo extends React.Component {
}), }),
]).then(axios.spread((responseA1,responseA2)=>{ ]).then(axios.spread((responseA1,responseA2)=>{
console.log(responseA1.data, responseA2.data); console.log(responseA1.data, responseA2.data);
})) }))
}), }),
error => { } error => { }
); );
} }
getInfoComments() { getInfoComments() {
return axios.all([ return axios.all([
axios.get('https://www.googleapis.com/youtube/v3/videos', { //Richiesta per tutte le info sul video axios.get('https://www.googleapis.com/youtube/v3/videos', { //Richiesta per tutte le info sul video
params: { params: {
'part': 'snippet,contentDetails,statistics,topicDetails', 'part': 'snippet,contentDetails,statistics,topicDetails',
'id': this.state.videoId, 'id': this.state.videoId,
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' // process.env.APIKEY in production 'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' // 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' in production
} }
}), axios.get('https://www.googleapis.com/youtube/v3/commentThreads', { //Richiesta per ottenere i commenti del video }), axios.get('https://www.googleapis.com/youtube/v3/commentThreads', { //Richiesta per ottenere i commenti del video
params: { params: {
'part': 'snippet', 'part': 'snippet',
'videoId': this.state.videoId, 'videoId': this.state.videoId,
'order': 'relevance', 'order': 'relevance',
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' // process.env.APIKEY in production 'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' // 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' in production
} }
})]) })])
.then(axios.spread((videosResponse, commentThreadResponse) => { .then(axios.spread((videosResponse, commentThreadResponse) => {
this.isArtistOrTitle(ytclear(videosResponse.data.items[0].snippet.title).split('-')); // this.isArtistOrTitle(ytclear(videosResponse.data.items[0].snippet.title).split('-'));
this.setState({ this.setState({
VideoDetails: videosResponse.data.items[0], VideoDetails: videosResponse.data.items[0],
comments: commentThreadResponse.data.items, comments: commentThreadResponse.data.items,
others: { others: {
artist: null, title2: ytclear(videosResponse.data.items[0].snippet.title).split('-')[1]
title: videosResponse.data.items[0].snippet.title
}, },
isLoaded: true isLoaded: true
}); });
@@ -127,6 +121,11 @@ class VideoInfo extends React.Component {
static getDerivedStateFromProps(nextProps, prevState) { static getDerivedStateFromProps(nextProps, prevState) {
if(nextProps.videoId !== prevState.videoId) if(nextProps.videoId !== prevState.videoId)
return { videoId: nextProps.videoId }; return { videoId: nextProps.videoId };
else if(nextProps.location.state)
return { others: {
artist: nextProps.location.state.artist,
title: nextProps.location.state.title
}}
return null; return null;
} }
componentDidMount() { componentDidMount() {
@@ -208,6 +207,7 @@ class VideoInfo extends React.Component {
<Tab className="text-white" eventKey="wikipedia" title="Wikipedia"> <Tab className="text-white" eventKey="wikipedia" title="Wikipedia">
<Wikipedia <Wikipedia
title={this.state.others.title} title={this.state.others.title}
title2={this.state.others.title2}
artist={this.state.others.artist} artist={this.state.others.artist}
videoId={this.state.videoId} videoId={this.state.videoId}
/> />
+3 -3
View File
@@ -47,7 +47,7 @@ class VideoList extends React.Component {
params: { params: {
part: 'snippet', part: 'snippet',
id: idToLookFor.slice(0, 50).toString(), id: idToLookFor.slice(0, 50).toString(),
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig', // process.env.APIKEY in production key: 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg', // 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' in production
fields: 'items(id,snippet/thumbnails/medium)' fields: 'items(id,snippet/thumbnails/medium)'
} }
}), }),
@@ -56,7 +56,7 @@ class VideoList extends React.Component {
params: { params: {
part: 'snippet', part: 'snippet',
id: idToLookFor.slice(50, 100).toString(), id: idToLookFor.slice(50, 100).toString(),
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig', // process.env.APIKEY in production key: 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg', // 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' in production
fields: 'items(id,snippet/thumbnails/medium)' fields: 'items(id,snippet/thumbnails/medium)'
} }
}), }),
@@ -65,7 +65,7 @@ class VideoList extends React.Component {
params: { params: {
part: 'snippet', part: 'snippet',
id: idToLookFor.slice(100, finalChunk).toString(), id: idToLookFor.slice(100, finalChunk).toString(),
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig', // process.env.APIKEY in production key: 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg', // 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' in production
fields: 'items(id,snippet/thumbnails/medium)' fields: 'items(id,snippet/thumbnails/medium)'
} }
}) })
+9 -7
View File
@@ -17,7 +17,9 @@ class Wikipedia extends Component {
isWikiLoaded: false, isWikiLoaded: false,
isWDataLoaded: false, isWDataLoaded: false,
isMBLoaded: false, isMBLoaded: false,
isLoaded: false isLoaded: false,
wikidatakeys: null,
wikipediakeys: null
}; };
ISO_8601toYYYY(a) { ISO_8601toYYYY(a) {
@@ -64,7 +66,7 @@ class Wikipedia extends Component {
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(() => { .then(() => {
if (this.state.wikidata.claims.P435) { if (this.state.wikidata.claims.P435) { // p435 == musicbrainzWorkId
axios.get(`${musicbrainzBaseUrl}/work/${this.state.wikidata.claims.P435[0].mainsnak.datavalue.value}`, { // get musicbrainz info axios.get(`${musicbrainzBaseUrl}/work/${this.state.wikidata.claims.P435[0].mainsnak.datavalue.value}`, { // get musicbrainz info
params: { params: {
'inc': 'artist-rels url-rels', 'inc': 'artist-rels url-rels',
@@ -105,7 +107,7 @@ class Wikipedia extends Component {
else { //oof else { //oof
axios.get(`${musicbrainzBaseUrl}/work`, { axios.get(`${musicbrainzBaseUrl}/work`, {
params: { params: {
'query': this.state.props.title.trim(), 'query': 'undefined' === typeof this.state.props.title ? this.state.props.title2 : this.state.props.title,
'limit': 1, 'limit': 1,
'offset': 0, 'offset': 0,
'fmt': 'json' 'fmt': 'json'
@@ -131,7 +133,7 @@ class Wikipedia extends Component {
this.getWikidataPage(wikidataEntityRegEx.exec(a.url.resource)) //.then(() => this.setState({ isWikiLoaded: true })); this.getWikidataPage(wikidataEntityRegEx.exec(a.url.resource)) //.then(() => this.setState({ isWikiLoaded: true }));
} }
else { // oof else { // oof
wikijs().find(this.state.props.title).then(data => console.log('asd', data)) // find by props.title wikijs().find('undefined' === typeof this.state.props.title? this.state.props.title2.trim(): this.state.props.title.trim()).then(data => console.log('asd', data)) // find by props.title
} }
}) })
) )
@@ -145,13 +147,13 @@ class Wikipedia extends Component {
return { return {
props: { props: {
videoId: nextProps.videoId, videoId: nextProps.videoId,
artist: nextProps.artist,
title: nextProps.title
}, },
isWikiLoaded: false, isWikiLoaded: false,
isWDataLoaded: false, isWDataLoaded: false,
isMBLoaded: false, isMBLoaded: false,
isLoaded: false isLoaded: false,
wikidatakeys: null,
wikipediakeys: null
}; };
return null return null
} }
+1 -1
View File
@@ -31,7 +31,7 @@ class RecommenderRandom extends Component{
'type' : 'video', //che contiene tutti i generi di musica 'type' : 'video', //che contiene tutti i generi di musica
'maxResults': '21', 'maxResults': '21',
'pageToken' : pageToken, 'pageToken' : pageToken,
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' // process.env.APIKEY in production 'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg'
} }
}).then( }).then(
response => { response => {
+1 -1
View File
@@ -33,7 +33,7 @@ class Related extends Component {
'relatedToVideoId' : this.state.videoId, 'relatedToVideoId' : this.state.videoId,
'type' : 'video', 'type' : 'video',
'maxResults' : '21', 'maxResults' : '21',
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' // process.env.APIKEY in production 'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg'
} }
}).then( }).then(
response => { response => {
+50 -14
View File
@@ -1,10 +1,13 @@
import React from 'react'; import React from 'react';
import axios from 'axios'; import axios from 'axios';
import { Card, Col } from 'react-bootstrap';
class Search extends React.Component { class Search extends React.Component {
state = { state = {
query: '', query: '',
isLoaded: false,
error: null,
res: null res: null
} }
@@ -16,20 +19,12 @@ class Search extends React.Component {
componentDidMount() { componentDidMount() {
console.log('called didmo'); console.log('called didmo');
}
// shouldComponentUpdate(nextProps, nextState) {
// }
componentDidUpdate(prevProps, prevState) {
console.log('called didup');
if (new RegExp("[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]").test(this.state.query.toString())) if (new RegExp("[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]").test(this.state.query.toString()))
axios.get('https://www.googleapis.com/youtube/v3/videos', { axios.get('https://www.googleapis.com/youtube/v3/videos', {
params: { params: {
'part': 'id', 'part': 'id',
'id': this.state.query, 'id': this.state.query,
'key': process.env.APIKEY ? process.env.APIKEY : 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig', 'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg',
'field': 'pageInfo/resultsPerPage' 'field': 'pageInfo/resultsPerPage'
} }
}).then( }).then(
@@ -46,6 +41,38 @@ class Search extends React.Component {
this.youtubeSearch(); this.youtubeSearch();
} }
// shouldComponentUpdate(nextProps, nextState) {
// }
componentDidUpdate(prevProps, prevState) {
console.log('called didup');
if (prevState.query !== this.props.match.params.query)
if (new RegExp("[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]").test(this.state.query.toString()))
axios.get('https://www.googleapis.com/youtube/v3/videos', {
params: {
'part': 'id',
'id': this.state.query,
'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg',
'field': 'pageInfo/resultsPerPage'
}
}).then(
res => {
res.data.pageInfo.resultsPerPage ?
this.props.history.push('/video/' + this.state.query) :
this.youtubeSearch()
},
error => {
console.error(error)
this.setState({
error
})
}
)
else
this.youtubeSearch();
}
// componentWillUnmount() { // componentWillUnmount() {
// } // }
@@ -59,13 +86,14 @@ class Search extends React.Component {
'type': 'video', 'type': 'video',
'maxResults': 30, 'maxResults': 30,
'topicId': '/m/04rlf, /m/02jjt', 'topicId': '/m/04rlf, /m/02jjt',
'key': process.env.APIKEY ? process.env.APIKEY : 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' 'key': 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg'
} }
}).then( }).then(
res => { res => {
console.log(res.data); console.log(res.data);
this.setState({ this.setState({
res: res.data res: res.data,
isLoaded: true
}) })
}, },
error => { console.error(error) } error => { console.error(error) }
@@ -73,12 +101,20 @@ class Search extends React.Component {
} }
render() { render() {
if (this.state.error) {
return <React.Fragment>Error: {this.state.error.message}</React.Fragment>;
} else if (!this.state.isLoaded) {
return <React.Fragment>Loading...</React.Fragment>;
} else {
return ( return (
<div> <Col>
<span>{this.state.query} keyword</span> {this.state.res.data.items.map(item => (<Card></Card>
</div>
))}
</Col>
); );
} }
} }
}
export default Search; export default Search;
+1 -1
View File
@@ -57,7 +57,7 @@ class fvitali extends React.Component {
params: { params: {
part: 'snippet', part: 'snippet',
id: idToLookFor.toString(), id: idToLookFor.toString(),
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig', key: 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg',
fields: 'items(id,snippet/thumbnails/medium,snippet/title)' fields: 'items(id,snippet/thumbnails/medium,snippet/title)'
} }
}) })
+1 -1
View File
@@ -48,7 +48,7 @@ class popGlobaleAssoluta extends React.Component {
params: { params: {
part: 'snippet', part: 'snippet',
id: idToLookFor.toString(), id: idToLookFor.toString(),
key: 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig', key: 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg',
fields: 'items(id,snippet/thumbnails/medium,snippet/title)' fields: 'items(id,snippet/thumbnails/medium,snippet/title)'
} }
}) })