Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ $ lux -j "https://www.bilibili.com/video/av20203945"
-o string
Specify the output path
-O string
Specify the output file name
Specify the output file name. supports placeholder %author %date %title.
```

#### Subtitle:
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func New() *cli.App {
func download(c *cli.Context, videoURL string) error {
data, err := extractors.Extract(videoURL, extractors.Options{
Playlist: c.Bool("playlist"),
AudioOnly: c.Bool("audio-only"),
Items: c.String("items"),
ItemStart: int(c.Uint("start")),
ItemEnd: int(c.Uint("end")),
Expand Down
23 changes: 20 additions & 3 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
"encoding/binary"
"encoding/json"
"fmt"
"github.com/cheggaaa/pb/v3"

Check failure on line 8 in downloader/downloader.go

View workflow job for this annotation

GitHub Actions / Go 1.24 in ubuntu-latest

File is not properly formatted (goimports)
"github.com/pkg/errors"
"io"
"net/http"
"os"
"path"
"path/filepath"
"regexp"
"sort"
"strings"
"sync"
"time"

"github.com/cheggaaa/pb/v3"
"github.com/pkg/errors"

"github.com/iawia002/lux/extractors"
"github.com/iawia002/lux/request"
"github.com/iawia002/lux/utils"
Expand Down Expand Up @@ -558,9 +558,26 @@
return nil
}

/*title := downloader.option.OutputName
if title == "" {
title = data.Title
}*/
title := downloader.option.OutputName
if title == "" {
title = data.Title
} else {
// 创建占位符映射
placeholders := map[string]string{
"%title": data.Title,
// 可以根据需要添加更多占位符
"%author": data.Author,
"%date": data.Date,
}

// 替换所有占位符
for placeholder, value := range placeholders {
title = strings.ReplaceAll(title, placeholder, value)
}
}
title = utils.FileName(title, "", downloader.option.FileNameLength)

Expand Down
13 changes: 13 additions & 0 deletions extractors/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,17 @@
return extractors.EmptyData(options.url, err)
}
title := parser.Title(doc)
var author = strings.TrimSpace(doc.Find("a.up-name").Text())
var datePart = doc.Find("div.pubdate-ip-text").Text()
if len(strings.TrimSpace(datePart)) > 0 {
parts := strings.Split(datePart, " ")
// 获取第一部分,即年月日
if len(parts) > 0 {
datePart = parts[0]
}
}
//title = fmt.Sprintf("%s %s", datePart, title)
title = fmt.Sprintf("%s", title)

Check failure on line 498 in extractors/bilibili/bilibili.go

View workflow job for this annotation

GitHub Actions / Go 1.24 in ubuntu-latest

S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
if options.subtitle != "" {
pageString := ""
if options.page > 0 {
Expand All @@ -500,6 +511,8 @@
return &extractors.Data{
Site: "哔哩哔哩 bilibili.com",
Title: title,
Date: datePart,
Author: author,
Type: extractors.DataTypeVideo,
Streams: streams,
Captions: map[string]*extractors.CaptionPart{
Expand Down
17 changes: 13 additions & 4 deletions extractors/bilibili/bilibili_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

func TestBilibili(t *testing.T) {
tests := []struct {
name string
args test.Args
playlist bool
name string
args test.Args
playlist bool
audioonly bool
}{
{
name: "normal test 1",
Expand All @@ -27,7 +28,8 @@ func TestBilibili(t *testing.T) {
URL: "https://www.bilibili.com/video/av41301960",
Title: "【英雄联盟】2019赛季CG 《觉醒》",
},
playlist: false,
playlist: false,
audioonly: true,
},
{
name: "bangumi test",
Expand Down Expand Up @@ -87,6 +89,13 @@ func TestBilibili(t *testing.T) {
ThreadNumber: 9,
})
test.CheckError(t, err)
}
if tt.audioonly {
// for playlist, we don't check the data
_, err = New().Extract(tt.args.URL, extractors.Options{
AudioOnly: true,
})
test.CheckError(t, err)
} else {
data, err = New().Extract(tt.args.URL, extractors.Options{})
test.CheckError(t, err)
Expand Down
13 changes: 9 additions & 4 deletions extractors/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ const (
// Data is the main data structure for the whole video data.
type Data struct {
// URL is used to record the address of this download
URL string `json:"url"`
Site string `json:"site"`
Title string `json:"title"`
Type DataType `json:"type"`
URL string `json:"url"`
Site string `json:"site"`
Title string `json:"title"`
Author string `json:"author"`
Date string `json:"date"`
Type DataType `json:"type"`
// each stream has it's own Parts and Quality
Streams map[string]*Stream `json:"streams"`
// danmaku, subtitles, etc
Expand Down Expand Up @@ -116,6 +118,9 @@ type Options struct {
// EpisodeTitleOnly indicates file name of each bilibili episode doesn't include the playlist title
EpisodeTitleOnly bool

// AudioOnly
AudioOnly bool

YoukuCcode string
YoukuCkey string
YoukuPassword string
Expand Down
Loading