Skip to content

Commit

Permalink
Initial upload support for catbox
Browse files Browse the repository at this point in the history
  • Loading branch information
vladaad committed Dec 14, 2023
1 parent 68fd3ed commit 954609c
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 5 deletions.
13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ module github.com/vladaad/discordcompressor

go 1.17

require github.com/google/uuid v1.3.0
require (
github.com/google/uuid v1.3.0
github.com/wabarc/go-catbox v0.1.0
)

require (
github.com/pkg/errors v0.9.1 // indirect
github.com/wabarc/helper v0.0.0-20210718171053-59c70d0b20c2 // indirect
golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect
golang.org/x/text v0.3.6 // indirect
mvdan.cc/xurls/v2 v2.2.0 // indirect
)
24 changes: 24 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/wabarc/go-catbox v0.1.0 h1:/UhV9md3MJrjZtm+EToSyFjawXgPiHSExLNRqsWNisg=
github.com/wabarc/go-catbox v0.1.0/go.mod h1:Zjs9Y55f2WOwGWwmKSCrUuMfwh+nDktkjub9jgHq4CQ=
github.com/wabarc/helper v0.0.0-20210718171053-59c70d0b20c2 h1:6rMZse2rdD7N6GxHRZqHlkSptBWh/Vf9aHiFVQjlQNo=
github.com/wabarc/helper v0.0.0-20210718171053-59c70d0b20c2/go.mod h1:uS6mimKlWkGvEZXkJ6JoW7LYnnB2JP6dLU9q7pgDaWQ=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210716203947-853a461950ff h1:j2EK/QoxYNBsXI4R7fQkkRUk8y6wnOBI+6hgPdP/6Ds=
golang.org/x/net v0.0.0-20210716203947-853a461950ff/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
mvdan.cc/xurls/v2 v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
mvdan.cc/xurls/v2 v2.2.0/go.mod h1:EV1RMtya9D6G5DMYPGD8zTQzaHet6Jh8gFlRgGRJeO8=
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/vladaad/discordcompressor/encoder/audio"
"github.com/vladaad/discordcompressor/metadata"
"github.com/vladaad/discordcompressor/settings"
"github.com/vladaad/discordcompressor/uploader"
"github.com/vladaad/discordcompressor/utils"
"io"
"log"
Expand Down Expand Up @@ -96,11 +97,19 @@ func init() {
}

func main() {
// Empty function for now, will be used for future features if needed
compress(input)
outVideo := compress(input)
log.Println("Done!")

// Optional video upload
if settings.General.UploadService != "none" {
URL := uploader.Upload(outVideo)
if URL != "" {
log.Println("Uploaded to: " + URL)
}
}
}

func compress(inVideo string) bool {
func compress(inVideo string) string {
var wg sync.WaitGroup
// Initialize variables
video := initVideo()
Expand Down Expand Up @@ -188,7 +197,7 @@ func compress(inVideo string) bool {
os.Remove(video.UUID + "-0.log.mbtree")
os.Remove(video.Output.AudioFile)

return true
return video.OutFile
}

func checkForFF() {
Expand Down
4 changes: 4 additions & 0 deletions settings/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func initGeneral() *general {
FDKaacExecutable: "fdkaac",
FHGaacExecutable: "fhgaacenc",
OutputSuffix: "-%smb",
UploadService: "none",
UploadMaxMB: 100,
}
}

Expand All @@ -24,4 +26,6 @@ type general struct {
FDKaacExecutable string
FHGaacExecutable string
OutputSuffix string
UploadService string
UploadMaxMB float64
}
17 changes: 17 additions & 0 deletions uploader/catbox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uploader

import (
"github.com/wabarc/go-catbox"
"log"
)

func catboxUpload(path string) string {
url, err := catbox.New(nil).Upload(path)

if err != nil {
log.Println(err)
panic("Catbox upload failed!")
}

return url
}
30 changes: 30 additions & 0 deletions uploader/uploader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uploader

import (
"github.com/vladaad/discordcompressor/settings"
"log"
"os"
)

func Upload(path string) string {
// Checking if filesize is under limit
file, err := os.Stat(path)
if err != nil {
panic(err)
}

if file.Size() > int64(settings.General.UploadMaxMB*1048576) { // 1024^2
log.Println("The video has exceeded the set upload limit! Please reduce the size parameter.")
return ""
}

// Upload
log.Println("Uploading...")
switch settings.General.UploadService {
case "catbox":
return catboxUpload(path)
default:
log.Println("Upload service name invalid!")
return ""
}
}

0 comments on commit 954609c

Please sign in to comment.