Skip to content

Commit

Permalink
Package for PyPi
Browse files Browse the repository at this point in the history
  • Loading branch information
hizkifw authored Jan 18, 2022
2 parents 99e970b + 5bd0993 commit 2f54dd9
Show file tree
Hide file tree
Showing 14 changed files with 1,386 additions and 1,251 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
*.m4a
*.json
__pycache__/
dist/
build/
*.egg-info
.install-cache/
92 changes: 63 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,59 @@
## Requirements

- python 3.8
- Python 3.8
- ffmpeg
- aiohttp (`pip install -r requirements.txt`)

## Features

- Wait for a stream to start and automatically start recording
- Save comment/chat logs
- Authenticate with cookies (Netscape format, same one used with youtube-dl)
- Remux recordings to .mp4/.m4a after it's done
- Continuously monitor multiple streams in parallel and automatically start downloading when any of them goes online
- Continuously monitor multiple streams in parallel and automatically start
downloading when any of them goes online

## Installation

```
pip install fc2-live-dl
```

## Usage

```
python3 fc2_live_dl.py https://live.fc2.com/<...>
fc2-live-dl https://live.fc2.com/<...>
```

```
usage: fc2_live_dl.py [-h] [-v]
[--quality {150Kbps,400Kbps,1.2Mbps,2Mbps,3Mbps,sound}]
[--latency {low,high,mid}] [--threads THREADS]
[-o OUTPUT] [--no-remux] [-k] [-x] [--cookies COOKIES]
[--write-chat] [--write-info-json] [--write-thumbnail]
[--wait] [--poll-interval POLL_INTERVAL]
[--log-level {silent,error,warn,info,debug,trace}]
[--dump-websocket]
url
usage: fc2-live-dl [-h] [-v]
[--quality {150Kbps,400Kbps,1.2Mbps,2Mbps,3Mbps,sound}]
[--latency {low,high,mid}] [--threads THREADS] [-o OUTPUT]
[--no-remux] [-k] [-x] [--cookies COOKIES] [--write-chat]
[--write-info-json] [--write-thumbnail] [--wait]
[--poll-interval POLL_INTERVAL]
[--log-level {silent,error,warn,info,debug,trace}]
[--dump-websocket]
url
positional arguments:
url A live.fc2.com URL.
optional arguments:
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
--quality {150Kbps,400Kbps,1.2Mbps,2Mbps,3Mbps,sound}
Quality of the stream to download. Default is 3Mbps.
--latency {low,high,mid}
Stream latency. Select a higher latency if
experiencing stability issues. Default is mid.
Stream latency. Select a higher latency if experiencing
stability issues. Default is mid.
--threads THREADS The size of the thread pool used to download segments.
Default is 1.
-o OUTPUT, --output OUTPUT
Set the output filename format. Supports formatting
options similar to youtube-dl. Default is '%(date)s
%(title)s (%(channel_name)s).%(ext)s'
Available format options:
channel_id (string): ID of the broadcast
channel_name (string): broadcaster's profile name
Expand Down Expand Up @@ -80,9 +86,14 @@ optional arguments:

## autofc2

> Monitor multiple channels at the same time, and automatically start downloading when any of them goes online
> Monitor multiple channels at the same time, and automatically start
> downloading when any of them goes online
```
autofc2 --config autofc2.json
```

Create a file called `autofc2.json` following the example below, and place the file next to the `autofc2.py` script.
Where the `autofc2.json` file looks like this:

```json
{
Expand Down Expand Up @@ -114,28 +125,51 @@ Create a file called `autofc2.json` following the example below, and place the f
}
```

The `default_params` object will be the parameters applied to all of the channels. Check the usage section above for more information on each parameter. Note that `wait_for_live` needs to be set to `true` for the script to work properly. You can also override the parameters per-channel.
The `default_params` object will be the parameters applied to all of the
channels. Check the usage section above for more information on each parameter.
Note that `wait_for_live` needs to be set to `true` for the script to work
properly. You can also override the parameters per-channel.

Arbitrary parameters can be specified by prefixing them with `_`, and will be accessible in `outtmpl`. This is useful for specifying custom filenames just like in the example above. In the example I'm using `_en_name`, but you can use anything as long as it starts with `_`.
Arbitrary parameters can be specified by prefixing them with `_`, and will be
accessible in `outtmpl`. This is useful for specifying custom filenames just
like in the example above. In the example I'm using `_en_name`, but you can use
anything as long as it starts with `_`.

**NOTE Windows users**: When specifying a file path (e.g. for cookies) in the json, double up your backslashes, for example: `"cookies_file": "C:\\Documents\\cookies.txt"`.
**NOTE Windows users**: When specifying a file path (e.g. for cookies) in the
json, double up your backslashes, for example:
`"cookies_file": "C:\\Documents\\cookies.txt"`.

Once configured, you can run the script:

```
python3 autofc2.py
autofc2 --config autofc2.json
```

If you need to change the config json, feel free to change it while the script is running. It will reload the file if it detects any changes. Note that parameters will not be updated for ongoing streams (i.e. if the script is recording a stream and you change its settings, it will continue recording with the old settings and will only apply the new configuration to future recordings).
If you need to change the config json, feel free to change it while the script
is running. It will reload the file if it detects any changes. Note that
parameters will not be updated for ongoing streams (i.e. if the script is
recording a stream and you change its settings, it will continue recording with
the old settings and will only apply the new configuration to future
recordings).

## Notes

- FC2 does not allow multiple connections to the same stream, so you can't watch in the browser while downloading. You can instead preview the file being downloaded using `mpv` or `vlc`. Alternatively, log in with an account on your browser.
- Recording only starts from when you start the tool. This tool cannot "seek back" and record streams from the start.
- FC2 does not allow multiple connections to the same stream, so you can't watch
in the browser while downloading. You can instead preview the file being
downloaded using `mpv` or `vlc`. Alternatively, log in with an account on your
browser.
- Recording only starts from when you start the tool. This tool cannot "seek
back" and record streams from the start.
- If you can't run `fc2-live-dl` or `autofc2`, try uninstalling and reinstalling
with `pip uninstall fc2-live-dl`.

## Known issues

- Tested to work under Linux. It should work on Windows, but no guarantees. If you're facing any issues on Windows, try running it under WSL.
- Tested to work under Linux. It should work on Windows, but no guarantees. If
you're facing any issues on Windows, try running it under WSL.
- autofc2 will freak out over a private/paid streams.
- `--wait` doesn't work sometimes because FC2 would announce that the stream is live before the playlist is available. Use `autofc2` if you want to make sure streams get saved.
- When monitoring many channels with `autofc2`, if you face any 5xx errors, try increasing the `wait_poll_interval` to something higher.
- `--wait` doesn't work sometimes because FC2 would announce that the stream is
live before the playlist is available. Use `autofc2` if you want to make sure
streams get saved.
- When monitoring many channels with `autofc2`, if you face any 5xx errors, try
increasing the `wait_poll_interval` to something higher.
91 changes: 0 additions & 91 deletions autofc2.py

This file was deleted.

Loading

0 comments on commit 2f54dd9

Please sign in to comment.