Correct HTML feed auto-detection (bug 215)
[gpodder.git] / bin / gpodder
blob5874ba3be493c97bef69f1189135dade00010663
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
5 # gPodder - A media aggregator and podcast client
6 # Copyright (c) 2005-2008 Thomas Perl and the gPodder Team
8 # gPodder is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # gPodder is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 """
23 gPodder enables you to subscribe to RSS feeds and download
24 podcast episodes from these feeds. gPodder can operate in
25 GUI mode and in CLI mode. Downloaded podcasts can either
26 be synchronized to portable MP3 players (including iPods)
27 or played back on the user's desktop.
28 """
30 # PLEASE DO NOT CHANGE FORMAT OF __version__ LINE (setup.py reads this)
32 __author__ = "Thomas Perl <thp@perli.net>"
33 __version__ = "0.13.0"
34 __date__ = "2008-10-06"
35 __copyright__ = "Copyright (c) 2005-2008 %s. All rights reserved." % __author__
36 __licence__ = "GPL"
38 import sys
39 import os
40 import os.path
42 import locale
43 import gettext
45 from optparse import OptionParser
47 try:
48 import feedparser
49 except:
50 print 'Warning: Module "feedparser" not found. Please install "python-feedparser".'
51 print ' The feedparser module can also be downloaded from www.feedparser.org'
52 sys.exit( -1)
55 def main( argv = sys.argv):
56 prefix = os.path.abspath( os.path.normpath( os.path.join( os.path.dirname( argv[0]), '..')))
57 locale_dir = os.path.join( prefix, 'share', 'locale')
59 # Enable i18n support
60 domain = 'gpodder'
61 gettext.bindtextdomain( domain, locale_dir)
62 gettext.textdomain( domain)
63 gettext.install(domain, locale_dir, unicode=True)
65 s_usage = 'usage: %%prog [options]\n\n%s' % ( __doc__.strip() )
66 s_version = '%%prog %s' % ( __version__ )
68 parser = OptionParser( usage = s_usage, version = s_version)
70 parser.add_option("-v", "--verbose",
71 action="store_true", dest="verbose", default=False,
72 help=_("Print debugging output to stdout"))
74 parser.add_option("-t", "--local",
75 action="store_true", dest="local", default=False,
76 help=_("Run local version in current directory"))
78 parser.add_option("-m", "--maemo",
79 action="store_true", dest="maemo", default=False,
80 help=_("Start the Maemo user interface of gPodder"))
82 parser.add_option("-l", "--list",
83 action="store_true", dest="list", default=False,
84 help=_("List all channel subscriptions"))
86 parser.add_option("-r", "--run",
87 action="store_true", dest="run", default=False,
88 help=_("Update channel list, download new podcasts"))
90 parser.add_option("-u", "--update",
91 action="store_true", dest="update", default=False,
92 help=_("Update channel list and exit"))
94 parser.add_option("-s", "--sync",
95 action="store_true", dest="sync", default=False,
96 help=_("Synchronize channels to configured device"))
98 parser.add_option("-a", "--add", dest="add",
99 help=_("Subscribe to channel from URL"), metavar="URL")
101 parser.add_option("-d", "--delete", dest="delete",
102 help=_("Delete channel specified by URL"), metavar="URL")
104 parser.add_option("-S", "--stats",
105 action="store_true", dest="stats", default=False,
106 help=_("Get sync statistics"))
108 (options, args) = parser.parse_args(argv)
110 if options.local:
111 sys.path = [ os.path.join( prefix, 'src') ] + sys.path
113 import gpodder
114 gpodder.user_agent = 'gPodder/%s (+http://gpodder.berlios.de/)' % __version__
116 if options.maemo:
117 gpodder.interface = gpodder.MAEMO
118 elif options.list or options.run or options.update or \
119 options.sync or options.add or options.delete:
120 gpodder.interface = gpodder.CLI
121 else:
122 gpodder.interface = gpodder.GUI
124 if options.verbose:
125 from gpodder.liblogger import enable_verbose
126 enable_verbose()
128 from gpodder import console
129 if options.list:
130 console.list_channels()
131 elif options.run:
132 console.run()
133 elif options.update:
134 console.update()
135 elif options.sync:
136 console.sync_device()
137 elif options.add:
138 console.add_channel( options.add)
139 elif options.delete:
140 console.del_channel( options.delete)
141 elif options.stats:
142 console.sync_stats()
143 else:
144 #default run gui
145 from gpodder import gui
146 from gpodder.SimpleGladeApp import bindtextdomain
147 import gtk.glade
149 # check if we have a X connection
150 from os import environ
151 if not 'DISPLAY' in environ or not environ['DISPLAY']:
152 print 'Your DISPLAY variable is not set correctly. Cannot start GUI.'
153 sys.exit( -1)
155 gui.glade_dir = os.path.join( prefix, *gui.glade_dir)
156 gui.icon_dir = os.path.join( prefix, *gui.icon_dir)
157 gui.scalable_dir = os.path.join( prefix, *gui.scalable_dir)
159 if options.local:
160 gui.glade_dir = os.path.join( prefix, 'data')
161 gui.icon_dir = os.path.join( prefix, 'data', 'gpodder.png')
162 gui.scalable_dir = os.path.join( prefix, 'data', 'gpodder.svg')
163 locale_dir = os.path.join( prefix, 'data', 'locale')
165 bindtextdomain( domain, locale_dir)
166 gui.app_version = __version__
167 gui.main()
170 if __name__ == "__main__":
171 sys.exit( main())