Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Change file mode
Browse files Browse the repository at this point in the history
  • Loading branch information
roy2100 committed Jun 2, 2022
1 parent f73e0c0 commit ccfbe91
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"fmt"
"log"
"math/rand"
"net/url"
"os"
"strings"
"sync"
"time"

"github.com/nanlei2000/douyin_download/pkg/douyin"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -86,6 +88,9 @@ func main() {
<-c
}()

ran := rand.Int31n(100)
time.Sleep(time.Duration(ran) * time.Millisecond)

video, err := dy.Get(douyin.Source{
Type: douyin.SourceType_VideoID,
Content: id,
Expand Down
2 changes: 2 additions & 0 deletions pkg/douyin/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (d *DouYin) GetAllVideoIDList(secUid string) ([]string, error) {
}
defer resp.Body.Close()

d.printf("resp status: %s", resp.Status)

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("fail to read body, secUid: %s, err: %s", secUid, err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/douyin/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
)

func TestGetAllVideoIDList(t *testing.T) {
dy := DouYin{}
dy := NewDouYin()
dy.isDebug = true

list, err := dy.GetAllVideoIDList("MS4wLjABAAAAF0HqDm-8U9TiT_9AfqqPGiNbrP0c93AdB3_oRG7Em_Q")

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/douyin/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func (v *Video) Download(filename string) (string, error) {
dir := filepath.Dir(filename)

if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0655); err != nil {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return "", err
}
}
//如果是图片类,则将图片下载到指定目录
if v.VideoType == ImagePlayType {
imagePath := filepath.Join(dir, v.VideoId)
if err := os.MkdirAll(imagePath, 0655); err != nil {
if err := os.MkdirAll(imagePath, os.ModePerm); err != nil {
log.Printf("创建目录失败 [path=%s]", imagePath)
}
for _, image := range v.Images {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (v *Video) Download(filename string) (string, error) {
continue
}
_ = resp.Body.Close()
err = ioutil.WriteFile(imageName, b, 0655)
err = ioutil.WriteFile(imageName, b, os.ModePerm)
if err != nil {
log.Printf("保存图像出错 -> [play_id=%s] [image_url=%s]", v.PlayId, image.ImageUrl)
continue
Expand Down

0 comments on commit ccfbe91

Please sign in to comment.