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

Organize video into Lessons #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,33 @@ Kindly create your account [here](https://courses.calhoun.io/signup?). Jon is a

To install this package run

```bash
$ go get -u github.com/timolinn/joncalhoun-dl
```sh
$ go get -u github.com/timolinn/joncalhoun-dl
```

### To build from source run

```bash
$ git clone [email protected]:timolinn/joncalhoun-dl.git
$ cd joncalhoun-dl
$ go build .
```sh
$ git clone [email protected]:timolinn/joncalhoun-dl.git
$ cd joncalhoun-dl
$ go build .
```

## How to use

If you installed via `go get`, you can simply run

```bash
$ joncalhoun-dl [email protected] -password=12345 -course=gophercises -output=your-chosen-directory
[joncalhoun-dl]: fetching video urls for gophercises
[joncalhoun-dl]: fetching data from https://courses.calhoun.io/courses/cor_gophercises...
```sh
$ joncalhoun-dl [email protected] -password=12345 -course=gophercises -output=your-chosen-directory
[joncalhoun-dl]: fetching video urls for gophercises
[joncalhoun-dl]: fetching data from https://courses.calhoun.io/courses/cor_gophercises...
```

If you built from source, the compiled binary should be in the current folder.

```bash
$ ./joncalhoun-dl [email protected] -password=12345 -course=gophercises -output=your-chosen-directory
[joncalhoun-dl]: fetching video urls for gophercises
[joncalhoun-dl]: fetching data from https://courses.calhoun.io/courses/cor_gophercises...
```sh
$ ./joncalhoun-dl [email protected] -password=12345 -course=gophercises -output=your-chosen-directory[joncalhoun-dl]: fetching video urls for gophercises
[joncalhoun-dl]: fetching data from https://courses.calhoun.io/courses/cor_gophercises...
```

Also note, video downloads **resumes** from where it stopped, so should you experience network interruption nothing to worry about just make sure the output directory remains the same.
Expand Down Expand Up @@ -77,8 +76,8 @@ If you find a bug please create an [issue](https:/timolinn/joncalhou

To run existing tests

```bash
$ go test
```sh
$ go test
```

## TODO
Expand All @@ -92,6 +91,7 @@ To run existing tests
+ [ ] prevent signin when using cache
+ [ ] choose video quality
+ [ ] reduce cache size by storing fewer data
+ [ ] delete cache folder after download finishes

### Authors

Expand Down
27 changes: 27 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os/exec"
"strings"
"time"
"path/filepath"

"github.com/PuerkitoBio/goquery"
"golang.org/x/net/publicsuffix"
Expand Down Expand Up @@ -131,6 +132,32 @@ func main() {
fmt.Printf("[joncalhoun-dl]: Page for lesson 0%d does not have an embedded video \n", i+1)
}
}

os.Chdir(*outputdir)

files, _ := filepath.Glob("*.mp4")

for _, file := range files {

slc := strings.Split(file, "-")
for i := range slc {
slc[i] = strings.TrimSpace(slc[i])
}

lesson := strings.Join(slc[:2], " ")
video := strings.Join(slc[2:], " ")

// Create lesson directory if it does not exist yet
if !dirExists(*outputdir + "/" + lesson) {
err := os.Mkdir(*outputdir+"/"+lesson, 0755)
checkError(err)
}

fmt.Printf("[joncalhoun-dl]: Moving %s to %s/%s\n", file, lesson, video)

os.Rename(file, lesson+"/"+video)
}

fmt.Println("Done! 🚀")
}

Expand Down