new weboorrents application
This commit is contained in:
parent
85d78e9bdf
commit
f7db731878
3 changed files with 123 additions and 0 deletions
26
scripts/weboorrents
Executable file
26
scripts/weboorrents
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.frontends.weboorrents import Weboorrents
|
||||
|
||||
if __name__ == '__main__':
|
||||
Weboorrents.run()
|
||||
21
weboob/frontends/weboorrents/__init__.py
Normal file
21
weboob/frontends/weboorrents/__init__.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from .application import Weboorrents
|
||||
76
weboob/frontends/weboorrents/application.py
Normal file
76
weboob/frontends/weboorrents/application.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from weboob.capabilities.torrent import ICapTorrent
|
||||
from weboob.tools.application import ConsoleApplication
|
||||
|
||||
class Weboorrents(ConsoleApplication):
|
||||
APPNAME = 'weboorrents'
|
||||
VERSION = '1.0'
|
||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||
CONFIG = {}
|
||||
|
||||
def main(self, argv):
|
||||
self.load_backends(ICapTorrent)
|
||||
return self.process_command(*argv[1:])
|
||||
|
||||
@ConsoleApplication.command('Get information about a torrent')
|
||||
def command_info(self, id):
|
||||
if not '.' in id:
|
||||
print >>sys.stderr, 'ID must be in form <backend>.<ID>'
|
||||
return 1
|
||||
|
||||
backend_name, id = id.split('.', 1)
|
||||
backend = self.weboob.backends.get(backend_name, None)
|
||||
if not backend:
|
||||
print >>sys.stderr, 'Backends "%s" not found' % backend_name
|
||||
return 1
|
||||
|
||||
with backend:
|
||||
torrent = backend.get_torrent(id)
|
||||
|
||||
if not torrent:
|
||||
print >>sys.stderr, 'Torrent "%s" not found' % id
|
||||
return 1
|
||||
|
||||
rows = []
|
||||
rows.append(('ID', torrent.id))
|
||||
rows.append(('Name', torrent.name))
|
||||
rows.append(('Size', torrent.size))
|
||||
return {backend.name: rows}
|
||||
|
||||
@ConsoleApplication.command('Search torrents')
|
||||
def command_search(self, pattern=None):
|
||||
results = {}
|
||||
if pattern:
|
||||
results['BEFORE'] = u'Search pattern: %s' % pattern
|
||||
else:
|
||||
results['BEFORE'] = u'Last videos'
|
||||
results['HEADER'] = ('ID', 'Name', 'Size')
|
||||
|
||||
for backend, torrent in self.weboob.do('iter_torrents', pattern=pattern):
|
||||
row = ('%s.%s' % (backend.name,torrent.id), torrent.name, torrent.size)
|
||||
try:
|
||||
results[backend.name].append(row)
|
||||
except KeyError:
|
||||
results[backend.name] = [row]
|
||||
return results
|
||||
Loading…
Add table
Add a link
Reference in a new issue