Archived
santo stefano
This commit is contained in:
+151
-188
@@ -1,213 +1,176 @@
|
||||
import React, { Component } from 'react';
|
||||
// import PropTypes from 'prop-types';
|
||||
import Wikipedia from './areainfo/Wikipedia';
|
||||
import {Col, Tabs, Tab, ListGroup, ListGroupItem} from 'react-bootstrap';
|
||||
import { Tabs, Tab, Table } from 'react-bootstrap';
|
||||
import axios from 'axios';
|
||||
import Linkify from "react-linkify";
|
||||
import Card from "react-bootstrap/lib/Card";
|
||||
const ytclear = require('@c0b41/ytclear');
|
||||
import moment from 'moment';
|
||||
import momentDurationFormat from 'moment-duration-format';
|
||||
import './css/VideoInfo.scss';
|
||||
|
||||
class VideoInfo extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state={
|
||||
error: null,
|
||||
isLoaded: false,
|
||||
VideoDetails: {},
|
||||
videoId: '0J2QdDbelmY',
|
||||
comments : []
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
if(this.props.match.params.id){
|
||||
if(this.props.match.params.id === this.state.videoId){}
|
||||
else{
|
||||
this.setState({videoId: this.props.match.params.id});
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
error: null,
|
||||
isLoaded: false,
|
||||
VideoDetails: {},
|
||||
videoId: '0J2QdDbelmY',
|
||||
comments: []
|
||||
};
|
||||
this.momentDuration = this.momentDuration.bind(this);
|
||||
this.ISO_8601parse = this.ISO_8601parse.bind(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos', {
|
||||
params: {
|
||||
'part': 'snippet,contentDetails,statistics,topicDetails',
|
||||
'id': this.state.videoId,
|
||||
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
||||
}
|
||||
}).then(response => {
|
||||
this.setState({
|
||||
VideoDetails: response.data.items,
|
||||
others: {
|
||||
artist: ytclear(response.data.items[0].snippet.title).split('-')[0],
|
||||
title: ytclear(response.data.items[0].snippet.title).split('-')[1]
|
||||
},
|
||||
isLoaded: true});
|
||||
}, error => {
|
||||
console.error(error);
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
error
|
||||
});
|
||||
});
|
||||
|
||||
//Richiesta per ottenere i commenti del video
|
||||
axios.get('https://www.googleapis.com/youtube/v3/commentThreads', {
|
||||
params: {
|
||||
'part': 'snippet',
|
||||
'videoId': this.state.videoId, //Da sostituire con variabile
|
||||
'order': 'relevance',
|
||||
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
||||
}
|
||||
}).then(
|
||||
response => {
|
||||
this.setState({
|
||||
comments: response.data.items,
|
||||
});
|
||||
},
|
||||
error => {
|
||||
console.error(error);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// componentWillReceiveProps(nextProps) {
|
||||
|
||||
// }
|
||||
|
||||
// shouldComponentUpdate(nextProps, nextState) {
|
||||
|
||||
// }
|
||||
|
||||
componentWillUpdate(nextProps, nextState) {
|
||||
// console.info('nextProps',nextProps);
|
||||
// console.info('nextState',nextState);
|
||||
if(nextProps.match.params.id === this.state.videoId){}
|
||||
else if( nextProps.match.params.id){
|
||||
this.setState({videoId: nextProps.match.params.id});
|
||||
momentDuration(duration) {
|
||||
return moment.duration(duration).format('hh:mm:ss');
|
||||
}
|
||||
ISO_8601parse(a) {
|
||||
return moment(a, moment.ISO_8601).format('ddd, DD/MM/YYYY hh:mm:ss');
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
// console.info('prevProps',prevProps);
|
||||
// console.info('prevState',prevState);
|
||||
}
|
||||
|
||||
// componentWillUnmount() {
|
||||
|
||||
// }
|
||||
componentDidMount() {
|
||||
console.log('didmount', this.state.videoId)
|
||||
axios.all([
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos', { //Richiesta per tutte le info sul video
|
||||
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
|
||||
params: {
|
||||
'part': 'snippet',
|
||||
'videoId': this.state.videoId,
|
||||
'order': 'relevance',
|
||||
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
||||
}
|
||||
})])
|
||||
.then(axios.spread((videosResponse, commentThreadResponse) => {
|
||||
this.setState({
|
||||
VideoDetails: videosResponse.data.items[0],
|
||||
comments: commentThreadResponse.data.items,
|
||||
isLoaded: true
|
||||
});
|
||||
}), error => {
|
||||
console.error(error);
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
error
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { error, isLoaded, VideoDetails } = this.state;
|
||||
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>
|
||||
<Col className='border border-dark' lg={{span:7}} style={{overflow: 'auto',overflowY : 'scroll'}}>
|
||||
{/* codice per tabs reccomenders */}
|
||||
<Tabs defaultActiveKey={1} id="tabs" animation={0}>
|
||||
<Tab eventKey={1} title="Video">
|
||||
<div>
|
||||
{this.state.VideoDetails.map(function(item,index){
|
||||
return(
|
||||
<div key={index}>
|
||||
<h1 style={{margin : '1rem'}}>{item.snippet.title}</h1>
|
||||
<ListGroup style = {{display : 'inline-block',marginLeft : '2rem',marginTop : '1rem',maxWidth: ' 50rem'}}>
|
||||
<ListGroupItem><h5>ID Video</h5>{item.id}</ListGroupItem>
|
||||
<ListGroupItem><h5>Publish Time</h5>{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);
|
||||
})}
|
||||
</ListGroupItem>
|
||||
<ListGroupItem><h5>Channel Name</h5>{item.snippet.channelTitle}</ListGroupItem>
|
||||
<ListGroupItem><h5>Description</h5><Linkify>{item.snippet.description}</Linkify></ListGroupItem>
|
||||
<ListGroupItem><h5>Tags</h5>{item.snippet.tags.map(function(element,index){
|
||||
return(
|
||||
<span key={index} style={{margin : '0.5rem',textDecoration : 'underline'}}>{element}</span>
|
||||
)
|
||||
})}</ListGroupItem>
|
||||
</ListGroup>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
</Tab>
|
||||
<Tab eventKey={2} title="Tecnical Informations" >
|
||||
<div>
|
||||
{this.state.VideoDetails.map(function (item,index) {
|
||||
return(
|
||||
<div key={index}>
|
||||
<h1 style={{margin : '1rem'}}>{item.snippet.title}</h1>
|
||||
<ListGroup style = {{display : 'inline-block',marginLeft : '2rem',marginTop : '1rem'}}>
|
||||
<ListGroupItem><h5>Duration</h5>{item.contentDetails.duration.replace(/(PT(\d+)H(\d+)M(\d+)S)|(PT(\d+)M(\d+)S)/,function(match,p1,p2,p3,p4,p5,p6,p7){
|
||||
if(p1) return(p2+':'+p3+':'+p4);
|
||||
else return(p6+':'+p7);})}
|
||||
</ListGroupItem>
|
||||
<ListGroupItem><h5>Definition</h5>{item.contentDetails.definition}</ListGroupItem>
|
||||
<ListGroupItem><h5>Dimension</h5>{item.contentDetails.dimension}</ListGroupItem>
|
||||
<ListGroupItem><h5>Views</h5>{item.statistics.viewCount}</ListGroupItem>
|
||||
<ListGroupItem><h5>Likes</h5>{item.statistics.likeCount}</ListGroupItem>
|
||||
<ListGroupItem><h5>Dislikes</h5>{item.statistics.dislikeCount}</ListGroupItem>
|
||||
</ListGroup>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</Tab>
|
||||
<Tab eventKey={3} title="Comment">
|
||||
<ul>
|
||||
{this.state.comments.map(function (item,index) {
|
||||
return(
|
||||
<div key={index}>
|
||||
<Card style = {{width: '40rem',fontSize : 'medium',margin : '1em',borderRadius : '1rem'}}>
|
||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if (!(prevState.videoId === this.state.videoId))
|
||||
axios.all([
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos', { //Richiesta per tutte le info sul video
|
||||
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
|
||||
params: {
|
||||
'part': 'snippet',
|
||||
'videoId': this.state.videoId,
|
||||
'order': 'relevance',
|
||||
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
||||
}
|
||||
})])
|
||||
.then(axios.spread((videosResponse, commentThreadResponse) => {
|
||||
this.setState({
|
||||
VideoDetails: videosResponse.data.items[0],
|
||||
comments: commentThreadResponse.data.items,
|
||||
isLoaded: true
|
||||
});
|
||||
}), error => {
|
||||
console.error(error);
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
error
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
console.log(nextProps)
|
||||
if (nextProps.match.params.id && !(nextProps.match.params.id === this.state.videoId)) {
|
||||
this.setState({ videoId: nextProps.match.params.id })
|
||||
} // mindfuck
|
||||
}
|
||||
|
||||
render() {
|
||||
const { error, isLoaded, VideoDetails, comments } = this.state;
|
||||
const momentDuration = this.momentDuration; // bind momentDuration in render to the actual method
|
||||
const ISO_8601parse = this.ISO_8601parse; // bind momentDuration in render to the actual method
|
||||
if (error) {
|
||||
return (
|
||||
<span className="text-white">
|
||||
Error: {error.message} -- Cannot get {error.config.url}
|
||||
</span>
|
||||
);
|
||||
} else if (!isLoaded) {
|
||||
return <span className="text-white">Loading...</span>;
|
||||
} else {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<span class="h5 text-white">{VideoDetails.snippet.title}</span>
|
||||
<Tabs defaultActiveKey="video" id="tabs">
|
||||
<Tab className="text-white" eventKey="video" title="Video">
|
||||
<p>
|
||||
<b>ID Video: </b>{VideoDetails.id}<br />
|
||||
<b>Published: </b>{ISO_8601parse(VideoDetails.snippet.publishedAt)}<br />
|
||||
<b>Channel name: </b>{VideoDetails.snippet.channelTitle}<br />
|
||||
<b>Description: </b><Linkify>{VideoDetails.snippet.description}</Linkify><br />
|
||||
<b>Tags: </b>{VideoDetails.snippet.tags ?
|
||||
VideoDetails.snippet.tags.map(tag => (<span>{tag}</span>)) : ""}
|
||||
{/* tags should be links */}
|
||||
</p>
|
||||
</Tab>
|
||||
<Tab className="text-white" eventKey="techinfo" title="Tecnical Informations">
|
||||
<p><b>Duration: </b>{momentDuration(VideoDetails.contentDetails.duration)}<br />
|
||||
<b>Definition: </b> {VideoDetails.contentDetails.definition}<br />
|
||||
<b>Dimension: </b> {VideoDetails.contentDetails.dimension}<br />
|
||||
<b>Views: </b> {VideoDetails.statistics.viewCount}<br />
|
||||
<b>Likes: </b> {VideoDetails.statistics.likeCount}{String.fromCodePoint(0x1F44D)}<br />
|
||||
<b>Dislikes: </b> {VideoDetails.statistics.dislikeCount}{String.fromCodePoint(0x1F44E)}
|
||||
</p>
|
||||
</Tab>
|
||||
<Tab eventKey="comments" title="Comment">
|
||||
{comments.map(function (comment, index) {
|
||||
return (
|
||||
<Card key={index} className="my-1">
|
||||
<Card.Body>
|
||||
<Card.Title><Card.Img src={item.snippet.topLevelComment.snippet.authorProfileImageUrl} style={{width : '5rem', height : '5rem',padding : '1rem'}} />{item.snippet.topLevelComment.snippet.authorDisplayName}</Card.Title>
|
||||
<Card.Title>
|
||||
<Card.Img src={comment.snippet.topLevelComment.snippet.authorProfileImageUrl} style={{ width: '3rem', height: '3rem' }} />
|
||||
{comment.snippet.topLevelComment.snippet.authorDisplayName}
|
||||
</Card.Title>
|
||||
<Card.Text>
|
||||
<Linkify>
|
||||
{item.snippet.topLevelComment.snippet.textDisplay}
|
||||
{comment.snippet.topLevelComment.snippet.textOriginal}
|
||||
</Linkify>
|
||||
</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</Tab>
|
||||
<Tab eventKey={4} title="Wikipedia">
|
||||
<Wikipedia
|
||||
title={
|
||||
this.props.location.state
|
||||
? this.props.location.state.title
|
||||
: this.state.others.title
|
||||
}
|
||||
artist={
|
||||
this.props.location.state
|
||||
? this.props.location.state.artist
|
||||
: this.state.others.artist
|
||||
}
|
||||
videoId={this.props.match.params.id}
|
||||
/>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</Col>
|
||||
<Col className='border border-dark' lg={{span:4, offset:1}}>
|
||||
<p>2</p>
|
||||
</Col>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
})}
|
||||
</Tab>
|
||||
<Tab eventKey="wikipedia" title="Wikipedia">
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
VideoInfo.propTypes = {
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user