-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f5c0ace
Showing
1,418 changed files
with
74,271 additions
and
0 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,16 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
bin/ | ||
|
||
*.syso |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Abdelhafidh Belalia | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,45 @@ | ||
PROJECT_NAME = YouTubeDownloader | ||
|
||
CMD_DIR = ./cmd/ | ||
|
||
BIN_DIR_MAC = ./bin/mac/ | ||
BIN_DIR_LINUX = ./bin/linux/ | ||
BIN_DIR_WINDOWS = ./bin/windows/ | ||
|
||
GIT_TAG = "$(shell git describe --tags)" | ||
|
||
LD_FLAGS_MAC = "-X 'github.com/s77rt/YouTubeDownloader.Version=$(GIT_TAG)'" | ||
LD_FLAGS_LINUX = "-X 'github.com/s77rt/YouTubeDownloader.Version=$(GIT_TAG)'" | ||
LD_FLAGS_WINDOWS = "-X 'github.com/s77rt/YouTubeDownloader.Version=$(GIT_TAG)' -H windowsgui" | ||
|
||
all: clean dep compile | ||
|
||
clean: | ||
@echo -n "Cleaning: " | ||
@rm -rf $(BIN_DIR_MAC) | ||
@rm -rf $(BIN_DIR_LINUX) | ||
@rm -rf $(BIN_DIR_WINDOWS) | ||
@echo "[OK]" | ||
|
||
dep: | ||
@echo -n "Downloading Dependencies: " | ||
@go get -d ./... | ||
@echo "[OK]" | ||
|
||
compile: | ||
@echo "Compiling: " | ||
|
||
# MacOS (64bit) | ||
@mkdir -p $(BIN_DIR_MAC) | ||
GOOS=darwin GOARCH=amd64 go build -ldflags $(LD_FLAGS_MAC) -o $(BIN_DIR_MAC)$(PROJECT_NAME) $(CMD_DIR)$(PROJECT_NAME) | ||
|
||
# Linux (64bit) | ||
@mkdir -p $(BIN_DIR_LINUX) | ||
GOOS=linux GOARCH=amd64 go build -ldflags $(LD_FLAGS_LINUX) -o $(BIN_DIR_LINUX)$(PROJECT_NAME) $(CMD_DIR)$(PROJECT_NAME) | ||
|
||
# Windows (64bit) | ||
@mkdir -p $(BIN_DIR_WINDOWS) | ||
rsrc -arch amd64 -ico ico.ico -o $(CMD_DIR)$(PROJECT_NAME)/rsrc_windows_amd64.syso | ||
GOOS=windows GOARCH=amd64 go build -ldflags $(LD_FLAGS_WINDOWS) -o $(BIN_DIR_WINDOWS)$(PROJECT_NAME).exe $(CMD_DIR)$(PROJECT_NAME) | ||
|
||
@echo "[OK]" |
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,5 @@ | ||
# YouTubeDownloader | ||
YouTubeDownloader is a simple cross-platform YouTube downloader. | ||
|
||
## TODO | ||
- Write a better README.md |
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,48 @@ | ||
package YouTubeDownloader | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
E "github.com/s77rt/YouTubeDownloader/extractor" | ||
D "github.com/s77rt/YouTubeDownloader/downloader" | ||
) | ||
|
||
var ( | ||
Version string = "dev" | ||
) | ||
|
||
var ( | ||
tmpdir string | ||
outdir string | ||
extractor E.Extractor // Currently only one is supported | ||
downloader *D.Downloader | ||
tasks Tasks | ||
) | ||
|
||
func Init() { | ||
maketmpdir() | ||
makeoutdir() | ||
extractor = E.New_YouTube_Extractor() // Currently only YouTube is supported | ||
downloader = D.New_Downloader() | ||
tasks = NewTasks() | ||
} | ||
|
||
func Clean() { | ||
os.RemoveAll(tmpdir) | ||
} | ||
|
||
func maketmpdir() { | ||
tmpdir = filepath.Join(os.TempDir(), "YouTubeDownloader") | ||
err := os.MkdirAll(tmpdir, 0o755) | ||
if err != nil { | ||
panic("unable to create tmpdir") | ||
} | ||
} | ||
|
||
func makeoutdir() { | ||
outdir = filepath.Join(".", "Downloads") | ||
err := os.MkdirAll(outdir, 0o755) | ||
if err != nil { | ||
panic("unable to create outdir") | ||
} | ||
} |
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,97 @@ | ||
package YouTubeDownloader | ||
|
||
import ( | ||
"github.com/zserge/lorca" | ||
D "github.com/s77rt/YouTubeDownloader/downloader" | ||
) | ||
|
||
func BindUI(ui lorca.UI) { | ||
ui.Bind("Ready", func() { | ||
ui.Eval(`setVersion('`+EscapeJS(Version)+`');`) | ||
}) | ||
|
||
ui.Bind("GetVideo", func(url string) { | ||
video, err := extractor.GetVideo(url) | ||
if err != nil { | ||
ui.Eval(`w_GetVideo__onerror('`+EscapeJS(err.Error())+`');`) | ||
} else { | ||
ui.Eval(`add_video(`+EscapeJS(MarshalJSONS(video))+`);`) | ||
} | ||
ui.Eval(`h_unlock();`) | ||
}) | ||
|
||
ui.Bind("GetVideos", func(url string) { | ||
videos, err := extractor.GetVideos(url) | ||
if err != nil { | ||
ui.Eval(`w_GetVideo__onerror('`+EscapeJS(err.Error())+`');`) | ||
} else { | ||
for _, video := range videos { | ||
ui.Eval(`add_video(`+EscapeJS(MarshalJSONS(video))+`);`) | ||
} | ||
} | ||
ui.Eval(`h_unlock();`) | ||
}) | ||
|
||
ui.Bind("GetExistingVideo", func(uuid string, video interface{}, format interface{}) { | ||
filename, err := getOutputFile(extractor, downloader, video, format) | ||
if err != nil { | ||
ui.Eval(`w_GetExistingVideo__onerror('`+EscapeJS(uuid)+`', '`+EscapeJS(err.Error())+`');`) | ||
} else if FileExists(filename) { | ||
ui.Eval(`update_video_success('`+EscapeJS(uuid)+`','`+EscapeJS(filename)+`');`) | ||
} else { | ||
ui.Eval(`w_GetExistingVideo__onerror('`+EscapeJS(uuid)+`', 'not available');`) | ||
} | ||
}) | ||
|
||
ui.Bind("DownloadVideo", func(uuid string, video interface{}, format interface{}) { | ||
task := tasks.New(uuid) | ||
filename, err := DownloadVideo(task.Context, task.Tmpdir, extractor, downloader, video, format, func(p1, p2 *D.Progress) { | ||
ui.Eval(`update_video_progress('`+EscapeJS(uuid)+`',`+EscapeJS(MarshalJSONS(p1))+`,`+EscapeJS(MarshalJSONS(p2))+`);`) | ||
}) | ||
if err != nil { | ||
if task.Context.Err() != nil { | ||
/* | ||
Errors that are catched in this state where the context is closed | ||
are probably fine to ignore, because as the context get closed, by default a "post" function | ||
get executed and will delete the tmp files for that task, which may result in "no such file or directory" error | ||
for a function that may still trying to use such temp files, thus the error. | ||
the error may also be context.Canceled which is fine. | ||
this should be further investigated... | ||
*/ | ||
} else { | ||
ui.Eval(`w_DownloadVideo__onerror('`+EscapeJS(uuid)+`', '`+EscapeJS(err.Error())+`');`) | ||
} | ||
} else { | ||
ui.Eval(`update_video_success('`+EscapeJS(uuid)+`','`+EscapeJS(filename)+`');`) | ||
} | ||
task.Done() | ||
}) | ||
|
||
ui.Bind("CancelDownload", func(uuid string) { | ||
err := tasks.Abort(uuid) | ||
if err != nil { | ||
ui.Eval(`w_CancelDownload__onerror('`+EscapeJS(uuid)+`', '`+EscapeJS(err.Error())+`');`) | ||
} | ||
}) | ||
|
||
ui.Bind("PlayVideo", func(uuid string, video_filename string) { | ||
err := RunFile(video_filename) | ||
if err != nil { | ||
ui.Eval(`w_PlayVideo__onerror('`+EscapeJS(uuid)+`', '`+EscapeJS(err.Error())+`');`) | ||
} | ||
}) | ||
|
||
ui.Bind("OpenFolder", func(uuid string, video_filename string) { | ||
err := OpenFolder(video_filename) | ||
if err != nil { | ||
ui.Eval(`w_OpenFolder__onerror('`+EscapeJS(uuid)+`', '`+EscapeJS(err.Error())+`');`) | ||
} | ||
}) | ||
|
||
ui.Bind("DeleteVideo", func(uuid string, video_filename string) { | ||
err := DeleteFile(video_filename) | ||
if err != nil { | ||
ui.Eval(`w_DeleteVideo__onerror('`+EscapeJS(uuid)+`', '`+EscapeJS(err.Error())+`');`) | ||
} | ||
}) | ||
} |
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,32 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/s77rt/YouTubeDownloader" | ||
) | ||
|
||
func main() { | ||
YouTubeDownloader.Init() | ||
|
||
server := YouTubeDownloader.NewServer() | ||
defer server.Close() | ||
|
||
ui := YouTubeDownloader.NewUI() | ||
defer ui.Close() | ||
|
||
YouTubeDownloader.BindUI(ui) | ||
|
||
YouTubeDownloader.LoadUI(ui, server) | ||
|
||
// Wait until the interrupt signal arrives or browser window is closed | ||
sigc := make(chan os.Signal) | ||
signal.Notify(sigc, os.Interrupt) | ||
select { | ||
case <-sigc: | ||
case <-ui.Done(): | ||
} | ||
|
||
YouTubeDownloader.Clean() | ||
} |
Oops, something went wrong.