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