Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,6 @@ $RECYCLE.BIN/

# Specific for the MacOS
.DS_Store

# Specific for the autostream
videos/*
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerequisite

In order to use autostream, you have to install the ffmpeg library.
In order to use autostream, you have to install the `ffmpeg` library.

Here are some examples:

Expand All @@ -12,39 +12,25 @@ Here are some examples:
sudo apt update && apt install ffmpeg -y
```

- CentOS

```bash
sudo yum install epel-release -y \
&& yum update -y \
&& rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro \
&& rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm \
&& yum install ffmpeg ffmpeg-devel -y
```

- Windows

```bash
pacman -S mingw-w64-x86_64-ffmpeg
```

- MacOS

```bash
brew install ffmpeg
```

- Windows and More: Refer to [the official website](https://www.ffmpeg.org/download.html).

## Usage

### Have the live permission
### Start the live

1. Go to [the live page](https://link.bilibili.com/p/center/index#/my-room/start-live).
- If you don't have the live permission, you should apply for it first, click `立即开通直播间`, and then follow the instructions.
2. Click `开始直播`.
3. Get the server url and the key.

### Run the script


```bash
python -m autostream.cli bili --server_url <server_url> --key <key> --file <input_file>
python -m autostream.cli bili --server_url <server_url> --key <key> --folder <folder_path>
```
4 changes: 2 additions & 2 deletions autostream/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def cli():
bilibili_parser = subparsers.add_parser('bili', help='Stream on Bilibili')
bilibili_parser.add_argument('--server_url', required=True, help='(required) The server url')
bilibili_parser.add_argument('--key', required=True, help='(required) The stream key')
bilibili_parser.add_argument('--file', required=True, help='(required) The input file')
bilibili_parser.add_argument('--folder', required=True, help='(required) The input folder')

args = parser.parse_args()

Expand All @@ -29,7 +29,7 @@ def cli():

if args.subcommand == 'bili':
print(args)
BiliController(args.server_url, args.key, args.file).stream()
BiliController(args.server_url, args.key, args.folder).stream()

if __name__ == '__main__':
cli()
Empty file.
10 changes: 5 additions & 5 deletions autostream/controller/bili_controller.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Copyright (c) 2025 autostream

import subprocess
from autostream.execute.scan_and_execute import scan_folder_and_execute

class BiliController:
def __init__(self, server_url, key, file):
def __init__(self, server_url, key, folder):
self.server_url = server_url
self.key = key
self.file = file
self.folder = folder

@property
def stream_url(self):
return f'{self.server_url}{self.key}'

def stream(self):
command = f'ffmpeg -re -i {self.file} -c copy -f flv "{self.stream_url}"'
subprocess.run(command, shell=True, check=True)
# return command
while True:
scan_folder_and_execute(self.folder, self.stream_url)
Empty file added autostream/execute/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions autostream/execute/scan_and_execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2025 autostream

import os
import subprocess

def scan_folder_and_execute(folder_path, stream_url):
files = sorted(os.listdir(folder_path))
for file in files:
file_path = os.path.join(folder_path, file)
if os.path.isfile(file_path):
command = f'ffmpeg -re -i {file_path} -c copy -f flv "{stream_url}"'
subprocess.run(command, shell=True, check=True)
Empty file added autostream/tests/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions autostream/tests/test_execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2025 autostream

import unittest
from unittest.mock import patch, MagicMock
from autostream.execute.scan_and_execute import scan_folder_and_execute

class TestScanAndExecute(unittest.TestCase):

def test_scan_folder_and_execute(self):
folder_to_scan = "/home/jh/Downloads/autostream/videos"
command_to_execute = "ffmpeg -re -i {file_path} -c copy -f flv {stream_url}"
scan_folder_and_execute(folder_to_scan, command_to_execute)