-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nicer UI. removed download functionality temporarily (todo)
- Loading branch information
Showing
14 changed files
with
358 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,158 @@ | ||
<script> | ||
import { DownloadVideo } from '../wailsjs/go/controllers/App.js' | ||
let url | ||
let text = "" | ||
/* | ||
type DownloadOptions struct { | ||
Path string | ||
DownloadType string // "video" or "audio" | ||
FileType string // e.g., "mp4", "mp3" | ||
Resolution string // e.g., "720p", "1080p" | ||
Quality string // e.g., "best", "worst" | ||
} | ||
*/ | ||
const downloadOptions = { | ||
URL: url, | ||
DownloadType: "video", | ||
FileType: "mp4", | ||
Resolution: "720p", | ||
Quality: "best", | ||
} | ||
function handleButtonClick() { | ||
DownloadVideo(downloadOptions).then((result) => { | ||
text = result; | ||
}); | ||
} | ||
import { OpenBrowser, GetVideoInfo } from "../wailsjs/go/controllers/App.js"; | ||
import { onAccesibilityKeydown } from "./utils/accessibility.js"; | ||
import VideoModal from "./components/VideoModal.svelte"; | ||
import ThemeSwitcher from "./components/ThemeSwitcher.svelte"; | ||
let showModal = false; | ||
let modalTitle; | ||
let modalContent; | ||
let url; | ||
function openInBrowser(anchorUrl) { | ||
OpenBrowser(anchorUrl); | ||
} | ||
function openModal() { | ||
showModal = true; | ||
} | ||
function closeModal() { | ||
showModal = false; | ||
} | ||
function handleButtonClick() { | ||
if (!url) return; | ||
GetVideoInfo(url) | ||
.then((videoInfo) => { | ||
console.log(videoInfo); | ||
if (!videoInfo.Valid) { | ||
modalTitle = "Error fetching video!"; | ||
modalContent = "Please check your URL and try again."; | ||
} else { | ||
modalTitle = videoInfo.title; | ||
modalContent = `Duration: ${videoInfo.duration}\nUploader: ${videoInfo.uploader}\nViews : ${videoInfo.view_count}`; | ||
} | ||
openModal(); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
modalTitle = "Error fetching video!"; | ||
modalContent = "Please check your URL and try again."; | ||
openModal(); | ||
}); | ||
} | ||
</script> | ||
|
||
|
||
<main> | ||
|
||
<div class="input-box" id="input"> | ||
<p>{text}</p> | ||
<input autocomplete="off" bind:value={url} class="input" id="name" type="text"/> | ||
<button class="btn" on:click={handleButtonClick}>Get</button> | ||
</div> | ||
<ThemeSwitcher /> | ||
|
||
<h1 class="title"><span>Youtube Downloader</span></h1> | ||
|
||
<div class="input-box" id="input"> | ||
<input autocomplete="off" bind:value={url} class="input" id="name" type="text" placeholder="Enter your URL here..."/> | ||
<button class="btn" on:click={handleButtonClick}>►</button> | ||
</div> | ||
<footer> | ||
<p>Works with <span | ||
on:keydown={onAccesibilityKeydown} | ||
on:click={() => openInBrowser("https://github.com/yt-dlp/yt-dlp")} | ||
>almost anything</span>. Blazingly fast, I guess.</p> | ||
<p>Made by <span | ||
on:keydown={onAccesibilityKeydown} | ||
on:click={() => openInBrowser("https://github.com/nxrmqlly")} | ||
>@nxrmqlly</span> with | ||
|
||
<span | ||
on:keydown={onAccesibilityKeydown} | ||
on:click={() => openInBrowser("https://youtu.be/dQw4w9WgXcQ")} | ||
>❤</span> using Go and Svelte</p> | ||
</footer> | ||
|
||
{#if showModal} | ||
<VideoModal | ||
title={modalTitle} | ||
content={modalContent} | ||
onClose={closeModal} | ||
/> | ||
{/if} | ||
|
||
</main> | ||
|
||
|
||
<style> | ||
main { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100dvh; | ||
background-color: var(--bg-color); | ||
} | ||
.title { | ||
color: var(--fg-color); | ||
} | ||
.title span { | ||
display: inline-block; | ||
} | ||
.title span::after{ | ||
content: ''; | ||
height: 0.1em; | ||
background: var(--accent); | ||
border-radius: 0.1em; | ||
display: block | ||
} | ||
.input-box { | ||
margin-top: 1em; | ||
display: flex; | ||
border: 0.1em solid var(--accent); | ||
border-radius: 0.1em; | ||
overflow: hidden; | ||
} | ||
.input { | ||
border: none; | ||
padding: 10px; | ||
width: 30rem; | ||
outline: none; | ||
flex: 1; | ||
} | ||
.btn { | ||
background-color: var(--accent); | ||
color: white; | ||
border: none; | ||
padding: 10px 15px; | ||
transition: background-color 0.3s; | ||
} | ||
.btn:hover { | ||
cursor: pointer; | ||
background-color: var(--duo-accent); | ||
} | ||
footer { | ||
user-select: none; | ||
position: absolute; | ||
bottom: 0; | ||
width: 100%; | ||
text-align: center; | ||
font-size: 12px; | ||
color: #787878; | ||
} | ||
footer span { | ||
color: var(--accent); | ||
text-decoration: none; | ||
} | ||
footer span:hover { | ||
cursor: pointer; | ||
text-decoration: underline; | ||
} | ||
</style> |
Oops, something went wrong.