-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudiobooks.go
78 lines (66 loc) · 1.7 KB
/
audiobooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"log"
"os"
"path"
"strings"
)
type AudiobookEpisode struct {
SerialNumber int `json:"serialNumber"`
Title string `json:"title"`
Path string `json:"path"`
}
type Audiobook struct {
Title string `json:"title"`
Files []AudiobookEpisode `json:"files"`
}
type File struct {
Path string `json:"path"`
}
func (l *Leecher) fetchAllAudiobooks() {
var audiobooks TeaserList
err := l.getJson("https://iceportal.de/api1/rs/page/hoerbuecher", &audiobooks)
if err != nil {
log.Fatal(err)
}
for _, audiobook := range audiobooks.TeaserGroups[0].Items {
audiobookID := strings.Split(audiobook.Navigation.Href, "/")[2]
log.Print("Fetching ", audiobook.Title, " (", audiobookID, ")")
l.fetchAudiobook(audiobookID)
}
}
func (l *Leecher) fetchAudiobook(audiobookID string) {
var audiobook Audiobook
err := l.getJson("https://iceportal.de/api1/rs/page/hoerbuecher/"+audiobookID, &audiobook)
if err != nil {
log.Fatal(err)
}
dirPath := path.Join(
"audiobooks",
sanitizeFileOrPathName(audiobook.Title),
)
if err = os.MkdirAll(dirPath, 0o0755); err != nil {
log.Fatal("Creating directory for audiobook: ", err)
}
for _, episode := range audiobook.Files {
log.Println("Fetching episode", episode.SerialNumber, "-", episode.Title)
var file File
err := l.getJson("https://iceportal.de/api1/rs/audiobooks/path"+episode.Path, &file)
if err != nil {
log.Fatal(err)
}
episodeFilename := fmt.Sprintf("%03d", episode.SerialNumber) + "_" +
sanitizeFileOrPathName(episode.Title) + ".mp4"
err = l.saveTo(
"https://iceportal.de"+file.Path,
path.Join(
dirPath,
episodeFilename,
),
)
if err != nil {
log.Fatal(err)
}
}
}