Project Icon

ydls

灵活多功能的在线媒体处理平台

ydls项目提供了一个基于yt-dlp的HTTP服务,实现了多源媒体下载、流传输、转封装和转码功能。系统集成了丰富的格式和编解码器支持,可应用于媒体格式转换、播客制作和音频提取等领域。通过简洁而强大的API设计,开发者能够精确控制输出格式、编解码器选择和时间段截取,为各类媒体处理任务提供灵活解决方案。

youtube-dl HTTP service

HTTP service for yt-dlp that downloads media from requested URL and streams, transmux and transcode to requested format if needed.

It can be used to convert media, create podcasts and audio only versions of media from various site like youtube, vimeo etc.

Docker image uses ffmpeg from wader/static-ffmpeg which can handle most format and codecs. Default configuration can transcode to these format, container and codecs:

FormatContainerAudioVideoSubtitle
alacmp4alac
flacflacflac
gifgifgif
m4amp4aac
mp3mp3mp3
oggoggvorbis, opus
wavwavpcm_s16le
mkvmatroskaaac, alac, ac3, mp3, vorbis, opus, flach264, hevc, vp8, vp9, theora, av1subrip, ass
mp4mp4aac, alac, mp3, vorbis, flach264, vp9, av1, hevcmov_text
mxfmxfpcm_s16lempeg2video
tsmpegtsaac, mp3, ac3h264, hevc
webmwebmvorbis, opusvp8, av1, vp9webvtt
rssmp3mp3

The rss format transforms a playlist into a RSS audio podcast.

See ydls.json for more details.

Usage

Run with docker

Pull mwader/ydls or build image using the Dockerfile. Run a container and publish TCP port 8080 somehow.

docker run -p 8080:8080 mwader/ydls

Build and install yourself

Run go get github.com/wader/ydls/cmd/ydls to install ydls. Make sure you have ffmpeg, yt-dlp, rtmpdump and mplayer installed and in PATH.

Copy and edit ydls.json to match your ffmpeg builds supported formats and codecs.

Start with ydls -server -config /path/to/ydls.json and it default will listen on port 8080.

Endpoints

Download and make sure media is in specified format:
GET /<format>[+option+option...]/<URL-not-encoded>
GET /?format=<format>&url=<URL>[&codec=...&codec=...&retranscode=...]

Download in best format:
GET /<URL-not-encoded>
GET /?url=<URL-encoded>

Parameters

format - Format name. See table above and ydls.json
URL - Any URL that yt-dlp can handle
URL-not-encoded - Non-URL-encoded URL. The idea is to be able to simply prepend the download URL with the ydls URL by hand without doing any encoding (for example in the browser location bar)
codec - Codec to use instead of default for format (can be specified one or two times for audio and video codec)
retranscode - Retranscode even if input codec is same as output
time - Only download specificed time range. Ex: 30s, 20m30s, 1h20m30s will limit duration. 10s-30s will seek 10 seconds and stop at 30 seconds (20 second output duration)
items - If playlist only include this many items

option - Codec name, time range, retranscode or <N>items

Examples

Download and make sure media is in mp3 format:
http://ydls/mp3/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download using query parameters and make sure media is in mp3 format:
http://ydls/?format=mp3&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcF1zJYkBW4A

Download and make sure media is in webm format:
http://ydls/webm/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download and make sure media is in mkv format using mp3 and h264 codecs:
http://ydls/mkv+mp3+h264/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download and retranscode to mp3 even if input is already mp3:
http://ydls/mp3+retranscode/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download specified time range in mp3:
http://ydls/mp3+10s-30s/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download in best format:
http://ydls/https://www.youtube.com/watch?v=cF1zJYkBW4A

Playlist as audio podcast with 3 latest items:
http://ydls/rss+3items/https://www.youtube.com/watch?list=PLtLJO5JKE5YCYgIdpJPxNzWxpMuUWgbVi

Tricks and known issues

For some formats the transcoded file might have zero length or duration as transcoding is done while streaming. This is usually not a problem for most players.

Download with curl and save to filename provided by response header:

curl -OJ http://ydls-host/mp3/https://www.youtube.com/watch?v=cF1zJYkBW4A

Docker image can download from command line. This will download in mp3 format to current directory:

docker run --rm -v "$PWD:$PWD" -w "$PWD" mwader/ydls https://www.youtube.com/watch?v=cF1zJYkBW4A mp3

yt-dlp URL can point to a plain media file.

If you run the service using some cloud services you might run into geo-restriction issues with some sites like youtube.

Development

When fiddling with ffmpeg and yt-dlp related code I usually do this:

docker build --target ydls-dev -t ydls-dev . && docker run --rm -ti -v "$PWD:/$PWD" -w "$PWD" ydls-dev

Then inside dev container:

# run cli version
go run cmd/ydls/main.go -config ./ydls.json -debug
# run all tests
CONFIG="$PWD/ydls.json" TEST_EXTERNAL=1 go test -v -cover -race ./...

TODO

  • Optional stream for format? example mp4 at least video or audio?
  • Download playlist as zip archive.
  • JSON output?
  • Refactor messy downloadFormat function. Maybe a media interface with audio, video and subtitle implementations that select best format and return reader and mappings? should share a common format picker so formats can be shared and not re-downloaded.
  • Make download part into an interface to support more than yt-dlp.
  • Bitrate factor per codec when sorting formats (prefer aac over mp3 at same bitrate etc)
  • X-Remote IP header?

License

ydls is licensed under the MIT license. See LICENSE for the full license text.

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

白日梦AI

白日梦AI提供专注于AI视频生成的多样化功能,包括文生视频、动态画面和形象生成等,帮助用户快速上手,创造专业级内容。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

讯飞绘镜

讯飞绘镜是一个支持从创意到完整视频创作的智能平台,用户可以快速生成视频素材并创作独特的音乐视频和故事。平台提供多样化的主题和精选作品,帮助用户探索创意灵感。

Project Cover

讯飞文书

讯飞文书依托讯飞星火大模型,为文书写作者提供从素材筹备到稿件撰写及审稿的全程支持。通过录音智记和以稿写稿等功能,满足事务性工作的高频需求,帮助撰稿人节省精力,提高效率,优化工作与生活。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号