add command 'download'
This commit is contained in:
parent
c63e608388
commit
0d5e63e429
1 changed files with 32 additions and 1 deletions
|
|
@ -15,8 +15,9 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
from weboob.capabilities.video import ICapVideo
|
from weboob.capabilities.video import ICapVideo
|
||||||
from weboob.capabilities.base import NotLoaded
|
from weboob.capabilities.base import NotLoaded
|
||||||
|
|
@ -92,6 +93,36 @@ class Videoob(ReplApplication):
|
||||||
def _complete_id(self):
|
def _complete_id(self):
|
||||||
return ['%s@%s' % (video.id, video.backend) for video in self.videos]
|
return ['%s@%s' % (video.id, video.backend) for video in self.videos]
|
||||||
|
|
||||||
|
def complete_download(self, text, line, *ignored):
|
||||||
|
args = line.split(' ')
|
||||||
|
if len(args) == 2:
|
||||||
|
return self._complete_id()
|
||||||
|
elif len(args) >= 3:
|
||||||
|
return self.path_completer(args[2])
|
||||||
|
|
||||||
|
def do_download(self, line):
|
||||||
|
"""
|
||||||
|
download ID [FILENAME]
|
||||||
|
|
||||||
|
Download a video
|
||||||
|
"""
|
||||||
|
_id, dest = self.parse_command_args(line, 2, 1)
|
||||||
|
video = self._get_video(_id, ['url'])
|
||||||
|
if not video:
|
||||||
|
print 'Video not found: %s' % _id
|
||||||
|
return 1
|
||||||
|
|
||||||
|
with open('/dev/null', 'w') as devnull:
|
||||||
|
process = subprocess.Popen(['which', 'wget'], stdout=devnull)
|
||||||
|
if process.wait() != 0:
|
||||||
|
print >>sys.stderr, 'Please install "wget"'
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if dest is not None:
|
||||||
|
os.system('wget %s -O %s' % (video.url, dest))
|
||||||
|
else:
|
||||||
|
os.system('wget %s' % (video.url))
|
||||||
|
|
||||||
def complete_play(self, text, line, *ignored):
|
def complete_play(self, text, line, *ignored):
|
||||||
args = line.split(' ')
|
args = line.split(' ')
|
||||||
if len(args) == 2:
|
if len(args) == 2:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue