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 of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with this program. If not, see <http://www.gnu.org/licenses/>.1516package main1718import (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)2728// OPML document title29const title = "Podcast subscriptions"3031func usage() {32 fmt.Fprintf(os.Stderr, "USAGE: cpod-export FILE\n")33 os.Exit(1)34}3536func main() {37 if len(os.Args) <= 1 {38 usage()39 }4041 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 }4647 var wg sync.WaitGroup48 opmlFile := opml.Create(title)4950 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 return57 }5859 feed := p.Feed60 opmlFile.Add(feed.Title, feed.Type, p.URL)61 }(cast)62 }6364 wg.Wait()65 if err = opmlFile.Save(os.Args[1]); err != nil {66 panic(err)67 }68}