Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add size below add to ipfs button #53

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/models/video.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface VideoInfo {
refs: string[]
meta: any
reflink: string
size?: number
}

export interface VideoResolutionProfile {
Expand Down
201 changes: 101 additions & 100 deletions src/renderer/services/accountServices/permalinkToVideoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,118 +5,119 @@ import PromiseIPC from 'electron-promise-ipc'
export async function permalinkToVideoInfo(reflink, options: any = {}): Promise<VideoInfo> {
if (!reflink) return undefined

if (!(reflink instanceof RefLink)) {
reflink = RefLink.parse(reflink)
}
if (!options.type) {
options.type == '*'
}
if (!(reflink instanceof RefLink)) {
reflink = RefLink.parse(reflink)
}
if (!options.type) {
options.type == '*'
}

const postContent = await PromiseIPC.send('distiller.getContent', reflink.toString())
console.log('postContent', postContent)
const post_content = postContent.json_content
console.log('post_content', post_content)
if (!post_content) {
throw new Error('Invalid post content. Empty record')
}
switch (reflink.source.value) {
case 'hive': {
const json_metadata = post_content.json_metadata
console.log('json_metadata', json_metadata)
if (!(json_metadata.app && options.type === 'video')) {
if (json_metadata.type) {
if (!json_metadata.type.includes('3speak/video')) {
throw new Error('Invalid post content. Not a video')
const postContent = await PromiseIPC.send('distiller.getContent', reflink.toString())
console.log('postContent', postContent)
const post_content = postContent.json_content
console.log('post_content', post_content)
if (!post_content) {
throw new Error('Invalid post content. Empty record')
}
switch (reflink.source.value) {
case 'hive': {
const json_metadata = post_content.json_metadata
console.log('json_metadata', json_metadata)
const size = json_metadata.video.info.filesize
if (!(json_metadata.app && options.type === 'video')) {
if (json_metadata.type) {
if (!json_metadata.type.includes('3speak/video')) {
throw new Error('Invalid post content. Not a video')
}
}
//throw new Error("Invalid post content. Not a video");
}
const sources: VideoSource[] = []
let title
let description
let duration
if (json_metadata.video.info.sourceMap[1]) {
console.log('json_metadata.video.info.sourceMap', json_metadata.video.info.sourceMap)
console.log('sources', sources)
console.log('json_metadata', json_metadata)
sources.push(...json_metadata.video.info.sourceMap)
return {
sources,
creation: new Date(post_content.created + 'Z').toISOString(),
title: post_content.title,
description: post_content.body,
tags: json_metadata.tags,
refs: [`hive:${post_content.author}:${post_content.permlink}`], //Reserved for future use when multi account system support is added.
meta: {
duration: json_metadata.duration,
}, //Reserved for future use.
reflink: `hive:${post_content.author}:${post_content.permlink}`,
size,
}
}
try {
const video_info = json_metadata.video.info
const video_content = json_metadata.video.content
description = video_content.description
title = video_info.title
duration = video_info.duration
console.log('video_info', video_info)
console.log('video_info.file', video_info.file)
console.log('video_info.ipfs', video_info.ipfs)
console.log('video_info.ipfsThumbnail', video_info.ipfsThumbnail)
const urls = []
if (video_info.ipfs != null && video_info.ipfs) {
urls.push(`ipfs://${video_info.ipfs}`)
}
if (video_info.ipfsThumbnail != null && video_info.ipfsThumbnail) {
sources.push({
type: 'thumbnail',
url: `ipfs://${video_info.ipfsThumbnail}`,
})
} else if (video_info.sourceMap[0].url) {
console.log('video_info.sourceMap[0].url', video_info.sourceMap[0].url)
sources.push({
type: 'thumbnail',
url: `${video_info.sourceMap[0].url}`,
})
}
if (video_info.file) {
urls.push(`https://threespeakvideo.b-cdn.net/${reflink.permlink}/${video_info.file}`)
} else {
urls.push(`https://threespeakvideo.b-cdn.net/${reflink.permlink}/default.m3u8`)
}

for (const url of urls) {
sources.push({
type: 'video',
url,
/**
* Reserved if a different player must be used on per format basis.
*
* If multi-resolution support is added in the future continue to use the url/format scheme.
* url should link to neccessary metadata.
*/
format: url.split('.').slice(-1)[0],
})
}
} catch (ex) {
title = post_content.title
description = post_content.body
}
//throw new Error("Invalid post content. Not a video");
}
const sources: VideoSource[] = []
let title
let description
let duration
if (json_metadata.video.info.sourceMap[1]) {
console.log('json_metadata.video.info.sourceMap', json_metadata.video.info.sourceMap)
console.log('sources', sources)
console.log('json_metadata', json_metadata)
sources.push(...json_metadata.video.info.sourceMap)
return {
sources,
creation: new Date(post_content.created + 'Z').toISOString(),
title: post_content.title,
description: post_content.body,
title,
description,
tags: json_metadata.tags,
refs: [`hive:${post_content.author}:${post_content.permlink}`], //Reserved for future use when multi account system support is added.
meta: {
duration: json_metadata.duration,
}, //Reserved for future use.
meta: { duration }, //Reserved for future use.
reflink: `hive:${post_content.author}:${post_content.permlink}`,
}
}
try {
const video_info = json_metadata.video.info
const video_content = json_metadata.video.content
description = video_content.description
title = video_info.title
duration = video_info.duration
console.log("video_info", video_info)
console.log("video_info.file", video_info.file)
console.log("video_info.ipfs", video_info.ipfs)
console.log("video_info.ipfsThumbnail", video_info.ipfsThumbnail)
const urls = []
if (video_info.ipfs != null && video_info.ipfs) {
urls.push(`ipfs://${video_info.ipfs}`)
}
if (video_info.ipfsThumbnail != null && video_info.ipfsThumbnail) {
sources.push({
type: 'thumbnail',
url: `ipfs://${video_info.ipfsThumbnail}`,
})
}else if (video_info.sourceMap[0].url) {
console.log("video_info.sourceMap[0].url", video_info.sourceMap[0].url)
sources.push({
type: 'thumbnail',
url: `${video_info.sourceMap[0].url}`,
})
}
if (video_info.file) {
urls.push(`https://threespeakvideo.b-cdn.net/${reflink.permlink}/${video_info.file}`)
}else {
urls.push(`https://threespeakvideo.b-cdn.net/${reflink.permlink}/default.m3u8`)
}

for (const url of urls) {
sources.push({
type: 'video',
url,
/**
* Reserved if a different player must be used on per format basis.
*
* If multi-resolution support is added in the future continue to use the url/format scheme.
* url should link to neccessary metadata.
*/
format: url.split('.').slice(-1)[0],
})
}

} catch (ex) {
title = post_content.title
description = post_content.body
}
console.log('sources', sources)
return {
sources,
creation: new Date(post_content.created + 'Z').toISOString(),
title,
description,
tags: json_metadata.tags,
refs: [`hive:${post_content.author}:${post_content.permlink}`], //Reserved for future use when multi account system support is added.
meta: { duration }, //Reserved for future use.
reflink: `hive:${post_content.author}:${post_content.permlink}`,
default: {
throw new Error('Unknown account provider')
}
}
default: {
throw new Error('Unknown account provider')
}
}
}
47 changes: 24 additions & 23 deletions src/renderer/views/WatchView/WatchViewContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export const WatchViewContent = (props: any) => {
Finder,
} = props

function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes'

const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']

const i = Math.floor(Math.log(bytes) / Math.log(k))

return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
}

return (
<div>
{loaded ? (
Expand Down Expand Up @@ -86,31 +98,20 @@ export const WatchViewContent = (props: any) => {
<div className="float-right">
<Row>
<FollowWidget reflink={reflink} />
<a
target="_blank"
style={{ marginRight: '5px', marginLeft: '5px' }}
className="btn btn-light btn-sm"
onClick={PinLocally}
>
<FaDownload /> Download to IPFS node
</a>
<a
target="_blank"
style={{ marginRight: '5px' }}
className="btn btn-light btn-sm"
href={(() => {
const videoSource = Finder.one.in(videoInfo.sources).with({
format: 'mp4',
})
if (videoSource) {
return videoSource.url
}
})()}
>
<FaDownload /> Download
</a>
<div style={{ textAlign: 'center' }}>
<a
target="_blank"
style={{ marginRight: '5px', marginLeft: '5px' }}
className="btn btn-light btn-sm"
onClick={PinLocally}
>
<FaDownload /> Download to IPFS node
</a>
<div>{formatBytes(videoInfo.size)}</div>
</div>
</Row>
</div>

<img className="img-fluid" src={profilePictureURL} alt="" />
<p>
<a href={`#/user/${reflinkParsed.source.value}:${reflinkParsed.root}`}>
Expand Down
Loading