-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
96 lines (77 loc) · 2.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"flag"
"log"
"github.com/zachary-walters/anthelion_api/models"
"github.com/zachary-walters/anthelion_api/options"
"github.com/zachary-walters/anthelion_api/services"
)
func main() {
var filePath string
var tmdbID string
var announceUrl string
var apiKey string
flag.StringVar(&filePath, "p", "", "file path to the video file (-p)")
flag.StringVar(&tmdbID, "t", "", "TMDB ID (-t)")
flag.StringVar(&announceUrl, "u", "", "Announce URL (-u)")
flag.StringVar(&apiKey, "k", "", "API Key (-k)")
flag.Parse()
if filePath == "" {
log.Println("A file path (-p) flag is required.")
return
}
if tmdbID == "" {
log.Println("TMDB ID (-t) flag is required.")
return
}
options.LoadEnv()
if options.ANTHELION_API_URL == "" {
log.Println("Anthelion's API URL must be set as en environment variable")
return
}
if announceUrl != "" {
options.ANNOUNCE_URL = announceUrl
}
if apiKey != "" {
options.API_KEY = apiKey
}
if options.ANNOUNCE_URL == "" || options.API_KEY == "" {
log.Println("APIKey and/or Announce URL are missing. Aborting.")
return
}
shellCommandService := services.NewShellCommandService()
// GENERATE MEDIAINFO
mediainfo, err := shellCommandService.GetMediaInfo(filePath)
if err != nil {
return
}
log.Println("Generating Mediainfo DONE.")
mediainfoParsingService := services.NewMediainfoParsingService()
flags := mediainfoParsingService.GetFlags(mediainfo)
// CREATE .TORRENT FILE
torrentPath, err := shellCommandService.MakeTorrentFile(filePath)
if err != nil {
return
}
log.Println("Creating .torrent file DONE.")
// UPLOAD TORRENT
log.Println("Uploading Torrent ...")
apiParams := models.APIInputParameter{
APIKey: options.API_KEY,
Action: "upload",
TMDBID: tmdbID,
Mediainfo: mediainfo,
FileInput: torrentPath,
Flags: flags,
}
apiService := services.NewAPIService()
apiUploadResponse, err := apiService.UploadTorrent(apiParams)
if err != nil {
return
}
log.Println("Uploading Torrent DONE.")
err = apiService.DownloadTorrent(apiUploadResponse.Download, filePath)
if err != nil {
return
}
}