Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
igormuba authored Apr 4, 2023
2 parents 22a5334 + 3ec8662 commit a55a2a9
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/main/core/components/EncoderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ export class EncoderService {
sizes.push(profile.size)
ret.size(profile.size)
this.logger.info(`Profile size ${profile.size}`)
let totalTime
ret.on('codecData', (data) => {
totalTime = parseInt(data.duration.replace(/:/g, ''))
})
ret.on(
'progress',
((progress) => {
this.events.emit('progress', jobInfo.id, progress)
this.statusInfo[jobInfo.id].progress = progress
const time = parseInt(progress.timemark.replace(/:/g, ''))
const percent = (time / totalTime) * 100
this.events.emit('progress', jobInfo.id, { ...progress, percent })
this.statusInfo[jobInfo.id].progress = { ...progress, percent }
}).bind(this),
)
ret.on('end', () => {
Expand Down
95 changes: 95 additions & 0 deletions src/renderer/components/hooks/Feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,78 @@ const TRENDING_COMMUNITY_FEED = gql`
}
`

const LATEST_COMMUNITY_FEED = gql`
query Query($parent_permlink: String) {
latestFeed(parent_permlink: $parent_permlink, limit: 15) {
items {
... on CeramicPost {
stream_id
version_id
parent_id
title
json_metadata
app_metadata
}
... on HivePost {
created_at
updated_at
parent_author
parent_permlink
permlink
author
title
lang
post_type
app
tags
json_metadata
app_metadata
community_ref
three_video
}
__typename
}
}
}
`

const TRENDING_COMMUNITY_FEED = gql`
query Query($parent_permlink: String) {
trendingFeed(parent_permlink: $parent_permlink, limit: 15) {
items {
... on CeramicPost {
stream_id
version_id
parent_id
title
json_metadata
app_metadata
}
... on HivePost {
created_at
updated_at
parent_author
parent_permlink
permlink
author
title
lang
post_type
app
tags
json_metadata
app_metadata
community_ref
three_video
}
__typename
}
}
}
`

function transformGraphqlToNormal(data) {
let blob = []
for (let video of data) {
Expand Down Expand Up @@ -364,3 +436,26 @@ export function useTrendingCommunityFeed(parent_permlink) {
return transformGraphqlToNormal(videos)
}, [videos])
}

export function useLatestCommunityFeed(parent_permlink) {
const { data, loading, error } = useQuery(LATEST_COMMUNITY_FEED, {
client: IndexerClient,
variables: { parent_permlink },
})
const videos = data?.latestFeed?.items || []

return useMemo(() => {
return transformGraphqlToNormal(videos)
}, [videos])
}
export function useTrendingCommunityFeed(parent_permlink) {
const { data, loading, error } = useQuery(TRENDING_COMMUNITY_FEED, {
client: IndexerClient,
variables: { parent_permlink },
})
const videos = data?.latestFeed?.items || []

return useMemo(() => {
return transformGraphqlToNormal(videos)
}, [videos])
}
6 changes: 6 additions & 0 deletions src/renderer/views/CommunityView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export function CommunityView(props: any) {
const [communityInfo, setCommunityInfo] = useState({} as any)
// const [newVideos, setNewVideos] = useState([])
// const [trendingVideos, setTrendingVideos] = useState([])
const newVideos = useLatestCommunityFeed(reflink.root)
const trendingVideos = useTrendingCommunityFeed(reflink.root)
const [backgroundUrl, setBackgroundUrl] = useState(null)

const reflink = useMemo(() => {
return RefLink.parse(props.match.params.reflink)
}, [props.match])
Expand All @@ -25,6 +29,8 @@ export function CommunityView(props: any) {
const [backgroundUrl, setBackgroundUrl] = useState(null)


// for development purpouses:

// for development purpouses:

const generate = async () => {
Expand Down
35 changes: 23 additions & 12 deletions src/renderer/views/UploaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,16 @@ export function UploaderView() {
}

const handleVideoSelect = async (e) => {
const file = e.target.files[0]
setVideoSourceFile(file.path)
setLogData([...logData, `Selected: ${videoInfo.path}`])
let file
if (e.target && e.target.files) {
file = e.target.files[0]
} else if (e.dataTransfer && e.dataTransfer.files) {
file = e.dataTransfer.files[0]
}
if (file) {
setVideoSourceFile(file.path)
setLogData([...logData, `Selected: ${videoInfo.path}`])
}
}

const handleThumbnailSelect = async (e) => {
Expand Down Expand Up @@ -206,7 +213,8 @@ export function UploaderView() {
return
}
setEncodingInProgress(true)
setStartTime(new Date().getTime())
const _startingTime = new Date().getTime()
setStartTime(_startingTime)
setEndTime(null)

const jobInfo = (await PromiseIpc.send('encoder.createJob', {
Expand Down Expand Up @@ -240,21 +248,22 @@ export function UploaderView() {

let savePct = 0
const progressTrack = async () => {
const _timeNow = new Date().getTime()
const status = (await PromiseIpc.send('encoder.status', jobInfo.id)) as any

console.log(`Encoder status: `, status)

setProgress(status.progress || {})
setStatusInfo(status)

const val = caluclatePercentage()
const diffPct = val - savePct
savePct = val
const pctPerSec = diffPct / 3
const totalTimeRemaining = (100 - val) / pctPerSec

setEstimatedTimeRemaining(secondsAsString(totalTimeRemaining))
setEndTime(new Date().getTime())
const val = status.progress.percent
// const diffPct = val - savePct
// savePct = val
// const pctPerSec = diffPct / 3
// const totalTimeRemaining = (100 - val) / pctPerSec
const totalTimeRemaining = (100 * (_timeNow - _startingTime)) / val
setEstimatedTimeRemaining(millisecondsAsString(totalTimeRemaining))
setEndTime(_timeNow)
}

const pid = setInterval(progressTrack, 3000)
Expand Down Expand Up @@ -305,6 +314,8 @@ export function UploaderView() {
fontWeight: 'bold',
cursor: 'pointer',
}}
onDragOver={(e) => e.preventDefault()}
onDrop={handleVideoSelect}
>
Drop a file or click to start the upload <br />
<p>
Expand Down

0 comments on commit a55a2a9

Please sign in to comment.