Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cxjava committed Sep 17, 2021
0 parents commit 2717654
Show file tree
Hide file tree
Showing 28 changed files with 2,865 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build & Test
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
jobs:
ci:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
matrix:
go: [1.17.x]
os: [ubuntu-latest]
name: Go ${{ matrix.go }} in ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Environment
run: |
go version
go env
- name: Cache go module
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-
- name: Install tools
env:
GO111MODULE: on
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint --version
- name: Lint
run: |
go mod tidy
golangci-lint run ./... -v
- name: Test
env:
GOFLAGS: -mod=mod
run: go test -race -coverpkg=./... -coverprofile=coverage.txt ./...
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release

on:
push:
tags:
- "v*"
workflow_dispatch:
# inputs:
# upx_version:
# description: 'UPX version'
# required: true
# default: '3.95'

jobs:
release:
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
matrix:
go: [1.17.x]
os: [ubuntu-latest]
name: Go ${{ matrix.go }} in ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Environment
run: |
go version
go env
- name: Install tools
env:
GO111MODULE: on
run: |
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint --version
- name: Lint
run: |
go mod tidy
golangci-lint run ./... -v
- name: Test
env:
GOFLAGS: -mod=mod
run: go test -race -coverpkg=./... -coverprofile=coverage.txt ./...

# So GoReleaser can generate the changelog properly
- name: Unshallowify the repo clone
run: git fetch --prune --unshallow

- name: Check git tag exist
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
gitTagExists=$(git tag --points-at HEAD)
if ! [ -n "$gitTagExists" ]; then
echo "no tag, create one."
latesttag=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "latest tag: ${latesttag}"
newtag=$(echo ${latesttag} | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
echo "new tag: ${newtag}"
git tag $newtag
fi
# - name: Installing upx
# env:
# UPX_VERSION: ${{ github.event.inputs.upx_version }}
# run: |
# echo "Installing upx .."
# curl -OL "https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz"
# tar xvf "upx-${UPX_VERSION}-amd64_linux.tar.xz"
# cp "upx-${UPX_VERSION}-amd64_linux/upx" "$(go env GOPATH)/bin"
# upx --version

- name: Set environment variables
run: |
echo "GOLANG_VERSION=$(go version)" >> $GITHUB_ENV
echo "BUILT_BY=$(whoami)@$(hostname)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --skip-validate --skip-sign --debug
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
GOLANG_VERSION: ${{ env.GOLANG_VERSION }}
BUILT_BY: ${{ env.BUILT_BY }}
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
m3u8-downloader
.vscode
/outputFolder
58 changes: 58 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
env:
- GO111MODULE=on

builds:
- env:
- CGO_ENABLED=0
ldflags:
- '-s -w'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.Version={{.Version}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.Commit={{.FullCommit}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.RepoUrl={{.GitURL}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.BuildDate={{.Date}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.BuiltWithGoVersion={{.Env.GOLANG_VERSION}}'
- -X 'github.com/{{.Env.GITHUB_REPOSITORY}}/cmd.BuiltBy={{.Env.BUILT_BY}}'
goos:
- windows
- darwin
- linux
- freebsd
goarch:
- 386
- amd64
- arm
- arm64
- mips
- mipsle
- mips64
- mips64le
gomips:
- hardfloat
- softfloat
# hooks:
# post:
# - bash -c 'upx "{{ .Path }}" || true'
archives:
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}_v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
format: tar.gz
files:
- none*
format_overrides:
- goos: windows
format: zip
wrap_in_directory: false
replacements:
amd64: 64-bit
386: 32-bit
arm: ARM
arm64: ARM64
darwin: macOS
linux: Linux
windows: Windows
openbsd: OpenBSD
netbsd: NetBSD
freebsd: FreeBSD
release:
draft: true
prerelease: auto
name_template: '{{.ProjectName}}-v{{.Version}}-{{.Date}}'
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Char

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
155 changes: 155 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# m3u8-downloader

[![Build Status](https://github.com/cxjava/m3u8-downloader/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/cxjava/m3u8-downloader/actions/workflows/build-and-test.yml)
[![License](https://img.shields.io/github/license/cxjava/m3u8-downloader.svg)](https://github.com/cxjava/m3u8-downloader)
[![Release](https://img.shields.io/github/release/cxjava/m3u8-downloader.svg)](https://github.com/cxjava/m3u8-downloader/releases)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/cxjava/m3u8-downloader)

README | [简体中文](README.zh-cn.md)

m3u8 downloader by Golang

![m3u8-downloader-ScreenShot](https://user-images.githubusercontent.com/802316/133533481-483aa464-2fbe-4a25-9539-4a6345481dcd.png)

## feature

- Support CDN download, break the speed limit
- Support custom key, the format of the key can be hex or base64, or original
- Support custom host prefix
- Read m3u8 from file or m3u8 from network address
- Support proxy
- Support custom request header
- Whether to delete the downloaded ts file
- Custom number of threads
- Custom download file name
- Progress bar
- Support running on Apple M1, router

## TODO

- [ ] Support decryption while downloading
- [ ] ffmpeg processing command
- [ ] Show total file size
- [ ] Delete error CDN IP

## Ping command

``` shell
./m3u8-downloader p -h

With this command, you can ping multiple IPs to detect IP response speeds. Easily get the fastest CDN IPs.IP is separated by commas, for example: ./m3u8-downloader p 8.8.8.8,1.1.1.1,9.9.9.9, The have two output format, default output is speed of each IP, for example:

./m3u8-downloader p 8.8.8.8,1.1.1.1,9.9.9.9,

9.9.9.9 time: 23.9635ms
8.8.8.8 time: 61.2325ms
1.1.1.1 time: 225.7115ms

Other output is the parameter of download m3u8, for example:

./m3u8-downloader p 8.8.8.8,1.1.1.1,9.9.9.9, -d www.google.com -o p

-C 'www.google.com:8.8.8.8' -C 'www.google.com:1.1.1.1' -C 'www.google.com:9.9.9.9'

Usage:
m3u8-downloader ping [flags]

Aliases:
ping, p

Flags:
-d, --domain string Only avaliable when output type is 'p', domain to use output as a parameter, such as: -C 'www.google.com:1.1.1.1' -C 'www.google.com:8.8.8.8' (default "www.google.com")
-h, --help help for ping
-l, --logLevel string logging level on a Logger,logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic. (default "Info")
-o, --outputType string output type, can be 't' or 'p', if the type is 'p', it will print "-C 'www.example.com:1.1.1.1' -C 'www.example.com:9.9.9.9'". If the type is 't', it will print 8.8.8.8 time: 62.17ms (default "t")

Global Flags:
--config string config file (default is $HOME/.m3u8-downloader.yaml)
```
### How to use CDN for download
- Open [https://ping.chinaz.com/](https://ping.chinaz.com/) Enter the address of the domain name for which you need to find the IP, and click the Copy button after the ping is finished
![1](https://user-images.githubusercontent.com/802316/133531905-ac398cc4-77da-44e3-a309-351feebd0628.png)
- Run the `ping` command to query the ping time of each IP
``` shell
./m3u8-downloader p 8.8.8.8,1.1.1.1,9.9.9.9,
INFO[2021-09-16T08:56:33+08:00] Try to ping 8.8.8.8,1.1.1.1,9.9.9.9,
3 / 3 [-----------------------------------------------------------------------------------------] 100.00% 3 p/s 1.3s

8.8.8.8 time: 55.4175ms
9.9.9.9 time: 71.2685ms
1.1.1.1 time: 196.496ms

```
- Run the `ping` command with the parameter `-o P -d www.google.com` to get the parameters needed for the `download` command
``` shell
./m3u8-downloader ping 8.8.8.8,1.1.1.1,9.9.9.9, -d www.google.com -o p
INFO[2021-09-16T08:57:21+08:00] Try to ping 8.8.8.8,1.1.1.1,9.9.9.9,
3 / 3 [-----------------------------------------------------------------------------------------] 100.00% 3 p/s 1.3s

-C 'www.google.com:8.8.8.8' -C 'www.google.com:9.9.9.9' -C 'www.google.com:1.1.1.1'

```
- Copy `-C 'www.google.com:8.8.8.8' -C 'www.google.com:9.9.9.9' -C 'www.google.com:1.1.1.1'` to the `download` command
## Download command
``` shell
./m3u8-downloader download -h

All ts segments will be downloaded into a folder then be joined into a single TS file.

Usage:
m3u8-downloader download [flags]

Aliases:
download, d

Flags:
-u, --baseUrl string base url for m3u8.
-C, --cdn stringArray CDN(s) for the download domain, eg. -C 'www.google.com:8.8.8.8' -C 'www.google.com:1.1.1.1' -C 'www.google.com:9.9.9.9' .
-d, --deleteSyncByte some TS files do not start with SyncByte 0x47, they can not be played after merging, need to remove the bytes before the SyncByte.
-D, --deleteTS delete all the downloaded TS file. (default true)
-f, --downloadDir string download directory, base on current folder. (default "./outputFolder")
-H, --header stringArray custom http header(s), eg. -H 'user-agent: Mozilla/5.0...' -H 'accept: */*' .
-h, --help help for download
--key string custom key to decrypt ts data.
--keyFormat string format of key, format can be those values: original, hex, base64. (default "original")
-l, --logLevel string logging level on a Logger,logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic. (default "Info")
-o, --output string file name for save.
-x, --proxy string use proxy. eg. http://127.0.0.1:8080
-n, --threadNumber int the number of download thread. (default 10)

Global Flags:
--config string config file (default is $HOME/.m3u8-downloader.yaml)
```
### Quickly copy download information from chrome
- Open Chrome's developer tools, find the m3u8 request, right click `Copy`->`Copy as cURL`, as follows
![9](https://user-images.githubusercontent.com/802316/133644904-aa049868-e1fc-40d6-b7b8-85f615f86c07.png)
- Replace `curl` with `. /m3u8-downloader download`, and remove `--compressed` if it has it
``` shell
./m3u8-downloader download 'https://abc.com/def.m3u8' \
-H 'sec-ch-ua: "Microsoft Edge";v="93", " Not;A Brand";v="99", "Chromium";v="93"' \
-H 'accept: text/html' \
-H 'dnt: 1' \
-H 'x-requested-with: XMLHttpRequest' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.47' \
-H 'accept-language: en,en-US;q=0.9' \
```
## Thanks
- [https://github.com/Greyh4t/m3u8-Downloader-Go](https://github.com/Greyh4t/m3u8-Downloader-Go)
- [https://github.com/llychao/m3u8-downloader](https://github.com/llychao/m3u8-downloader)
Loading

0 comments on commit 2717654

Please sign in to comment.