2015-04-10 21:45:41 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-09-30 12:32:48 +02:00
|
|
|
# Copyright 2014-2016 Mike Fährmann
|
2015-04-10 21:45:41 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2016-09-30 12:32:48 +02:00
|
|
|
"""Downloader module for text:// urls"""
|
2015-04-10 21:45:41 +02:00
|
|
|
|
2014-10-12 21:56:44 +02:00
|
|
|
from .common import BasicDownloader
|
|
|
|
|
2017-01-30 19:40:15 +01:00
|
|
|
|
2014-10-12 21:56:44 +02:00
|
|
|
class Downloader(BasicDownloader):
|
|
|
|
|
2016-09-30 12:32:48 +02:00
|
|
|
def __init__(self, output):
|
2014-10-12 21:56:44 +02:00
|
|
|
BasicDownloader.__init__(self)
|
2016-09-30 12:32:48 +02:00
|
|
|
self.out = output
|
2014-10-12 21:56:44 +02:00
|
|
|
|
2016-09-30 12:32:48 +02:00
|
|
|
def download_impl(self, url, pathfmt):
|
|
|
|
if not pathfmt.has_extension:
|
|
|
|
pathfmt.set_extension("txt")
|
|
|
|
if pathfmt.exists():
|
|
|
|
self.out.skip(pathfmt.path)
|
|
|
|
return
|
|
|
|
|
|
|
|
self.out.start(pathfmt.path)
|
2016-11-27 23:43:25 +01:00
|
|
|
self.downloading = True
|
2016-09-30 12:32:48 +02:00
|
|
|
with pathfmt.open() as file:
|
|
|
|
file.write(bytes(url[7:], "utf-8"))
|
2016-11-27 23:43:25 +01:00
|
|
|
self.downloading = False
|
2016-09-30 12:32:48 +02:00
|
|
|
self.out.success(pathfmt.path, 0)
|