forked from mxpv/podsync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
254 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.20 as builder | ||
FROM golang:1.22 as builder | ||
|
||
ENV TAG="nightly" | ||
ENV COMMIT="" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
|
||
"strconv" | ||
"time" | ||
|
||
"github.com/mxpv/podsync/pkg/feed" | ||
"github.com/pkg/errors" | ||
"github.com/yangtfu/bilibili/v3" | ||
|
||
"github.com/mxpv/podsync/pkg/model" | ||
) | ||
|
||
type BilibiliBuilder struct { | ||
client *bilibili.Client | ||
} | ||
|
||
func (b *BilibiliBuilder) queryFeed(feed *model.Feed, info *model.Info) error { | ||
switch info.LinkType { | ||
case model.TypeChannel: | ||
//TODO channel surpport | ||
return errors.New("Bilibili channel not supported.") | ||
case model.TypeUser: | ||
// query user info | ||
mid, err := strconv.Atoi(info.ItemID) | ||
if err != nil { | ||
return err | ||
} | ||
userCardParam := bilibili.GetUserCardParam{Mid: mid, Photo: false} | ||
userCard, err := b.client.GetUserCard(userCardParam) | ||
if err != nil { | ||
return err | ||
} | ||
feed.Author = userCard.Card.Name | ||
feed.CoverArt = userCard.Card.Face | ||
feed.Title = userCard.Card.Name | ||
feed.Description = userCard.Card.Sign | ||
// query video collection | ||
videoParam := bilibili.GetVideoByKeywordsParam{Mid: mid, Keywords: "", Ps: feed.PageSize} | ||
videoCollection, err := b.client.GetVideoByKeywords(videoParam) | ||
if err != nil { | ||
return err | ||
} | ||
feed.PubDate = time.Unix(int64(videoCollection.Archives[0].Pubdate), 0) | ||
for _, videoInfo := range videoCollection.Archives { | ||
bvid := videoInfo.Bvid | ||
desc, err := b.client.GetVideoDesc(bilibili.VideoParam{Bvid: bvid}) | ||
if err == nil { | ||
e := model.Episode{ | ||
ID: videoInfo.Bvid, | ||
Title: videoInfo.Title, | ||
Description: desc, | ||
Duration: int64(videoInfo.Duration), | ||
Size: int64(videoInfo.Duration * 15000), // very rough estimate | ||
VideoURL: "https://www.bilibili.com/" + videoInfo.Bvid, | ||
PubDate: time.Unix(int64(videoInfo.Pubdate), 0), | ||
Thumbnail: videoInfo.Pic, | ||
Status: model.EpisodeNew, | ||
} | ||
feed.Episodes = append(feed.Episodes, &e) | ||
} | ||
} | ||
|
||
return nil | ||
default: | ||
return errors.New("unsupported link format") | ||
} | ||
} | ||
|
||
func (b *BilibiliBuilder) Build(ctx context.Context, cfg *feed.Config) (*model.Feed, error) { | ||
info, err := ParseURL(cfg.URL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_feed := &model.Feed{ | ||
ItemID: info.ItemID, | ||
Provider: info.Provider, | ||
LinkType: info.LinkType, | ||
Format: cfg.Format, | ||
Quality: cfg.Quality, | ||
CoverArtQuality: cfg.Custom.CoverArtQuality, | ||
PageSize: cfg.PageSize, | ||
PlaylistSort: cfg.PlaylistSort, | ||
PrivateFeed: cfg.PrivateFeed, | ||
UpdatedAt: time.Now().UTC(), | ||
ItemURL: cfg.URL, | ||
} | ||
|
||
// Query general information about feed (title, description, lang, etc) | ||
if err := b.queryFeed(_feed, &info); err != nil { | ||
return nil, err | ||
} | ||
|
||
return _feed, nil | ||
} | ||
|
||
func NewBilibiliBuilder() (*BilibiliBuilder, error) { | ||
sc := bilibili.New() | ||
|
||
return &BilibiliBuilder{client: sc}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package builder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mxpv/podsync/pkg/feed" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBilibili_BuildFeed(t *testing.T) { | ||
builder, err := NewBilibiliBuilder() | ||
require.NoError(t, err) | ||
|
||
urls := []string{ | ||
"https://space.bilibili.com/1302298364", | ||
"https://space.bilibili.com/397490386/channel/seriesdetail?sid=1203833", | ||
} | ||
|
||
t.Run(urls[0], func(t *testing.T) { | ||
feed, err := builder.Build(testCtx, &feed.Config{URL: urls[0]}) | ||
require.NoError(t, err) | ||
|
||
assert.NotEmpty(t, feed.Title) | ||
assert.NotEmpty(t, feed.Description) | ||
assert.NotEmpty(t, feed.Author) | ||
assert.NotEmpty(t, feed.ItemURL) | ||
|
||
assert.NotZero(t, len(feed.Episodes)) | ||
|
||
for _, item := range feed.Episodes { | ||
assert.NotEmpty(t, item.Title) | ||
assert.NotEmpty(t, item.VideoURL) | ||
assert.NotZero(t, item.Duration) | ||
assert.NotEmpty(t, item.Title) | ||
assert.NotEmpty(t, item.Thumbnail) | ||
} | ||
}) | ||
|
||
t.Run(urls[1], func(t *testing.T) { | ||
_, err := builder.Build(testCtx, &feed.Config{URL: urls[1]}) | ||
require.Error(t, err, "Bilibili channel not supported.") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
669d559
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好作者。感谢分享。我用了docker方式部署,但是报错了,应该是dns解析的问题,但是我不知道如何在配置层面修复。你的环境下,这样部署有没有问题?希望得到你的回复。谢谢。
这是docker compose文件:
version: '3.9'
services:
podsync:
image: 'ghcr.io/yangtfu/podsync:nightly'
volumes:
- './config.toml:/app/config.toml'
- './data:/app/data/'
ports:
- '8080:8080'
这是容器配置文件config.toml,照抄你的,没有改动
[server]
port = 8080
hostname = "我的ip" # 此处填写 IP 地址或者域名,如果有HTTPS证书的话记得改成 https://
data_dir = "/app/data" # docker内数据存放目录,对应映射到宿主机目录,不建议改动
Tokens from
Access tokens
section[tokens]
youtube = "我的token" # 引号内填写 YouTube API Key.
bilibili= "123" #由于不想破坏源代码结构,必须给B站定义一个key,可填写任意字符串,不能为空
[feeds]
[feeds.ID1]
ID1 为最终生成的RSS文件的名称,可以修改
url = "www.youtube.com/channel/UCtAIPjABiQD3qjlEl1T5VpA" # 引号内填写Youtube频道/组织/用户/播放列表的链接,注意不要有 http:// 部分!!!
page_size = 10 # 每次更新节目时的分页大小
update_period = "12h" # 更新周期,例如: "60m", "4h", "2h45m"
cron_schedule = "0 1,7,11,16 * * *" #crontab更新方式
quality = "high" # 文件品质高-high,或低-low
format = "audio" # 文件类型音频-audio,视频-video,通常播客使用音频类型即可
filters = { title = "111", not_title = "222", description = "333", not_description = "444" } # [可选项,使用时去除行首井号]过滤节目,只保留「标题含有111,不含222,描述包含 333,不含 444 的节目」
clean = { keep_last = 10 } # 自动清理,只保留最近10期节目
private_feed = true #是否私有,非私有的话会可以被iTunes等客户端搜索到,建议true
可以配置多个 feeds
[feeds.ID2]
url = "https://space.bilibili.com/3537109151386355" #要订阅的B站用户主页链接
#全部同上
page_size = 10
cron_schedule = "0 1,7,11,16 * * *"
quality = "high" # "high" or "low"
format = "audio" # "audio", "video" or "custom"
filters = {}
opml = true
clean = { keep_last = 20 }
private_feed = true
[database]
badger = { truncate = true, file_io = true } # 数据库配置,无需改动
[downloader]
self_update = true # 自动更新下载程序
程序运行日志配置,无需改动
[log]
filename = "podsync.log"
max_size = 50 # MB
max_age = 30 # days
max_backups = 7
compress = true
这是容器里面的日志:
/app # tail -f podsync.log
time="2025-01-21T12:20:41Z" level=info msg="found ffmpeg: ffmpeg version 5.1.4 Copyright (c) 2000-2023 the FFmpeg developers\nbuilt with gcc 12.2.1 (Alpine 12.2.1_git20220924-r4) 20220924\nconfiguration: --prefix=/usr --enable-avfilter --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gnutls --enable-gpl --enable-libass --enable-libmp3lame --enable-libpulse --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libx264 --enable-libx265 --enable-libtheora --enable-libv4l2 --enable-libdav1d --enable-lto --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-libxcb --enable-librist --enable-libsrt --enable-libssh --enable-libvidstab --disable-stripping --disable-static --disable-librtmp --disable-lzma --enable-libaom --enable-libopus --enable-libsoxr --enable-libwebp --enable-vaapi --enable-vdpau --enable-vulkan --enable-libdrm --enable-libzmq --optflags=-O2 --disable-debug --enable-libsvtav1\nlibavutil 57. 28.100 / 57. 28.100\nlibavcodec 59. 37.100 / 59. 37.100\nlibavformat 59. 27.100 / 59. 27.100\nlibavdevice 59. 7.100 / 59. 7.100\nlibavfilter 8. 44.100 / 8. 44.100\nlibswscale 6. 7.100 / 6. 7.100\nlibswresample 4. 7.100 / 4. 7.100\nlibpostproc 56. 6.100 / 56. 6.100\n"
time="2025-01-21T12:20:41Z" level=info msg="updating youtube-dl"
time="2025-01-21T12:20:47Z" level=error msg="[debug] Command-line config: ['--update', '--verbose']\n[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8 (No ANSI), error utf-8 (No ANSI), screen utf-8 (No ANSI)\n[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [c8541f8b1] (zip)\n[debug] Python 3.10.15 (CPython x86_64 64bit) - Linux-3.10.0-1160.90.1.el7.x86_64-x86_64-with (OpenSSL 3.0.15 3 Sep 2024)\n[debug] exe versions: ffmpeg 5.1.4 (setts), ffprobe 5.1.4\n[debug] Optional libraries: sqlite3-3.40.1\n[debug] Proxy map: {}\n[debug] Request Handlers: urllib\n[debug] Loaded 1837 extractors\n[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest\nERROR: Unable to obtain version info ([Errno -3] Try again); Please try again later or visit https://github.com/yt-dlp/yt-dlp/releases/latest\n" error="failed to execute youtube-dl: exit status 100"
time="2025-01-21T12:20:47Z" level=error msg="failed to update youtube-dl" error="failed to self update youtube-dl: failed to execute youtube-dl: exit status 100"
time="2025-01-21T12:20:47Z" level=info msg="opening database "db""
time="2025-01-21T12:20:47Z" level=info msg="All 0 tables opened in 0s\n"
time="2025-01-21T12:20:47Z" level=info msg="running listener at :8080"
time="2025-01-21T12:20:47Z" level=info msg="-> updating www.youtube.com/channel/UCtAIPjABiQD3qjlEl1T5VpA" feed_id=ID1 format=audio quality=high
time="2025-01-21T12:20:55Z" level=error msg="failed to update feed: www.youtube.com/channel/UCtAIPjABiQD3qjlEl1T5VpA" error="update failed: failed to query channel: Get "https://www.googleapis.com/youtube/v3/channels?alt=json&id=UCtAIPjABiQD3qjlEl1T5VpA&key=XriA7WSI3qOLkXriA7WSI3qOLkXriA7WSI3qOLk&part=id%2Csnippet%2CcontentDetails\": dial tcp: lookup www.googleapis.com on 127.0.0.11:53: server misbehaving"
time="2025-01-21T12:20:55Z" level=info msg="-> updating https://space.bilibili.com/3537109151386355" feed_id=ID2 format=audio quality=high
time="2025-01-21T12:21:03Z" level=error msg="failed to update feed: https://space.bilibili.com/3537109151386355" error="update failed: Get "https://api.bilibili.com/x/web-interface/card?mid=3537109151386355\": dial tcp: lookup api.bilibili.com on 127.0.0.11:53: server misbehaving"
669d559
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这个youtube-dl都下载不下来,应该事网络问题,跟podsync没关系啊
669d559
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.