{text}
- - -diff --git a/backend/controllers/browser.go b/backend/controllers/browser.go
new file mode 100644
index 0000000..966a58d
--- /dev/null
+++ b/backend/controllers/browser.go
@@ -0,0 +1,9 @@
+package controllers
+
+import (
+ "github.com/wailsapp/wails/v2/pkg/runtime"
+)
+
+func (a *App) OpenBrowser(url string) {
+ runtime.BrowserOpenURL(a.ctx, url)
+}
diff --git a/backend/controllers/download.go b/backend/controllers/download.go
index 3264a0f..5d140a2 100644
--- a/backend/controllers/download.go
+++ b/backend/controllers/download.go
@@ -8,17 +8,11 @@ import (
"unicode"
"youtube-downloader-go/backend/models"
+ "youtube-downloader-go/backend/utils"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
-var youtubeRegex, _ = regexp.Compile(`^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(?:-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$`)
-
-// Check if the url is valid youtube video URL
-func isValidYouTubeURL(url string) bool {
- return youtubeRegex.MatchString(url)
-}
-
func slugify(input string) string {
// Remove non-ASCII characters
cleaned := strings.Map(func(r rune) rune {
@@ -47,12 +41,9 @@ func slugify(input string) string {
func (a *App) DownloadVideo(opts models.DownloadOptions) (string, error) {
//* check if the url is valid
- var url = opts.URL
+ _, ytdlpPath := utils.YtDlpSetup()
- if !isValidYouTubeURL(url) {
- err := fmt.Errorf("invalid url: %s", url)
- return err.Error(), err
- }
+ var url = opts.URL
pathToSave, err := runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{Title: "Save File"})
@@ -78,7 +69,7 @@ func (a *App) DownloadVideo(opts models.DownloadOptions) (string, error) {
}
// Execute yt-dlp command
- cmd := exec.Command("yt-dlp", cmdArgs...)
+ cmd := exec.Command(ytdlpPath, cmdArgs...)
output, err := cmd.CombinedOutput()
if err != nil {
err := fmt.Errorf("error executing yt-dlp: %v\nOutput: %s", err, string(output))
diff --git a/backend/controllers/get.go b/backend/controllers/get.go
new file mode 100644
index 0000000..c2a7087
--- /dev/null
+++ b/backend/controllers/get.go
@@ -0,0 +1,33 @@
+package controllers
+
+import (
+ "encoding/json"
+ "fmt"
+ "os/exec"
+
+ "youtube-downloader-go/backend/models"
+ "youtube-downloader-go/backend/utils"
+)
+
+func (a *App) GetVideoInfo(videoURL string) (models.VideoInfo, error) {
+ _, ytDlpPath := utils.YtDlpSetup()
+
+ cmd := exec.Command(ytDlpPath, "--dump-json", videoURL)
+
+ // Capture the output
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ return models.VideoInfo{Valid: false}, fmt.Errorf("1 error executing yt-dlp: %w", err)
+ }
+
+ // Parse the JSON output
+ var videoInfo models.VideoInfo
+ err = json.Unmarshal(output, &videoInfo)
+ if err != nil {
+ return models.VideoInfo{Valid: false}, fmt.Errorf("error parsing JSON: %w", err)
+ }
+
+ videoInfo.Valid = true
+
+ return videoInfo, nil
+}
diff --git a/backend/models/video_info.go b/backend/models/video_info.go
new file mode 100644
index 0000000..e62f89d
--- /dev/null
+++ b/backend/models/video_info.go
@@ -0,0 +1,9 @@
+package models
+
+type VideoInfo struct {
+ Valid bool
+ Title string `json:"title"`
+ Uploader string `json:"uploader"`
+ Duration int `json:"duration"` // Duration in seconds
+ ViewCount int `json:"view_count"`
+}
diff --git a/backend/utils/get_ytdlp.go b/backend/utils/get_ytdlp.go
index 98c55f5..a216fea 100644
--- a/backend/utils/get_ytdlp.go
+++ b/backend/utils/get_ytdlp.go
@@ -6,28 +6,33 @@ import (
"net/http"
"os"
"path/filepath"
-
- "github.com/wader/goutubedl"
)
const YtDlpGitgubRelease = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe"
// If yt-dlp isn't installed yet, download it locally.
-func getYtDlp() {
+func downloadYtDlpBinary() (string, error) {
folderPath := "./bin-deps"
- // Check if the folder exists
- _, err := os.Stat(folderPath)
-
// If the folder doesn't exist, create it
+ _, err := os.Stat(folderPath)
if os.IsNotExist(err) {
err := os.Mkdir(folderPath, 0755)
if err != nil {
fmt.Println("Error creating folder:", err)
- return
+ return "", err
}
}
- out, err := os.Create("./bin-deps/yt-dlp.exe")
+
+ // create a new file in the folder
+
+ cwd, err := os.Getwd()
+ if err != nil {
+ panic(err)
+ }
+ pathToCreate := filepath.Join(cwd, "bin-deps", "yt-dlp.exe")
+
+ out, err := os.Create(pathToCreate)
if err != nil {
panic(err)
}
@@ -35,26 +40,30 @@ func getYtDlp() {
resp, err := http.Get(YtDlpGitgubRelease)
if err != nil {
- panic(err)
+ return "", err
}
defer resp.Body.Close()
io.Copy(out, resp.Body)
+ return pathToCreate, nil
}
// Get yt-dlp if not exists, returns cwd and path of yt-dlp
-func YtDlSetup() (string, string) {
- // check if ./bin-deps/yt-dlp.exe exists
- if _, err := os.Stat("./bin-deps/yt-dlp.exe"); os.IsNotExist(err) {
- getYtDlp()
- }
+func YtDlpSetup() (string, string) {
+ var ytDlpPath string
var cwd, err = os.Getwd()
if err != nil {
panic(err)
}
- goutubedl.Path = filepath.Join(cwd, "bin-deps", "yt-dlp.exe")
- return cwd, goutubedl.Path
+ // check if ./bin-deps/yt-dlp.exe exists
+ if _, err := os.Stat("./bin-deps/yt-dlp.exe"); os.IsNotExist(err) {
+ ytDlpPath, _ = downloadYtDlpBinary()
+ } else {
+ ytDlpPath = filepath.Join(cwd, "bin-deps", "yt-dlp.exe")
+
+ }
+ return cwd, ytDlpPath
}
diff --git a/frontend/package.json b/frontend/package.json
index 8c9ae62..c903c36 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -12,5 +12,8 @@
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"svelte": "^3.49.0",
"vite": "^3.0.7"
+ },
+ "dependencies": {
+ "@fortawesome/fontawesome-free": "^6.6.0"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte
index a14aba6..0543e54 100644
--- a/frontend/src/App.svelte
+++ b/frontend/src/App.svelte
@@ -1,42 +1,158 @@
{text}Youtube Downloader
+
+