cpod

Yet another cron-friendly podcatcher

git clone https://git.8pit.net/cpod.git

 1// Copyright (C) 2013-2015 Sören Tempel
 2//
 3// This program is free software: you can redistribute it and/or modify
 4// it under the terms of the GNU General Public License as published by
 5// the Free Software Foundation, either version 3 of the License, or
 6// (at your option) any later version.
 7//
 8// This program is distributed in the hope that it will be useful,
 9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16package main
17
18import (
19	"fmt"
20	"github.com/nmeum/cpod/opml"
21	"github.com/nmeum/cpod/store"
22	"github.com/nmeum/cpod/util"
23	"os"
24	"path/filepath"
25	"sync"
26)
27
28// OPML document title
29const title = "Podcast subscriptions"
30
31func usage() {
32	fmt.Fprintf(os.Stderr, "USAGE: cpod-export FILE\n")
33	os.Exit(1)
34}
35
36func main() {
37	if len(os.Args) <= 1 {
38		usage()
39	}
40
41	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), "cpod")
42	storage, err := store.Load(filepath.Join(storeDir, "urls"))
43	if err != nil {
44		panic(err)
45	}
46
47	var wg sync.WaitGroup
48	opmlFile := opml.Create(title)
49
50	for cast := range storage.Fetch() {
51		wg.Add(1)
52		go func(p store.Podcast) {
53			defer wg.Done()
54			if p.Error != nil {
55				fmt.Fprintf(os.Stderr, "%s\n", p.Error)
56				return
57			}
58
59			feed := p.Feed
60			opmlFile.Add(feed.Title, feed.Type, p.URL)
61		}(cast)
62	}
63
64	wg.Wait()
65	if err = opmlFile.Save(os.Args[1]); err != nil {
66		panic(err)
67	}
68}