Removed Spaces CDN
This commit is contained in:
101
arn/AMV.go
101
arn/AMV.go
@ -1,16 +1,14 @@
|
||||
package arn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/aerogo/nano"
|
||||
"github.com/animenotifier/notify.moe/arn/video"
|
||||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
// AMV is an anime music video.
|
||||
@ -39,13 +37,7 @@ func (amv *AMV) Link() string {
|
||||
|
||||
// VideoLink returns the permalink for the video file.
|
||||
func (amv *AMV) VideoLink() string {
|
||||
domain := "arn.sfo2.cdn"
|
||||
|
||||
if amv.IsDraft {
|
||||
domain = "arn.sfo2"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("https://%s.digitaloceanspaces.com/videos/amvs/%s", domain, amv.File)
|
||||
return fmt.Sprintf("https://notify.moe/videos/amvs/%s", amv.File)
|
||||
}
|
||||
|
||||
// TitleByUser returns the preferred title for the given user.
|
||||
@ -56,17 +48,13 @@ func (amv *AMV) TitleByUser(user *User) string {
|
||||
// SetVideoReader sets the bytes for the video file by reading them from the reader.
|
||||
func (amv *AMV) SetVideoReader(reader io.Reader) error {
|
||||
fileName := amv.ID + ".webm"
|
||||
pattern := amv.ID + ".*.webm"
|
||||
file, err := os.CreateTemp("", pattern)
|
||||
file, err := os.Create(filepath.Join(Root, "videos", "amvs", fileName))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filePath := file.Name()
|
||||
defer os.Remove(filePath)
|
||||
|
||||
// Write file contents
|
||||
defer file.Close()
|
||||
_, err = io.Copy(file, reader)
|
||||
|
||||
if err != nil {
|
||||
@ -74,56 +62,59 @@ func (amv *AMV) SetVideoReader(reader io.Reader) error {
|
||||
}
|
||||
|
||||
// Run mkclean
|
||||
optimizedFile := filePath + ".optimized"
|
||||
defer os.Remove(optimizedFile)
|
||||
// optimizedFile := filePath + ".optimized"
|
||||
// defer os.Remove(optimizedFile)
|
||||
|
||||
cmd := exec.Command(
|
||||
"mkclean",
|
||||
"--doctype", "4",
|
||||
"--keep-cues",
|
||||
"--optimize",
|
||||
filePath,
|
||||
optimizedFile,
|
||||
)
|
||||
// cmd := exec.Command(
|
||||
// "mkclean",
|
||||
// "--doctype", "4",
|
||||
// "--keep-cues",
|
||||
// "--optimize",
|
||||
// filePath,
|
||||
// optimizedFile,
|
||||
// )
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
// cmd.Stdout = os.Stdout
|
||||
// cmd.Stderr = os.Stderr
|
||||
// cmd.Stdin = os.Stdin
|
||||
|
||||
err = cmd.Start()
|
||||
// err = cmd.Start()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
err = cmd.Wait()
|
||||
// err = cmd.Wait()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// Refresh video file info
|
||||
info, err := video.GetInfo(optimizedFile)
|
||||
// info, err := video.GetInfo(optimizedFile)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// Is our storage server available?
|
||||
if Spaces == nil {
|
||||
return errors.New("File storage client has not been initialized")
|
||||
}
|
||||
// // Is our storage server available?
|
||||
// if Spaces == nil {
|
||||
// return errors.New("File storage client has not been initialized")
|
||||
// }
|
||||
|
||||
// Make sure the file is public
|
||||
userMetaData := map[string]string{
|
||||
"x-amz-acl": "public-read",
|
||||
}
|
||||
// // Make sure the file is public
|
||||
// userMetaData := map[string]string{
|
||||
// "x-amz-acl": "public-read",
|
||||
// }
|
||||
|
||||
// Upload the file to our storage server
|
||||
_, err = Spaces.FPutObject(context.TODO(), "arn", fmt.Sprintf("videos/amvs/%s.webm", amv.ID), optimizedFile, minio.PutObjectOptions{
|
||||
ContentType: "video/webm",
|
||||
UserMetadata: userMetaData,
|
||||
})
|
||||
// // Upload the file to our storage server
|
||||
// _, err = Spaces.FPutObject(context.TODO(), "arn", , optimizedFile, minio.PutObjectOptions{
|
||||
// ContentType: "video/webm",
|
||||
// UserMetadata: userMetaData,
|
||||
// })
|
||||
|
||||
// Refresh video file info
|
||||
info, err := video.GetInfo(fileName)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -190,7 +181,7 @@ func (amv *AMV) Publish() error {
|
||||
}
|
||||
|
||||
// No file uploaded
|
||||
_, err := Spaces.StatObject(context.TODO(), "arn", fmt.Sprintf("videos/amvs/%s", amv.File), minio.StatObjectOptions{})
|
||||
_, err := os.Stat(filepath.Join(Root, "videos", "amvs", amv.File))
|
||||
|
||||
if err != nil {
|
||||
return errors.New("You need to upload a WebM file for this AMV")
|
||||
|
Reference in New Issue
Block a user