import React, { useEffect } from 'react' import Typography from '@material-ui/core/Typography' import { Button, ButtonGroup, Grid, List, ListItem } from '@material-ui/core' import CachedIcon from '@material-ui/icons/Cached' import LinearProgress from '@material-ui/core/LinearProgress'; import { getPeerString, humanizeSize } from '../utils/Utils' import { playlistTorrHost, streamHost } from '../utils/Hosts' import DialogTitle from '@material-ui/core/DialogTitle' import DialogContent from '@material-ui/core/DialogContent' const style = { width100: { width: '100%', }, width80: { width: '80%', }, poster: { display: 'flex', flexDirection: 'row', borderRadius:'5px', }, } export default function DialogTorrentInfo(props) { const [torrent, setTorrent] = React.useState(props.torrent) const [progress, setProgress] = React.useState(-1) useEffect(() => { setTorrent(props.torrent) if(torrent.stat==2) setProgress(torrent.preloaded_bytes * 100 / torrent.preload_size) }, [props.torrent, props.open]) return (
{torrent.poster && } {torrent.title} {torrent.name && torrent.name !== torrent.title && ' | ' + torrent.name} Peers: {getPeerString(torrent)}
Loaded: {getPreload(torrent)}
Speed: {humanizeSize(torrent.download_speed)}
Status: {torrent.stat_string}
{torrent.stat==2 && }
{getPlayableFile(torrent) && getPlayableFile(torrent).map((file) => ( ))}
) } function getPlayableFile(torrent){ if (!torrent || !torrent.file_stats) return null return torrent.file_stats.filter(file => extPlayable.includes(getExt(file.path))) } function getExt(filename){ const ext = filename.split('.').pop() if (ext == filename) return '' return ext.toLowerCase() } function getPreload(torrent) { if (torrent.preloaded_bytes > 0 && torrent.preload_size > 0 && torrent.preloaded_bytes < torrent.preload_size) { let progress = ((torrent.preloaded_bytes * 100) / torrent.preload_size).toFixed(2) return humanizeSize(torrent.preloaded_bytes) + ' / ' + humanizeSize(torrent.preload_size) + ' ' + progress + '%' } if (!torrent.preloaded_bytes) return humanizeSize(0) return humanizeSize(torrent.preloaded_bytes) } const extPlayable = [ // video "3g2", "3gp", "aaf", "asf", "avchd", "avi", "drc", "flv", "iso", "m2v", "m2ts", "m4p", "m4v", "mkv", "mng", "mov", "mp2", "mp4", "mpe", "mpeg", "mpg", "mpv", "mxf", "nsv", "ogg", "ogv", "ts", "qt", "rm", "rmvb", "roq", "svi", "vob", "webm", "wmv", "yuv", // audio "aac", "aiff", "ape", "au", "flac", "gsm", "it", "m3u", "m4a", "mid", "mod", "mp3", "mpa", "pls", "ra", "s3m", "sid", "wav", "wma", "xm" ]