Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output flag #42

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ vimeo-dl -i "https://8vod-adaptive.akamaized.net/xxx/yyy/sep/video/9f88d1ff,b83d
ffmpeg -i ${clip_id}-video.mp4 -i ${clip_id}-audio.mp4 -c copy ${clip_id}.mp4
```

```sh
# Download a video with the specified output file name
vimeo-dl -i "https://8vod-adaptive.akamaized.net/xxx/yyy/sep/video/9f88d1ff,b83d0f9d,da44206b,f34fd50d,f9ebc26f/master.json?base64_init=1" \
--video-id "b83d0f9d" \
--audio-id "b83d0f9d" \
--combine \
-o "output"
```

## Options

```
Expand All @@ -54,6 +63,7 @@ Flags:
--user-agent string user-agent for request
-v, --version version for vimeo-dl
--video-id string video id
-o, --output output file name
```

## Install
Expand Down
29 changes: 26 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"net/url"
"os"
"os/exec"
"regexp"
"strings"

"github.com/akiomik/vimeo-dl/config"
"github.com/akiomik/vimeo-dl/vimeo"
Expand All @@ -31,6 +33,7 @@ var (
userAgent string
videoId string
audioId string
output string
combine bool
)

Expand All @@ -56,7 +59,8 @@ var rootCmd = &cobra.Command{
os.Exit(1)
}

videoOutputFilename := masterJson.ClipId + "-video.mp4"
videoOutputFilename := generateOutputFilename(masterJson.ClipId, "video.mp4")

err = createVideo(client, masterJson, masterJsonUrl, videoOutputFilename)
if err != nil {
fmt.Println("Error:", err.Error())
Expand All @@ -73,15 +77,17 @@ var rootCmd = &cobra.Command{
}

if len(masterJson.Audio) > 0 {
audioOutputFilename := masterJson.ClipId + "-audio.mp4"
audioOutputFilename := generateOutputFilename(masterJson.ClipId, "audio.mp4")

err = createAudio(client, masterJson, masterJsonUrl, audioOutputFilename)
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
}

if combine {
outputFilename := masterJson.ClipId + ".mp4"
outputFilename := generateOutputFilename(masterJson.ClipId, ".mp4")

err = combineVideoAndAudio(videoOutputFilename, audioOutputFilename, outputFilename)
if err != nil {
fmt.Println("Error:", err.Error())
Expand All @@ -99,6 +105,7 @@ func init() {
rootCmd.Flags().StringVarP(&userAgent, "user-agent", "", "", "user-agent for request")
rootCmd.Flags().StringVarP(&videoId, "video-id", "", "", "video id")
rootCmd.Flags().StringVarP(&audioId, "audio-id", "", "", "audio id")
rootCmd.Flags().StringVarP(&output, "output", "o", "", "output file name")
rootCmd.Flags().BoolVarP(&combine, "combine", "", false, "combine video and audio into a single mp4 (ffmpeg is required)")
rootCmd.MarkFlagRequired("input")
}
Expand Down Expand Up @@ -173,3 +180,19 @@ func combineVideoAndAudio(videoFilename string, audioFilename string, outputFile

return nil
}

func generateOutputFilename(clipId, suffix string) string {
if output == "" {
return clipId + "-" + suffix
}

sanitizedOutput := sanitizeFileName(output)
return sanitizedOutput + "-" + suffix
}

func sanitizeFileName(filename string) string {
invalidCharRegex := regexp.MustCompile(`[\\/:"*?<>|]`)
filename = invalidCharRegex.ReplaceAllString(filename, "_")
filename = strings.TrimSpace(filename)
return filename
}
Loading