Skip to content

Commit 89c8de3

Browse files
committed
feat: separate tmp dir
1 parent d8049d1 commit 89c8de3

File tree

7 files changed

+65
-23
lines changed

7 files changed

+65
-23
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ config.yml
2525
config.yaml
2626

2727
# downloads
28-
/downloads
29-
/output
28+
/radiko
3029

3130
# misc
3231
*.bak

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ COPY --from=build /build/radicron /app/radicron
2828
# set timezone
2929
ENV TZ "Asia/Tokyo"
3030
# set the default download dir
31-
ENV RADIGO_HOME "/downloads"
32-
VOLUME ["/downloads"]
31+
ENV RADICRON_HOME "/radiko"
32+
VOLUME ["/radiko"]
3333

3434
ENTRYPOINT ["/app/radicron"]
3535
CMD ["-c", "/app/config.yml"]

README.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Create a configuration file (`config.yml`) to define rules for recording:
5151
area-id: JP13 # if unset, default to "your" region
5252
extra-stations:
5353
- ALPHA-STATION # include stations not in your region
54+
ignore-stations:
55+
- JOAK # ignore stations from search
56+
minimum-output-size: 2 # do not save an audio below this size (in MB), default is 1 (MB)
5457
rules:
5558
airship: # name your rule as you like
5659
station-id: FMT # (optional) the staion_id, if not available by default, automatically add this station to the watch list
@@ -60,35 +63,30 @@ rules:
6063
window: 48h # only within the past window from the current time
6164
hiccorohee:
6265
pfm: "ヒコロヒー" # search by pfm
63-
watchman:
66+
trad:
6467
dow: # filter by day of the week (e.g, Mon, tue, WED)
65-
- fri
66-
pfm: "宇多丸"
67-
station-id: TBS
68+
- wed
69+
- thu
70+
station-id: FMT
71+
title: "THE TRAD"
6872
```
6973
70-
In addition, set `${RADIGO_HOME}` to set the download directory.
74+
In addition, set `${RADICRON_HOME}` to set the download directory.
7175

7276
## Usage
7377

7478
```bash
75-
mkdir -p ./downloads && RADIGO_HOME=./downloads radicron -c config.yml
79+
mkdir -p ./radiko/{downloads,tmp} && RADICRON_HOME=./radiko radicron -c config.yml
7680
```
7781

7882
### Try with Docker
7983

80-
By default, it mounts `./config.yml` and `./downloads` to the container.
84+
By default, it mounts `./config.yml` and `./radiko` to the container.
8185

8286
```console
8387
docker compose up
8488
```
8589

86-
To set the ownership of the downloaded files right, run with `$UID` and `$GID` environment variables:
87-
88-
```console
89-
UID=$(id -u) GID=$(id -g) docker compose up -d
90-
```
91-
9290
## Build the image yourself
9391

9492
In case the [image](https://github.com/iomz/radicron/pkgs/container/radicron) is not available for your platform:

cmd/radicron/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func reload(ctx context.Context, filename string) (radicron.Rules, error) {
2828
rules := radicron.Rules{}
2929
cwd, _ := os.Getwd()
3030

31-
// check ${RADIGO_HOME}
32-
if os.Getenv("RADIGO_HOME") == "" {
33-
os.Setenv("RADIGO_HOME", filepath.Join(cwd, "downloads"))
31+
// check ${RADICRON_HOME}
32+
if os.Getenv("RADICRON_HOME") == "" {
33+
os.Setenv("RADICRON_HOME", filepath.Join(cwd, "radiko"))
3434
}
3535

3636
// load params from a config file

const.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const (
1313
DefaultInterval = "168h"
1414
// DefaultMinimumOutputSize
1515
DefaultMinimumOutputSize = 1
16+
// Environment Variable for RADICRON_HOME
17+
EnvRadicronHome = "RADICRON_HOME"
1618
// Language for ID3v2 tags
1719
ID3v2LangJPN = "jpn"
1820
// Kilobytes for the metric bytes

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ services:
88
user: 1000:1000
99
volumes:
1010
- ./config.yml:/app/config.yml
11-
- ./downloads:/downloads
11+
- ./radiko:/radiko

download.go

+45-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func Download(
5757
asset.Schedules = append(asset.Schedules, prog)
5858

5959
// the output config
60-
output, err := radigo.NewOutputConfig(
60+
output, err := newOutputConfig(
6161
fmt.Sprintf(
6262
"%s_%s_%s",
6363
startTime.In(Location).Format(OutputDatetimeLayout),
@@ -275,6 +275,30 @@ func getChunklistFromM3U8(uri string) ([]string, error) {
275275
return getChunklist(resp.Body)
276276
}
277277

278+
// getRadicronPath gets the RADICRON_HOME path
279+
func getRadicronPath(sub string) (string, error) {
280+
// If the environment variable RADICRON_HOME is set,
281+
// override working directory path.
282+
fullPath := os.Getenv(EnvRadicronHome)
283+
switch {
284+
case fullPath != "" && !filepath.IsAbs(fullPath):
285+
wd, err := os.Getwd()
286+
if err != nil {
287+
return "", err
288+
}
289+
fullPath = filepath.Join(wd, fullPath, sub)
290+
case fullPath == "":
291+
wd, err := os.Getwd()
292+
if err != nil {
293+
return "", err
294+
}
295+
fullPath = filepath.Join(wd, "radiko", sub)
296+
default:
297+
fullPath = filepath.Join(fullPath, sub)
298+
}
299+
return filepath.Clean(fullPath), nil
300+
}
301+
278302
// getURI returns uri generated by parsing m3u8.
279303
func getURI(input io.Reader) (string, error) {
280304
playlist, listType, err := m3u8.DecodeFrom(input, true)
@@ -289,9 +313,28 @@ func getURI(input io.Reader) (string, error) {
289313
return p.Variants[0].URI, nil
290314
}
291315

316+
// newOutputConfig prepares the outputdir
317+
func newOutputConfig(fileBaseName, fileFormat string) (*radigo.OutputConfig, error) {
318+
fullPath, err := getRadicronPath("downloads")
319+
if err != nil {
320+
return nil, err
321+
}
322+
323+
return &radigo.OutputConfig{
324+
DirFullPath: fullPath,
325+
FileBaseName: fileBaseName,
326+
FileFormat: fileFormat,
327+
}, nil
328+
}
329+
292330
// tempAACDir creates a dir to store temporary aac files
293331
func tempAACDir() (string, error) {
294-
aacDir, err := os.MkdirTemp("", "aac")
332+
fullPath, err := getRadicronPath("tmp")
333+
if err != nil {
334+
return "", err
335+
}
336+
337+
aacDir, err := os.MkdirTemp(fullPath, "aac")
295338
if err != nil {
296339
return "", err
297340
}

0 commit comments

Comments
 (0)