Skip to content

Commit

Permalink
release: fix client panic
Browse files Browse the repository at this point in the history
  • Loading branch information
norwnd committed May 28, 2023
1 parent ce3bbfa commit b30b579
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print
## help: Show makefile commands
.PHONY: help
help: Makefile
@echo "---- Project: kkdai/youtube ----"
@echo "---- Project: norwnd/youtube ----"
@echo " Usage: make COMMAND"
@echo
@echo " Management Commands:"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Download Youtube Video in Golang
==================

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/kkdai/youtube/master/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/kkdai/youtube.svg)](https://pkg.go.dev/github.com/kkdai/youtube/v2)
[![Build Status](https://github.com/kkdai/youtube/workflows/go/badge.svg?branch=master)](https://github.com/kkdai/youtube/actions)
[![Coverage](https://codecov.io/gh/kkdai/youtube/branch/master/graph/badge.svg)](https://codecov.io/gh/kkdai/youtube)
[![](https://goreportcard.com/badge/github.com/kkdai/youtube)](https://goreportcard.com/badge/github.com/kkdai/youtube)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/norwnd/youtube/master/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/norwnd/youtube.svg)](https://pkg.go.dev/github.com/norwnd/youtube/v2)
[![Build Status](https://github.com/norwnd/youtube/workflows/go/badge.svg?branch=master)](https://github.com/norwnd/youtube/actions)
[![Coverage](https://codecov.io/gh/norwnd/youtube/branch/master/graph/badge.svg)](https://codecov.io/gh/norwnd/youtube)
[![](https://goreportcard.com/badge/github.com/norwnd/youtube)](https://goreportcard.com/badge/github.com/norwnd/youtube)


This package is a Youtube video download package, for more detail refer [https://github.com/ytdl-org/youtube-dl](https://github.com/ytdl-org/youtube-dl) for more download options.
Expand All @@ -24,13 +24,13 @@ This tool is meant to be used to download CC0 licenced content, we do not suppor
Please ensure you have installed Go 1.18 or later.

```shell
go get github.com/kkdai/youtube/v2
go get github.com/norwnd/youtube/v2
```

### From source code

```shell
git clone https://github.com/kkdai/youtube.git
git clone https://github.com/norwnd/youtube.git
cd youtube
go run ./cmd/youtubedr
```
Expand Down Expand Up @@ -69,7 +69,7 @@ Please check out the [example_test.go](example_test.go) for example code.
## Example:
* ### Get information of dotGo-2015-rob-pike video for downloading

`go get github.com/kkdai/youtube/v2/youtubedr`
`go get github.com/norwnd/youtube/v2/youtubedr`

Download video from [dotGo 2015 - Rob Pike - Simplicity is Complicated](https://www.youtube.com/watch?v=rFejpH_tAHM)

Expand All @@ -87,7 +87,7 @@ Please check out the [example_test.go](example_test.go) for example code.
```
* ### Download dotGo-2015-rob-pike-video

`go get github.com/kkdai/youtube/v2/youtubedr`
`go get github.com/norwnd/youtube/v2/youtubedr`

Download video from [dotGo 2015 - Rob Pike - Simplicity is Complicated](https://www.youtube.com/watch?v=rFejpH_tAHM)

Expand All @@ -97,7 +97,7 @@ Please check out the [example_test.go](example_test.go) for example code.

* ### Download video to specific folder and name

`go get github.com/kkdai/youtube/v2/youtubedr`
`go get github.com/norwnd/youtube/v2/youtubedr`

Download video from [dotGo 2015 - Rob Pike - Simplicity is Complicated](https://www.youtube.com/watch?v=rFejpH_tAHM) to current directory and name the file to simplicity-is-complicated.mp4

Expand All @@ -107,7 +107,7 @@ Please check out the [example_test.go](example_test.go) for example code.

* ### Download video with specific quality

`go get github.com/kkdai/youtube/v2/youtubedr`
`go get github.com/norwnd/youtube/v2/youtubedr`

Download video from [dotGo 2015 - Rob Pike - Simplicity is Complicated](https://www.youtube.com/watch?v=rFejpH_tAHM) with specific quality

Expand All @@ -125,7 +125,7 @@ Please check out the [example_test.go](example_test.go) for example code.

* ### Download video with specific itag

`go get github.com/kkdai/youtube/v2/youtubedr`
`go get github.com/norwnd/youtube/v2/youtubedr`

Download video from [dotGo 2015 - Rob Pike - Simplicity is Complicated](https://www.youtube.com/watch?v=rFejpH_tAHM)

Expand Down Expand Up @@ -154,7 +154,7 @@ Please check out the [example_test.go](example_test.go) for example code.


## Project52
It is one of my [project 52](https://github.com/kkdai/project52).
It is one of my [project 52](https://github.com/norwnd/project52).


## License
Expand Down
10 changes: 8 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ func (c *Client) GetStreamURL(video *Video, format *Format) (string, error) {

// GetStreamURLContext returns the url for a specific format with a context
func (c *Client) GetStreamURLContext(ctx context.Context, video *Video, format *Format) (string, error) {
c.assureClient()

if format == nil {
return "", ErrNoFormat
}
Expand Down Expand Up @@ -613,15 +615,19 @@ func (c *Client) httpPostBodyBytes(ctx context.Context, url string, body interfa

// downloadChunk returns the chunk bytes.
// Downloading in multiple chunks is much faster:
// https://github.com/kkdai/youtube/pull/190
// https://github.com/norwnd/youtube/pull/190
func (c *Client) downloadChunk(req *http.Request, chunk chunk) ([]byte, error) {
q := req.URL.Query()
q.Set("range", fmt.Sprintf("%d-%d", chunk.start, chunk.end))
req.URL.RawQuery = q.Encode()

resp, err := c.httpDo(req)
if err != nil {
return nil, ErrUnexpectedStatusCode(resp.StatusCode)
statusCode := 0 // unknown
if resp != nil {
statusCode = resp.StatusCode
}
return nil, fmt.Errorf("unexpected error in downloadChunk, status code: %d, err: %w", statusCode, err)
}
defer resp.Body.Close()

Expand Down
4 changes: 2 additions & 2 deletions cmd/youtubedr/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/spf13/pflag"
"golang.org/x/net/http/httpproxy"

"github.com/kkdai/youtube/v2"
ytdl "github.com/kkdai/youtube/v2/downloader"
"github.com/norwnd/youtube/v2"
ytdl "github.com/norwnd/youtube/v2/downloader"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion decipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *Client) decipherURL(ctx context.Context, videoID string, cipher string)
return uri.String(), nil
}

// see https://github.com/kkdai/youtube/pull/244
// see https://github.com/norwnd/youtube/pull/244
func (c *Client) unThrottle(ctx context.Context, videoID string, urlString string) (string, error) {
config, err := c.getPlayerConfig(ctx, videoID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os/exec"
"path/filepath"

"github.com/kkdai/youtube/v2"
"github.com/norwnd/youtube/v2"
"github.com/vbauerster/mpb/v5"
"github.com/vbauerster/mpb/v5/decor"
)
Expand Down
2 changes: 1 addition & 1 deletion downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/kkdai/youtube/v2"
"github.com/norwnd/youtube/v2"
)

var testDownloader = func() (dl Downloader) {
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

"github.com/kkdai/youtube/v2"
"github.com/norwnd/youtube/v2"
)

// ExampleDownload : Example code for how to use this package for download video.
Expand Down
2 changes: 1 addition & 1 deletion format_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func sortFormat(i int, j int, formats FormatList) bool {
// Sort by Width
if formats[i].Width == formats[j].Width {
// Format 137 downloads slowly, give it less priority
// see https://github.com/kkdai/youtube/pull/171
// see https://github.com/norwnd/youtube/pull/171
switch 137 {
case formats[i].ItagNo:
return false
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/kkdai/youtube/v2
module github.com/norwnd/youtube/v2

go 1.19

Expand Down
2 changes: 1 addition & 1 deletion video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestDownload_WhenPlayabilityStatusIsNotOK(t *testing.T) {
}
}

// See https://github.com/kkdai/youtube/pull/238
// See https://github.com/norwnd/youtube/pull/238
func TestDownload_SensitiveContent(t *testing.T) {
_, err := testClient.GetVideo("MS91knuzoOA")
require.EqualError(t, err, "can't bypass age restriction: embedding of this video has been disabled")
Expand Down

0 comments on commit b30b579

Please sign in to comment.