Skip to content

Commit

Permalink
fix: default download size 1Mb > 10Mb
Browse files Browse the repository at this point in the history
  • Loading branch information
Davincible authored and corny committed May 4, 2023
1 parent 3509e5f commit cd26881
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (c *Client) getChunkSize() int64 {
return c.ChunkSize
}

return Size1Mb
return Size10Mb
}

func (c *Client) getMaxRoutines(limit int) int {
Expand Down
49 changes: 20 additions & 29 deletions video_test.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,55 @@
package youtube

import (
"fmt"
"io"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestChunk(t *testing.T) {
fmt.Println(getChunks(100, 10))
}

func TestSimpleTest(t *testing.T) {
client := Client{Debug: true, ChunkSize: Size10Mb}
func ExampleClient_GetStream() {
client := Client{Debug: true}

video, err := client.GetVideo("https://www.youtube.com/watch?v=BaW_jenozKc")
video, err := client.GetVideo("https://www.youtube.com/watch?v=9_MbW9FK1fA")
if err != nil {
panic(err)
}

// Typically youtube only provides separate streams for video and audio.
// If you want audio and video combined, take a look a the downloader package.
format := video.Formats.FindByQuality("hd1080")

start := time.Now()
format := video.Formats.FindByQuality("medium")
reader, _, err := client.GetStream(video, format)
require.NoError(t, err, "get stream")

fmt.Println("Duration Milliseconds: ", time.Since(start).Milliseconds())

// do something with the reader
b, err := io.ReadAll(reader)
if err != nil {
panic(err)
}

fmt.Println("Downloaded ", len(b))
// do something with the reader

reader.Close()
}

func ExampleClient_GetStream() {
client := Client{Debug: true}
func TestSimpleTest(t *testing.T) {
client := Client{Debug: true, ChunkSize: Size10Mb}

video, err := client.GetVideo("https://www.youtube.com/watch?v=9_MbW9FK1fA")
if err != nil {
panic(err)
}
video, err := client.GetVideo("https://www.youtube.com/watch?v=BaW_jenozKc")
require.NoError(t, err, "get body")

// Typically youtube only provides separate streams for video and audio.
// If you want audio and video combined, take a look a the downloader package.
format := video.Formats.FindByQuality("medium")
format := video.Formats.FindByQuality("hd1080")

start := time.Now()
reader, _, err := client.GetStream(video, format)
if err != nil {
panic(err)
}
require.NoError(t, err, "get stream")

t.Log("Duration Milliseconds: ", time.Since(start).Milliseconds())

// do something with the reader
b, err := io.ReadAll(reader)
require.NoError(t, err, "read body")

reader.Close()
t.Log("Downloaded ", len(b))
}

func TestDownload_Regular(t *testing.T) {
Expand Down

0 comments on commit cd26881

Please sign in to comment.