2018-12-13 02:18:03 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import Wikipedia from './areainfo/Wikipedia';
|
2018-12-14 17:48:29 +01:00
|
|
|
import { Col, Tabs, Tab,} from 'react-bootstrap';
|
2018-12-13 02:18:03 +01:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import Linkify from "react-linkify";
|
|
|
|
|
import Card from "react-bootstrap/lib/Card";
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
import momentDurationFormat from 'moment-duration-format';
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-12-13 02:18:03 +01:00
|
|
|
class VideoInfo extends Component {
|
2018-11-25 19:45:16 +01:00
|
|
|
constructor(props) {
|
2018-12-13 02:18:03 +01:00
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
error: null,
|
|
|
|
|
isLoaded: false,
|
|
|
|
|
VideoDetails: {},
|
|
|
|
|
videoId: '0J2QdDbelmY',
|
|
|
|
|
comments: []
|
|
|
|
|
};
|
|
|
|
|
this.momentDuration = this.momentDuration.bind(this);
|
|
|
|
|
}
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-12-13 02:18:03 +01:00
|
|
|
momentDuration(duration){
|
|
|
|
|
return moment.duration(duration).format('hh:mm:ss');
|
2018-11-24 01:41:45 +01:00
|
|
|
}
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-11-25 19:45:16 +01:00
|
|
|
componentWillMount() {
|
2018-12-13 02:18:03 +01:00
|
|
|
if (this.props.match.params.id) {
|
|
|
|
|
if (this.props.match.params.id === this.state.videoId) { }
|
|
|
|
|
else {
|
|
|
|
|
this.setState({ videoId: this.props.match.params.id });
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-25 19:45:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-12-13 02:18:03 +01:00
|
|
|
axios.all([
|
2018-12-14 17:48:29 +01:00
|
|
|
axios.get('https://www.googleapis.com/youtube/v3/videos', { //Richiesta per tutte le info sul video
|
2018-12-13 02:18:03 +01:00
|
|
|
params: {
|
|
|
|
|
'part': 'snippet,contentDetails,statistics,topicDetails',
|
|
|
|
|
'id': this.state.videoId,
|
|
|
|
|
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
|
|
|
|
}
|
|
|
|
|
}), axios.get('https://www.googleapis.com/youtube/v3/commentThreads', { //Richiesta per ottenere i commenti del video
|
2018-12-12 19:07:10 +01:00
|
|
|
params: {
|
|
|
|
|
'part': 'snippet',
|
2018-12-14 17:48:29 +01:00
|
|
|
'videoId': this.state.videoId,
|
2018-12-12 19:07:10 +01:00
|
|
|
'order': 'relevance',
|
|
|
|
|
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
|
|
|
|
}
|
2018-12-13 02:18:03 +01:00
|
|
|
})])
|
|
|
|
|
.then(axios.spread((videosResponse, commentThreadResponse) => {
|
2018-12-12 19:07:10 +01:00
|
|
|
this.setState({
|
2018-12-13 02:18:03 +01:00
|
|
|
VideoDetails: videosResponse.data.items,
|
|
|
|
|
comments: commentThreadResponse.data.items,
|
|
|
|
|
isLoaded: true
|
2018-12-12 19:07:10 +01:00
|
|
|
});
|
2018-12-13 02:18:03 +01:00
|
|
|
}), error => {
|
2018-12-12 19:07:10 +01:00
|
|
|
console.error(error);
|
2018-12-13 02:18:03 +01:00
|
|
|
this.setState({
|
|
|
|
|
isLoaded: true,
|
|
|
|
|
error
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-11-25 19:45:16 +01:00
|
|
|
}
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-11-25 19:45:16 +01:00
|
|
|
componentWillUpdate(nextProps, nextState) {
|
2018-12-13 02:18:03 +01:00
|
|
|
if (nextProps.match.params.id === this.state.videoId) { }
|
|
|
|
|
else if (nextProps.match.params.id) {
|
|
|
|
|
this.setState({ videoId: nextProps.match.params.id });
|
|
|
|
|
}
|
2018-11-25 19:45:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-12-13 02:18:03 +01:00
|
|
|
const { error, isLoaded, VideoDetails, comments } = this.state;
|
|
|
|
|
const momentDuration = this.momentDuration; // bind momentDuration in render to the actual method
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
Error: {error.message} -- Cannot get {error.config.url}
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
} else if (!isLoaded) {
|
|
|
|
|
return <React.Fragment>Loading...</React.Fragment>;
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
2018-12-14 17:48:29 +01:00
|
|
|
<Col style={{width:'35rem',height:'35rem',marginTop:'1rem'}}>
|
2018-12-13 02:18:03 +01:00
|
|
|
{/* codice per tabs reccomenders */}
|
|
|
|
|
<Tabs defaultActiveKey={1} id="tabs" animation={0}>
|
2018-12-14 17:48:29 +01:00
|
|
|
<Tab eventKey={1} title="Video" style={{overflow:'auto',overflowY:'scroll',height:'30rem'}}>
|
|
|
|
|
<div style={{color : 'white'}}>
|
|
|
|
|
{this.state.VideoDetails.map(function(item,index){
|
|
|
|
|
return(
|
|
|
|
|
<div key={index}>
|
|
|
|
|
<h5 style={{marginTop : '1rem'}}>{item.snippet.title}</h5>
|
|
|
|
|
<p><b>ID Video :</b> {item.id}<br/>
|
|
|
|
|
<b>Publish Time :</b> {item.snippet.publishedAt.replace(/(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+).000Z/,function(match,p1,p2,p3,p4,p5,p6){
|
|
|
|
|
return(p3+'/'+p2+'/'+p1+' - '+p4+':'+p5+':'+p6);
|
|
|
|
|
})}<br/>
|
|
|
|
|
<b>Channel Name :</b> {item.snippet.channelTitle}<br/>
|
|
|
|
|
<b>Description :</b><br/><Linkify>{item.snippet.description}</Linkify><br/>
|
|
|
|
|
<b>Tags :</b><br/>{item.snippet.tags.map(function(element,index){
|
|
|
|
|
if(index===4)
|
|
|
|
|
return (<br/>);
|
|
|
|
|
return(
|
|
|
|
|
<span key={index} style={{margin : '0.5rem',textDecoration : 'underline'}}>{element}</span>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-12-13 02:18:03 +01:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</Tab>
|
2018-12-14 17:48:29 +01:00
|
|
|
<Tab eventKey={2} title="Tecnical Informations">
|
|
|
|
|
<div style={{color:'white'}}>
|
|
|
|
|
{this.state.VideoDetails.map(function (item,index) {
|
|
|
|
|
return(
|
2018-12-13 02:18:03 +01:00
|
|
|
<div key={index}>
|
2018-12-14 17:48:29 +01:00
|
|
|
<h5 style={{marginTop : '1rem'}}>{item.snippet.title}</h5>
|
|
|
|
|
<p><b>Duration :</b>{ momentDuration(item.contentDetails.duration) }<br/>
|
|
|
|
|
<b>Definition :</b> {item.contentDetails.definition}<br/>
|
|
|
|
|
<b>Dimension :</b> {item.contentDetails.dimension}<br/>
|
|
|
|
|
<b> Views :</b> {item.statistics.viewCount}<br/>
|
|
|
|
|
<b>Likes :</b> {item.statistics.likeCount}<br/>
|
|
|
|
|
<b>Dislikes :</b> {item.statistics.dislikeCount}
|
|
|
|
|
</p>
|
2018-12-13 02:18:03 +01:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</Tab>
|
2018-12-14 17:48:29 +01:00
|
|
|
<Tab eventKey={3} title="Comment" style={{overflow:'auto',overflowY:'scroll',height: '30rem'}}>
|
|
|
|
|
<div>
|
|
|
|
|
{this.state.comments.map(function (item,index) {
|
|
|
|
|
return(
|
2018-12-13 02:18:03 +01:00
|
|
|
<div key={index}>
|
2018-12-14 17:48:29 +01:00
|
|
|
<Card style = {{width: '30rem',fontSize : 'small',marginTop : '0.5rem',marginBottom:'0,5rem',borderRadius : '1rem'}}>
|
2018-12-13 02:18:03 +01:00
|
|
|
<Card.Body>
|
2018-12-14 17:48:29 +01:00
|
|
|
<Card.Title><Card.Img src={item.snippet.topLevelComment.snippet.authorProfileImageUrl} style={{width : '3rem', height : '3rem'}} />{item.snippet.topLevelComment.snippet.authorDisplayName}</Card.Title>
|
2018-12-13 02:18:03 +01:00
|
|
|
<Card.Text>
|
|
|
|
|
<Linkify>
|
|
|
|
|
{item.snippet.topLevelComment.snippet.textDisplay}
|
|
|
|
|
</Linkify>
|
|
|
|
|
</Card.Text>
|
|
|
|
|
</Card.Body>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
})}
|
2018-12-14 17:48:29 +01:00
|
|
|
</div>
|
2018-12-13 02:18:03 +01:00
|
|
|
</Tab>
|
|
|
|
|
<Tab eventKey={4} title="Wikipedia">
|
|
|
|
|
<div>
|
2018-12-12 19:07:10 +01:00
|
|
|
|
2018-12-13 02:18:03 +01:00
|
|
|
</div>
|
|
|
|
|
</Tab>
|
|
|
|
|
</Tabs>
|
|
|
|
|
</Col>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-11-25 19:45:16 +01:00
|
|
|
}
|
2018-12-13 02:18:03 +01:00
|
|
|
}
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-12-13 02:18:03 +01:00
|
|
|
VideoInfo.propTypes = {
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-12-13 02:18:03 +01:00
|
|
|
};
|
2018-11-08 18:22:06 +01:00
|
|
|
|
2018-12-13 02:18:03 +01:00
|
|
|
export default VideoInfo;
|