Skip to content

Commit

Permalink
Merge pull request #2 from XXXFQ:develop
Browse files Browse the repository at this point in the history
Initialize versioning and update project structure
  • Loading branch information
XXXFQ authored Nov 10, 2024
2 parents 6df429a + e6a6fac commit 6b409c3
Show file tree
Hide file tree
Showing 10 changed files with 527 additions and 62 deletions.
39 changes: 6 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,25 @@
# Radiko Recorder

Radiko Recorderは、Radikoからラジオ放送を録音するためのツールです。このリポジトリには、Radikoの録音機能を使用するために必要なスクリプトと設定が含まれています
Radikoからラジオ放送を録音するためのツールです。

## ■必要条件

- Python 3.8以上
- 必要なPythonパッケージ(`requirements.txt`が提供されている場合、それを使用してインストール)
- Python 3.11以上

## ■インストール

1. リポジトリをクローンします:
```sh
git clone https://github.com/XXXFQ/Radiko_Recorder.git
cd Radiko_Recorder
```

2. 必要なPythonパッケージをインストールします:
```sh
pip install -r requirements.txt
```

## ■使い方

Radiko RecorderはコマンドラインまたはJupyterノートブックで使用できます。以下に両方の方法について説明します。

### コマンドライン

#### 放送局リストの表示
## ■放送局リストの表示

放送局のリストを表示するには、`-sl`または`--station-list`オプションを使用します:

```sh
sh Radiko_Recorder.sh -sl
radiko-recorder -sl
```

## ■放送局の録音

ラジオ放送を録音するには、以下のコマンドを使用します:

```sh
sh Radiko_Recorder.sh <station_id> <start_time> <duration_minutes>
radiko-recorder <station_id> <start_time> <duration_minutes>
```

- `<station_id>`: 録音したい放送局のID(例:`TBS`, `QRR`など)。
Expand All @@ -48,18 +28,11 @@ sh Radiko_Recorder.sh <station_id> <start_time> <duration_minutes>

例:
```sh
sh Radiko_Recorder.sh FMGUNMA 20240604000000 50
radiko-recorder FMGUNMA 20240604000000 50
```

これは、2024年6月4日00:00:00から50分間、FMGUNMA局を録音します。

## ■設定
Radiko Recorderを使用するには、`config.py`ファイルでいくつかの設定を行う必要があります。`RADIKO_AREA_ID``OUTPUT_DIR`の変数を必要に応じて設定してください。

## ■ファイル
- `Radiko_Recorder.sh`: Pythonを使用してレコーダーを実行するためのシェルスクリプト。
- `Radiko_Recorder.cmd`: Windowsでレコーダーを実行するためのコマンドスクリプト。

## ■ライセンス
このプロジェクトはMITライセンスの下でライセンスされています。

Expand Down
50 changes: 50 additions & 0 deletions devscripts/update-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Allow direct execution
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import toml

VERSION_TEMPLATE = '''\
# Autogenerated by devscripts/update-version.py
__version__ = {version!r}
'''

def read_pyproject_version(pyproject_path="pyproject.toml") -> str:
'''
Read version information from pyproject.toml.
Parameters
----------
pyproject_path : str
Path to pyproject.toml
Returns
-------
str
Version information
'''
with open(pyproject_path, "r") as f:
pyproject = toml.load(f)
return pyproject["tool"]["poetry"]["version"]

def write_version_file(version, output_path="radiko_recorder/version.py"):
'''
Write version information to version.py.
Parameters
----------
version : str
Version information
output_path : str
Path to version.py
'''
with open(output_path, "w") as f:
f.write(VERSION_TEMPLATE.format(version=version))
print(f"version.py has been generated with version: {version}")

if __name__ == "__main__":
version = read_pyproject_version()
write_version_file(version)
412 changes: 412 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "radiko-recorder"
version = "0.1.0"
description = ""
authors = ["ARM0930 <72128692+XXXFQ@users.noreply.github.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.11,<3.14"
beautifulsoup4 = "^4.12.3"
colorlog = "^6.9.0"
ffmpeg-python = "^0.2.0"
requests = "^2.32.3"
python-dotenv = "^1.0.1"

[tool.poetry.group.dev.dependencies]
pyinstaller = "^6.11.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
30 changes: 24 additions & 6 deletions radiko_recorder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
raise ImportError(
f'You are using an unsupported version of Python. Only Python versions 3.8 and above are supported by ihc_reporter') # noqa: F541

import re
import argparse
import re
from datetime import datetime
from pathlib import Path

from .version import __version__
from .recorder import RadikoPlayer
from .config import (
RADIKO_AREA_ID,
OUTPUT_DIR
)
from .config import RADIKO_AREA_ID

def record_radio(area_id: str, station_id: str, start_time: str, duration_minutes: int):
'''
Expand All @@ -33,6 +32,9 @@ def record_radio(area_id: str, station_id: str, start_time: str, duration_minute
if not _is_valid_area_id(area_id):
raise ValueError(f"Invalid area ID: {area_id}")

# 出力ファイルのパス
OUTPUT_DIR = Path("output")
OUTPUT_DIR.mkdir(exist_ok=True)
output_path = OUTPUT_DIR / f'{station_id}_{datetime.now().strftime("%Y%m%d%H%M%S")}.aac'

# ラジオを録音
Expand Down Expand Up @@ -97,6 +99,22 @@ def init_parser() -> argparse.ArgumentParser:
parser.add_argument('duration_minutes', type=int, nargs='?', help='Duration (minutes)', default=60)
return parser

def _check_args(args: argparse.Namespace) -> bool:
'''
必須引数が提供されているかをチェックする
Parameters
----------
args : argparse.Namespace
コマンドライン引数
Returns
-------
bool
必須引数が提供されているかどうか
'''
return all([args.station_id, args.start_time, args.duration_minutes])

def main(argv=None):
'''
メイン関数
Expand All @@ -110,7 +128,7 @@ def main(argv=None):
return

# 必須引数のチェック
if not all([args.station_id, args.start_time, args.duration_minutes]):
if not _check_args(args):
parser.print_usage()
print("Station ID, start time, and duration minutes are required unless using the --station-list option.")
return
Expand Down
6 changes: 1 addition & 5 deletions radiko_recorder/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import os
from pathlib import Path

from dotenv import load_dotenv

# 環境変数へ反映
load_dotenv()

RADIKO_AREA_ID = os.getenv('RADIKO_AREA_ID')

OUTPUT_DIR = Path("output")
OUTPUT_DIR.mkdir(exist_ok=True)
RADIKO_AREA_ID = os.getenv('RADIKO_AREA_ID')
1 change: 1 addition & 0 deletions radiko_recorder/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def record(self, station_id: str, start_time: datetime, duration_minutes: int, o
headers = f"X-RADIKO-AUTHTOKEN: {self._headers['X-Radiko-AuthToken']}"

# ffmpegコマンドを実行して録音
logger.info(f'Recording {output_path}...')
(
ffmpeg
.input(filename=stream_url, headers=headers)
Expand Down
3 changes: 3 additions & 0 deletions radiko_recorder/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Autogenerated by devscripts/update-version.py

__version__ = '0.1.0'
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

23 changes: 9 additions & 14 deletions test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,18 @@
" Area ID (JP13, JP27, etc.)\n",
" -s, --station_list Show station list\n"
]
},
{
"ename": "SystemExit",
"evalue": "0",
"output_type": "error",
"traceback": [
"An exception has occurred, use %tb to see the full traceback.\n",
"\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n"
]
}
],
"source": [
"radiko_recorder.main(['-h'])"
"try:\n",
" radiko_recorder.main(['-h'])\n",
"except SystemExit:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -82,19 +76,20 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[90m2024-06-09 01:53:25 \u001b[94mINFO \u001b[35mradiko_recorder.recorder \u001b[37mSuccessfully recorded output\\FMT_20240609015308.aac\u001b[0m\n"
"\u001b[90m2024-11-11 00:54:56 \u001b[94mINFO \u001b[35mradiko_recorder.recorder \u001b[37mRecording output\\FMT_20241111005454.aac...\u001b[0m\n",
"\u001b[90m2024-11-11 00:55:09 \u001b[94mINFO \u001b[35mradiko_recorder.recorder \u001b[37mSuccessfully recorded output\\FMT_20241111005454.aac\u001b[0m\n"
]
}
],
"source": [
"radiko_recorder.main(['-a', 'JP13', 'FMT', '20240608120000', '30'])"
"radiko_recorder.main(['-a', 'JP13', 'FMT', '20241108120000', '30'])"
]
}
],
Expand Down

0 comments on commit 6b409c3

Please sign in to comment.