streaming rate on embeds, artist column
This commit is contained in:
64
handlers.go
64
handlers.go
@@ -338,6 +338,7 @@ type VideoMeta struct {
|
||||
width uint
|
||||
height uint
|
||||
fps float64
|
||||
length float64
|
||||
}
|
||||
|
||||
type AudioMeta struct {
|
||||
@@ -357,10 +358,15 @@ func getVideoMeta(path string) (VideoMeta, error) {
|
||||
if err != nil {
|
||||
return VideoMeta{}, err
|
||||
}
|
||||
length, err := getLength(path)
|
||||
if err != nil {
|
||||
return VideoMeta{}, err
|
||||
}
|
||||
return VideoMeta{
|
||||
width: w,
|
||||
height: h,
|
||||
fps: fps,
|
||||
length: length,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -439,11 +445,17 @@ func processOriginal(originalID uint) {
|
||||
db.Model(&Video{}).Where("id = ?", video.ID).Update("fps", videoMeta.fps)
|
||||
db.Model(&Video{}).Where("id = ?", video.ID).Update("width", videoMeta.width)
|
||||
db.Model(&Video{}).Where("id = ?", video.ID).Update("height", videoMeta.height)
|
||||
db.Model(&Video{}).Where("id = ?", video.ID).Updates(map[string]interface{}{
|
||||
"fps": videoMeta.fps,
|
||||
"width": videoMeta.width,
|
||||
"height": videoMeta.height,
|
||||
"length": videoMeta.length,
|
||||
})
|
||||
}
|
||||
|
||||
videoSize, err := getSize(videoFilepath)
|
||||
if err == nil {
|
||||
db.Model(&Video{}).Where("id = ?", video.ID).Update("size", humanSize(videoSize))
|
||||
db.Model(&Video{}).Where("id = ?", video.ID).Update("size", videoSize)
|
||||
}
|
||||
|
||||
// create audio transcodes
|
||||
@@ -489,12 +501,12 @@ func processOriginal(originalID uint) {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(audioMeta)
|
||||
db.Model(&Audio{}).Where("id = ?", audio.ID).Update("kbps", fmt.Sprintf("%.1fk", float64(audioMeta.rate)/1000))
|
||||
db.Model(&Audio{}).Where("id = ?", audio.ID).Update("bps", audioMeta.rate)
|
||||
}
|
||||
|
||||
size, err := getSize(audioFilepath)
|
||||
if err == nil {
|
||||
db.Model(&Audio{}).Where("id = ?", audio.ID).Update("size", humanSize(size))
|
||||
db.Model(&Audio{}).Where("id = ?", audio.ID).Update("size", size)
|
||||
}
|
||||
|
||||
// create audio transcodes
|
||||
@@ -566,12 +578,17 @@ func startDownload(originalID uint, videoURL string, audioOnly bool) {
|
||||
return
|
||||
}
|
||||
|
||||
length, _ := getLength(dlFilepath)
|
||||
size, _ := getSize(dlFilepath)
|
||||
|
||||
if audioOnly {
|
||||
audio := Audio{
|
||||
OriginalID: originalID,
|
||||
Filename: dlFilename,
|
||||
Source: "original",
|
||||
Type: origMeta.ext,
|
||||
Length: length,
|
||||
Size: size,
|
||||
}
|
||||
fmt.Println("create Audio", audio)
|
||||
if db.Create(&audio).Error != nil {
|
||||
@@ -585,6 +602,8 @@ func startDownload(originalID uint, videoURL string, audioOnly bool) {
|
||||
Filename: dlFilename,
|
||||
Source: "original",
|
||||
Type: origMeta.ext,
|
||||
Length: length,
|
||||
Size: size,
|
||||
}
|
||||
fmt.Println("create Video", video)
|
||||
if db.Create(&video).Error != nil {
|
||||
@@ -610,12 +629,21 @@ func videosHandler(c echo.Context) error {
|
||||
}
|
||||
|
||||
type VideoTemplate struct {
|
||||
Video
|
||||
Source string
|
||||
Width uint
|
||||
Height uint
|
||||
FPS string
|
||||
Size string
|
||||
Filename string
|
||||
StreamRate string
|
||||
TempURL
|
||||
}
|
||||
|
||||
type AudioTemplate struct {
|
||||
Audio
|
||||
Kbps string
|
||||
Size string
|
||||
Filename string
|
||||
StreamRate string
|
||||
TempURL
|
||||
}
|
||||
|
||||
@@ -642,14 +670,36 @@ func videoHandler(c echo.Context) error {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
videoURLs = append(videoURLs, VideoTemplate{video, tempURL})
|
||||
|
||||
rate := float64(video.Size) / video.Length
|
||||
|
||||
videoURLs = append(videoURLs, VideoTemplate{
|
||||
Source: video.Source,
|
||||
Width: video.Width,
|
||||
Height: video.Height,
|
||||
FPS: fmt.Sprintf("%.1f", video.FPS),
|
||||
Size: humanSize(video.Size),
|
||||
Filename: video.Filename,
|
||||
StreamRate: fmt.Sprintf("%.1f KiB/s", rate/1024),
|
||||
TempURL: tempURL,
|
||||
})
|
||||
}
|
||||
for _, audio := range audios {
|
||||
tempURL, err := CreateTempURL(filepath.Join(dataDir, audio.Filename))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
audioURLs = append(audioURLs, AudioTemplate{audio, tempURL})
|
||||
|
||||
kbps := float64(audio.Bps) / 1000
|
||||
rate := float64(audio.Size) / audio.Length
|
||||
|
||||
audioURLs = append(audioURLs, AudioTemplate{
|
||||
Kbps: fmt.Sprintf("%.1f kbps", kbps),
|
||||
Size: humanSize(audio.Size),
|
||||
Filename: audio.Filename,
|
||||
StreamRate: fmt.Sprintf("%.1f KiB/s", rate/1024),
|
||||
TempURL: tempURL,
|
||||
})
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "video.html",
|
||||
|
10
models.go
10
models.go
@@ -30,8 +30,8 @@ type Video struct {
|
||||
Width uint
|
||||
Height uint
|
||||
FPS float64
|
||||
Length string
|
||||
Size string
|
||||
Length float64
|
||||
Size int64
|
||||
Type string
|
||||
Codec string
|
||||
}
|
||||
@@ -59,9 +59,9 @@ type Audio struct {
|
||||
gorm.Model
|
||||
OriginalID uint // Original.ID
|
||||
Source string // "original", "transcode"
|
||||
Kbps string
|
||||
Length string
|
||||
Size string
|
||||
Bps uint
|
||||
Length float64
|
||||
Size int64
|
||||
Type string
|
||||
Codec string
|
||||
Filename string
|
||||
|
@@ -54,7 +54,7 @@
|
||||
</video>
|
||||
</div>
|
||||
<div class="video-download">
|
||||
<a href="/data/{{.Filename}}" download>Download ({{.Size}})</a>
|
||||
<a href="/data/{{.Filename}}" download>Download ({{.Size}}, {{.StreamRate}})</a>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
</audio>
|
||||
</div>
|
||||
<div class="audio-download">
|
||||
<a href="/data/{{.Filename}}" download>Download ({{.Size}})</a>
|
||||
<a href="/data/{{.Filename}}" download>Download ({{.Size}}, {{.StreamRate}})</a>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
@@ -30,6 +30,7 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Author</th>
|
||||
<th>URL</th>
|
||||
<th>Type</th>
|
||||
<th>Status</th>
|
||||
@@ -44,6 +45,7 @@
|
||||
{{.Title}}
|
||||
{{end}}
|
||||
</td>
|
||||
<td>{{.Artist}}</td>
|
||||
<td><a href="{{.URL}}">{{.URL}}</a></td>
|
||||
<td>
|
||||
{{if .Audio}}
|
||||
|
28
workers.go
28
workers.go
@@ -39,7 +39,7 @@ func videoToVideo(transID uint, height uint, srcFilepath string) {
|
||||
var audioBitrate uint = 160
|
||||
if height <= 144 {
|
||||
audioBitrate = 64
|
||||
} else if height <= 240 {
|
||||
} else if height <= 480 {
|
||||
audioBitrate = 96
|
||||
} else if height < 720 {
|
||||
audioBitrate = 128
|
||||
@@ -74,7 +74,11 @@ func videoToVideo(transID uint, height uint, srcFilepath string) {
|
||||
|
||||
fileSize, err := getSize(dstFilepath)
|
||||
if err == nil {
|
||||
video.Size = humanSize(fileSize)
|
||||
video.Size = fileSize
|
||||
}
|
||||
length, err := getLength(dstFilepath)
|
||||
if err == nil {
|
||||
video.Length = length
|
||||
}
|
||||
|
||||
meta, err := getVideoMeta(dstFilepath)
|
||||
@@ -91,7 +95,7 @@ func videoToVideo(transID uint, height uint, srcFilepath string) {
|
||||
db.Delete(&trans)
|
||||
}
|
||||
|
||||
func videoToAudio(transID uint, bitrate uint, videoFilepath string) {
|
||||
func videoToAudio(transID uint, kbps uint, videoFilepath string) {
|
||||
|
||||
// determine destination path
|
||||
audioFilename := uuid.Must(uuid.NewV7()).String()
|
||||
@@ -109,7 +113,7 @@ func videoToAudio(transID uint, bitrate uint, videoFilepath string) {
|
||||
ffmpeg := "ffmpeg"
|
||||
ffmpegArgs := []string{"-i", videoFilepath, "-vn", "-acodec",
|
||||
"mp3", "-b:a",
|
||||
fmt.Sprintf("%dk", bitrate),
|
||||
fmt.Sprintf("%dk", kbps),
|
||||
audioFilepath}
|
||||
fmt.Println(ffmpeg, strings.Join(ffmpegArgs, " "))
|
||||
cmd := exec.Command(ffmpeg, ffmpegArgs...)
|
||||
@@ -128,11 +132,15 @@ func videoToAudio(transID uint, bitrate uint, videoFilepath string) {
|
||||
db.First(&orig, "id = ?", trans.OriginalID)
|
||||
|
||||
// create audio record
|
||||
audio := Audio{OriginalID: orig.ID, Filename: audioFilename, Kbps: fmt.Sprintf("%dk", bitrate)}
|
||||
audio := Audio{OriginalID: orig.ID, Filename: audioFilename, Bps: kbps * 1000}
|
||||
|
||||
fileSize, err := getSize(audioFilepath)
|
||||
if err == nil {
|
||||
audio.Size = humanSize(fileSize)
|
||||
audio.Size = fileSize
|
||||
}
|
||||
length, err := getLength(audioFilepath)
|
||||
if err == nil {
|
||||
audio.Length = length
|
||||
}
|
||||
|
||||
db.Create(&audio)
|
||||
@@ -181,12 +189,16 @@ func audioToAudio(transID uint, kbps uint, srcFilepath string) {
|
||||
audio := Audio{
|
||||
OriginalID: orig.ID,
|
||||
Filename: dstFilename,
|
||||
Kbps: fmt.Sprintf("%dk", kbps),
|
||||
Bps: kbps * 1000,
|
||||
}
|
||||
|
||||
fileSize, err := getSize(dstFilepath)
|
||||
if err == nil {
|
||||
audio.Size = humanSize(fileSize)
|
||||
audio.Size = fileSize
|
||||
}
|
||||
length, err := getLength(dstFilepath)
|
||||
if err == nil {
|
||||
audio.Length = length
|
||||
}
|
||||
|
||||
db.Create(&audio)
|
||||
|
Reference in New Issue
Block a user