Ejemplo n.º 1
0
    def pre_download(self):
        """ Downloads some content to start safely the player. """

        # Download the subtitle
        gobject.idle_add(self.gui_manager.set_status_message,
            gettext("Downloading subtitles..."))

        # Wait for the file to exists
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Please wait..."))
        while not os.path.exists(self.file_path):
            time.sleep(1)

        # Show the progress bar box
        gobject.idle_add(self.gui_manager.progress.set_fraction, 0.0)
        gobject.idle_add(self.gui_manager.progress_box.show)
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Filling cache..."))

        if self.downloader.file_size != 0:
            # Waits %1 of the total download
            percent = self.downloader.file_size * 0.01

            while self.downloader.downloaded_size < percent:
                self._update_progress()
                self.update_speed()
                time.sleep(1)
        else:
            # Waits 2MB, just an arbitrary amount
            while self.downloader.downloaded_size < 2 * 1024 * 1024:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(0.5)
Ejemplo n.º 2
0
    def pre_download(self):
        """ Downloads some content to start safely the player. """

        # Download the subtitle
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Downloading subtitles..."))

        # Wait for the file to exists
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Please wait..."))
        while not os.path.exists(self.file_path):
            time.sleep(1)

        # Show the progress bar box
        gobject.idle_add(self.gui_manager.progress.set_fraction, 0.0)
        gobject.idle_add(self.gui_manager.progress_box.show)
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Filling cache..."))

        if self.downloader.file_size != 0:
            # Waits %1 of the total download
            percent = self.downloader.file_size * 0.01

            while self.downloader.downloaded_size < percent:
                self._update_progress()
                self.update_speed()
                time.sleep(1)
        else:
            # Waits 2MB, just an arbitrary amount
            while self.downloader.downloaded_size < 2 * 1024 * 1024:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(0.5)
Ejemplo n.º 3
0
    def update(self):
        """ Updates the GUI with downloading data. """

        stop = False

        while not stop:
            downloaded_size = self.downloader.downloaded_size

            self.update_speed()

            if self.speed > 0:
                remaining_size = (self.downloader.file_size -
                                  downloaded_size) / 1024.0
                remaining_time = (remaining_size / self.speed) / 60
            else:
                remaining_time = 0

            if remaining_time >= 1:  # if it's more than a minute
                if remaining_time == 1:
                    remaining_message = gettext(
                        "%d minute left") % remaining_time
                else:
                    remaining_message = gettext(
                        "%d minutes left") % remaining_time
            else:
                if (remaining_time * 60) > 10:
                    remaining_message = gettext("%d seconds left") % (
                        remaining_time * 60)
                elif remaining_time != 0:
                    remaining_message = gettext("a few seconds left")
                else:
                    remaining_message = ""

            if downloaded_size < self.downloader.file_size:
                gobject.idle_add(self.gui_manager.progress_label.set_text, \
                    "%.2fKB/s - %s" % (self.speed, remaining_message))
            else:
                gobject.idle_add(self.gui_manager.progress_label.set_text, "")

            if self.downloader.file_size != 0:
                self._update_progress()
                time.sleep(1)
            else:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(1)

            stop = downloaded_size == self.downloader.file_size

            if not self.download_only:
                stop |= self.player_process.poll() != None
Ejemplo n.º 4
0
    def file_hosts(self):
        hosts = {}
        data = url_open(urls.show_sources % self.id)

        try:
            sources = json.loads(self._sources_re.search(data).group(1))
        except AttributeError:
            raise Exception(gettext("No host found"))

        for quality in sources:
            for host in sources[quality]["2"]:
                data = [("id", self.id), ("tipo", "serie"),
                        ("def", quality), ("audio", "2"),
                        ("host", host)]

                hostdata = url_open(urls.source_get, data=data)

                if "referer.us/" in hostdata:
                    hostdata = hostdata.replace("referer.us/", "")

                url = hostdata[hostdata.find('http:'):].split('&id')[0]

                if not host in hosts:
                    hosts[host] = {}

                hosts[host][quality] = url

        return hosts
Ejemplo n.º 5
0
    def file_hosts(self):
        hosts = {}
        data = url_open(urls.show_sources % self.id)

        try:
            sources = json.loads(self._sources_re.search(data).group(1))
        except AttributeError:
            raise Exception(gettext("No host found"))

        for quality in sources:
            for host in sources[quality]["2"]:
                data = [("id", self.id), ("tipo", "serie"), ("def", quality),
                        ("audio", "2"), ("host", host)]

                hostdata = url_open(urls.source_get, data=data)

                if "referer.us/" in hostdata:
                    hostdata = hostdata.replace("referer.us/", "")

                url = hostdata[hostdata.find('http:'):].split('&id')[0]

                if not host in hosts:
                    hosts[host] = {}

                hosts[host][quality] = url

        return hosts
Ejemplo n.º 6
0
    def __init__(self, gui_manager, file_object,
                 file_path=None, download_only=False, choose_host=False):
        self.gui_manager = gui_manager
        self.config = Config.get()

        self.file_object = file_object
        self.download_only = download_only
        self.choose_host = choose_host

        self.selected_quality = None

        self._speed_list = []
        self._last_downloaded_size = 0
        self.speed = 0

        self.file_path = file_path
        if not self.file_path:
            self.file_path = self.config.get_key("cache_dir")

        self.file_path = os.path.join(self.file_path, self.get_filename())

        # Builder for the hosts selection
        self.hosts_builder = gtk.Builder()
        self.hosts_builder.add_from_file(HOSTS_GUI_FILE)
        self.hosts_builder.connect_signals(self)

        glade_objects = ["hosts_window", "hosts_icon_view",
                         "hosts_icon_view_model"]

        for glade_object in glade_objects:
            setattr(self, glade_object,
                self.hosts_builder.get_object(glade_object))

        self.gui_manager.background_task(self.get_hosts, self.display_hosts,
            status_message=gettext("Fetching hosts..."), unfreeze=False)
Ejemplo n.º 7
0
    def wait_time(self):
        """ Waits the necesary time to start the download. """

        for i in range(self.account.wait_time, 0, -1):
            gobject.idle_add(self.gui_manager.set_status_message,
                gettext("Please wait %d second%s...") % (i, "s" * (i > 1)))
            time.sleep(1)
Ejemplo n.º 8
0
    def update(self):
        """ Updates the GUI with downloading data. """

        stop = False

        while not stop:
            downloaded_size = self.downloader.downloaded_size

            self.update_speed()

            if self.speed > 0:
                remaining_size = (self.downloader.file_size - downloaded_size) / 1024.0
                remaining_time = (remaining_size / self.speed) / 60
            else:
                remaining_time = 0

            if remaining_time >= 1:  # if it's more than a minute
                if remaining_time == 1:
                    remaining_message = gettext("%d minute left") % remaining_time
                else:
                    remaining_message = gettext("%d minutes left") % remaining_time
            else:
                if (remaining_time * 60) > 10:
                    remaining_message = gettext("%d seconds left") % (remaining_time * 60)
                elif remaining_time != 0:
                    remaining_message = gettext("a few seconds left")
                else:
                    remaining_message = ""

            if downloaded_size < self.downloader.file_size:
                gobject.idle_add(self.gui_manager.progress_label.set_text, \
                    "%.2fKB/s - %s" % (self.speed, remaining_message))
            else:
                gobject.idle_add(self.gui_manager.progress_label.set_text, "")

            if self.downloader.file_size != 0:
                self._update_progress()
                time.sleep(1)
            else:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(1)

            stop = downloaded_size == self.downloader.file_size

            if not self.download_only:
                stop |= self.player_process.poll() != None
Ejemplo n.º 9
0
    def _download_loop(self):
        """ Actually download the file. """

        self.add_range(URL_OPEN)
        try:
            handler = URL_OPEN(self.megalink, handle=True)
        except Exception, error:
            message = gettext("Error downloading from megaupload: %s") % error
            raise DownloadError(message)
Ejemplo n.º 10
0
    def send_captcha(self):
        gobject.idle_add(self.gui_manager.set_status_message,
            gettext("Sending Captcha..."))

        response_text = self.captcha_window.get_input_text()

        request_url = REQUEST_URL % self.download_id
        request_data = {"request": "validateCaptcha", "ajaxid": self.ajaxdl,
            "recaptcha_challenge_field": self.recaptcha_new_challenge,
            "recaptcha_response_field": response_text}

        page_data = MAIN_URL_OPEN(request_url, data=request_data)
        return page_data.count("SUCCESS") > 0
Ejemplo n.º 11
0
    def send_captcha(self):
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Sending Captcha..."))

        response_text = self.captcha_window.get_input_text()

        request_url = REQUEST_URL % self.download_id
        request_data = {
            "request": "validateCaptcha",
            "ajaxid": self.ajaxdl,
            "recaptcha_challenge_field": self.recaptcha_new_challenge,
            "recaptcha_response_field": response_text
        }

        page_data = MAIN_URL_OPEN(request_url, data=request_data)
        return page_data.count("SUCCESS") > 0
Ejemplo n.º 12
0
    def __init__(self,
                 gui_manager,
                 file_object,
                 file_path=None,
                 download_only=False,
                 choose_host=False):
        self.gui_manager = gui_manager
        self.config = Config.get()

        self.file_object = file_object
        self.download_only = download_only
        self.choose_host = choose_host

        self.selected_quality = None

        self._speed_list = []
        self._last_downloaded_size = 0
        self.speed = 0

        self.file_path = file_path
        if not self.file_path:
            self.file_path = self.config.get_key("cache_dir")

        self.file_path = os.path.join(self.file_path, self.get_filename())

        # Builder for the hosts selection
        self.hosts_builder = gtk.Builder()
        self.hosts_builder.add_from_file(HOSTS_GUI_FILE)
        self.hosts_builder.connect_signals(self)

        glade_objects = [
            "hosts_window", "hosts_icon_view", "hosts_icon_view_model"
        ]

        for glade_object in glade_objects:
            setattr(self, glade_object,
                    self.hosts_builder.get_object(glade_object))

        self.gui_manager.background_task(
            self.get_hosts,
            self.display_hosts,
            status_message=gettext("Fetching hosts..."),
            unfreeze=False)
Ejemplo n.º 13
0
    def _download_loop(self):
        request_url = REQUEST_URL % self.download_id
        request_data = {"request": "getDownloadURL", "ajaxid": self.ajaxdl}

        page_data = MAIN_URL_OPEN(request_url, data=request_data)

        if not page_data.startswith("SUCCESS"):
            message = gettext("Not success finding the bitshare " \
                              "download link. Got: %s") % page_data

            self.gui_manager.report_error(message)
            return

        real_link = page_data.split("#")[1]

        self.add_range(MAIN_URL_OPEN)
        handler = MAIN_URL_OPEN(real_link, handle=True)

        # Using the BaseDownloader download function
        self.download_to(handler, self.file_path)
Ejemplo n.º 14
0
    def _download_loop(self):
        request_url = REQUEST_URL % self.download_id
        request_data = {"request": "getDownloadURL", "ajaxid": self.ajaxdl}

        page_data = MAIN_URL_OPEN(request_url, data=request_data)

        if not page_data.startswith("SUCCESS"):
            message = gettext("Not success finding the bitshare " \
                              "download link. Got: %s") % page_data

            self.gui_manager.report_error(message)
            return

        real_link = page_data.split("#")[1]

        self.add_range(MAIN_URL_OPEN)
        handler = MAIN_URL_OPEN(real_link, handle=True)

        # Using the BaseDownloader download function
        self.download_to(handler, self.file_path)
Ejemplo n.º 15
0
class Megaupload(BaseDownloader):
    """ Megaupload's Downloader. """

    name = "Megaupload"
    icon_path = HOSTS_IMAGES_DIR + SEP + "megaupload.png"
    accept_ranges = True

    def __init__(self, gui_manager, url):
        BaseDownloader.__init__(self, URL_OPEN, gui_manager, url)

        self.gui_manager = gui_manager
        self.url = url
        self.stop_downloading = False

    def process_url(self, play_callback, file_path):
        """ Start the download process. """

        self.play_callback = play_callback
        self.file_path = file_path

        self.gui_manager.background_task(self.get_megalink,
                    self._on_megalink_finish, unfreeze=False)

    def wait_time(self):
        """ Waits the necesary time to start the download. """

        for i in range(self.account.wait_time, 0, -1):
            gobject.idle_add(self.gui_manager.set_status_message,
                gettext("Please wait %d second%s...") % (i, "s" * (i > 1)))
            time.sleep(1)

    def start_download(self, (is_error, result)):
        """ Starts the actually download loop and opens up the player. """
        if is_error:
            self.gui_manager.report_error(gettext("Error: %s") % result)
            return

        self.gui_manager.background_task(self._download_loop,
                    self._on_download_finish, unfreeze=False)

        self.play_callback()
Ejemplo n.º 16
0
    def start_regular(self):
        if self.user and self.password and ACCOUNT.account_type=="Premium":
            console("trying with cool API")
            id_ = URL_ID_RE.search(self.url).group(1)
            self.file_url = API_DOWNLOAD % (self.user, self.password, id_)
            console(self.file_url)
            return False

        page_data = self.MAIN_URL_OPEN(self.url)

        if "this file has been removed" in page_data:
            raise Exception(gettext("File removed"))

        try:
            self.regular_url = REGULAR_URL_RE.search(page_data).group(1)
            self.regular_url = "http://www.wupload.com/file/" + self.regular_url + "/" + self.regular_url + "?start=1"
        except Exception, e:
            msg = "Regular link not found"
            log.error(msg)
            log.error(e.message)
            tmp_dump(page_data, link)
            raise DownloadError(msg)
Ejemplo n.º 17
0
    def start_regular(self):
        if self.user and self.password and ACCOUNT.account_type == "Premium":
            console("trying with cool API")
            id_ = URL_ID_RE.search(self.url).group(1)
            self.file_url = API_DOWNLOAD % (self.user, self.password, id_)
            console(self.file_url)
            return False

        page_data = self.MAIN_URL_OPEN(self.url)

        if "this file has been removed" in page_data:
            raise Exception(gettext("File removed"))

        try:
            self.regular_url = REGULAR_URL_RE.search(page_data).group(1)
            self.regular_url = "http://www.wupload.com/file/" + self.regular_url + "/" + self.regular_url + "?start=1"
        except Exception, e:
            msg = "Regular link not found"
            log.error(msg)
            log.error(e.message)
            tmp_dump(page_data, link)
            raise DownloadError(msg)
Ejemplo n.º 18
0
    def start_regular(self):
        page_data = MAIN_URL_OPEN(self.url)
        self.download_id = self.url.split("?f=")[1]

        if "Error - Archivo no disponible" in page_data:
            msg = "File not avaliable anymore"
            log.warn(msg)
            raise Exception(msg)

        try:
            self.ajaxdl = AJAXDL_RE.search(page_data).group(1)
        except:
            msg = "ajaxid not found"
            log.warn(msg)
            raise DownloadError(msg)

        try:
            self.recaptcha_challenge_id = RECAPTCHA_CHALLENGE_ID_RE.search(
                page_data).group(1)
        except:
            log.error("Captcha id not found")
            self.recaptcha_challenge_id = None

        request_url = REQUEST_URL % self.download_id
        request_data = {"request": "generateID", "ajaxid": self.ajaxdl}

        page_data = MAIN_URL_OPEN(request_url, data=request_data)
        page_data = page_data.split(":")
        waiting_time = int(page_data[1])
        has_captcha = page_data[2] == "1"

        for i in range(waiting_time, 0, -1):
            gobject.idle_add(
                self.gui_manager.set_status_message,
                gettext("Please wait %d second%s...") % (i, "s" * (i > 1)))
            time.sleep(1)

        return has_captcha
Ejemplo n.º 19
0
    def start_regular(self):
        page_data = MAIN_URL_OPEN(self.url)
        self.download_id = self.url.split("?f=")[1]

        if "Error - Archivo no disponible" in page_data:
            msg = "File not avaliable anymore"
            log.warn(msg)
            raise Exception(msg)

        try:
            self.ajaxdl = AJAXDL_RE.search(page_data).group(1)
        except:
            msg = "ajaxid not found"
            log.warn(msg)
            raise DownloadError(msg)

        try:
            self.recaptcha_challenge_id = RECAPTCHA_CHALLENGE_ID_RE.search(page_data).group(1)
        except:
            log.error("Captcha id not found")
            self.recaptcha_challenge_id = None

        request_url = REQUEST_URL % self.download_id
        request_data = {"request": "generateID", "ajaxid": self.ajaxdl}

        page_data = MAIN_URL_OPEN(request_url, data=request_data)
        page_data = page_data.split(":")
        waiting_time = int(page_data[1])
        has_captcha = page_data[2] == "1"

        for i in range(waiting_time, 0, -1):
            gobject.idle_add(self.gui_manager.set_status_message,
                gettext("Please wait %d second%s...") % (i, "s" * (i > 1)))
            time.sleep(1)

        return has_captcha
Ejemplo n.º 20
0
        real_link = page_data.split("#")[1]

        self.add_range(MAIN_URL_OPEN)
        handler = MAIN_URL_OPEN(real_link, handle=True)

        # Using the BaseDownloader download function
        self.download_to(handler, self.file_path)

    def _on_captcha_ok(self):
        self.gui_manager.background_task(self.send_captcha,
            self._on_captcha_finish)

    def _on_captcha_finish(self, (is_error, result)):
        if not result:
            self.gui_manager.report_error(gettext("Wrong captcha"))
            return

        self.gui_manager.background_task(self._download_loop,
            self._on_download_finish)

        self.play_callback()

    def _on_download_finish(self, (is_error, result)):
        if is_error:
            if "Requested Range Not Satisfiable" in str(result):
                self.file_size = self.downloaded_size
            else:
                message = gettext("Download finish with error: %s") % result
                self.gui_manager.report_error(message)
Ejemplo n.º 21
0
            try:
                self.recaptcha_challenge_id = RECAPTCHA_CHALLENGE_ID_RE.search(
                    regular_data).group(1)
            except Exception, e:
                msg = "Captcha challenge not found!"
                log.error(msg)
                log.error(e.message)
                tmp_dump(page_data, self.url)
                raise DownloadError(msg)

        return has_captcha

    def on_waiting_finish(self, (is_error, result)):
        if is_error:
            message = gettext("Error obtaining wuploads's link: %s" % result)
            self.gui_manager.report_error(message)
            return
        else:
            has_captcha = result

            if not has_captcha:
                self._on_captcha_finish((False, None))
            else:
                self.gui_manager.background_task(self.request_captcha,
                                                 self.captcha_window.show)

        return None

    def request_captcha(self):
        assert self.recaptcha_challenge_id != None, "Captcha required but challenge not found"
Ejemplo n.º 22
0
class Wupload(BaseDownloader):
    """ Wupload's Downloader. """

    name = "Wupload"
    icon_path = HOSTS_IMAGES_DIR + SEP + "wupload.png"
    accept_ranges = True

    def __init__(self, gui_manager, url):
        self.MAIN_URL_OPEN = UrlOpen(use_cache=False)
        BaseDownloader.__init__(self, self.MAIN_URL_OPEN, gui_manager, url)

        self.url = url
        self.gui_manager = gui_manager
        self.config = Config.get()
        self.user = None
        self.password = None
        accounts = self.config.get_key("accounts")

        for host, data in accounts:
            if host == "wupload":
                self.user = data["username"]
                self.password = base64.b64decode(data["password"])

        self.captcha_window = CaptchaWindow(gui_manager, self._on_captcha_ok)

        self.MAIN_URL_OPEN.add_headers({
            "Referer": url,
            "Origin": "http://www.wupload.com",
            "Host": "www.wupload.com",
        })

        CAPTCHA_URL_OPEN.add_headers({"referer": url})

    def process_url(self, play_callback, file_path):
        self.play_callback = play_callback
        self.file_path = file_path

        self.gui_manager.background_task(self.start_regular,
                                         self.on_waiting_finish,
                                         unfreeze=False)

    def start_regular(self):
        if self.user and self.password and ACCOUNT.account_type == "Premium":
            console("trying with cool API")
            id_ = URL_ID_RE.search(self.url).group(1)
            self.file_url = API_DOWNLOAD % (self.user, self.password, id_)
            console(self.file_url)
            return False

        page_data = self.MAIN_URL_OPEN(self.url)

        if "this file has been removed" in page_data:
            raise Exception(gettext("File removed"))

        try:
            self.regular_url = REGULAR_URL_RE.search(page_data).group(1)
            self.regular_url = "http://www.wupload.com/file/" + self.regular_url + "/" + self.regular_url + "?start=1"
        except Exception, e:
            msg = "Regular link not found"
            log.error(msg)
            log.error(e.message)
            tmp_dump(page_data, link)
            raise DownloadError(msg)

        self.MAIN_URL_OPEN.add_headers({"X-Requested-With": "XMLHttpRequest"})
        print "REGULAR URL", self.regular_url
        regular_data = self.MAIN_URL_OPEN(self.regular_url)

        if "countDownDelay" in regular_data:
            waiting_time = int(WAITING_TIME_RE.search(regular_data).group(1))

            try:
                tm = int(TM_RE.search(regular_data).group(1))
                tm_hash = TM_HASH_RE.search(regular_data).group("value")
                tm_data = {"tm": tm, "tm_hash": tm_hash}
            except:
                tm_data = None

            for i in range(waiting_time, 0, -1):
                gobject.idle_add(
                    self.gui_manager.set_status_message,
                    gettext("Please wait %d second%s...") % (i, "s" * (i > 1)))
                time.sleep(1)

            log.info("Trying to get captcha..")
            log.info(tm_data)
            regular_data = self.MAIN_URL_OPEN(self.regular_url, data=tm_data)

        if "Download Ready" in regular_data:
            has_captcha = False
            self.file_url = FILE_URL_RE.search(regular_data).group(1)
        else:
            has_captcha = True

            try:
                self.recaptcha_challenge_id = RECAPTCHA_CHALLENGE_ID_RE.search(
                    regular_data).group(1)
            except Exception, e:
                msg = "Captcha challenge not found!"
                log.error(msg)
                log.error(e.message)
                tmp_dump(page_data, self.url)
                raise DownloadError(msg)
Ejemplo n.º 23
0
            while self.downloader.downloaded_size < percent:
                self._update_progress()
                self.update_speed()
                time.sleep(1)
        else:
            # Waits 2MB, just an arbitrary amount
            while self.downloader.downloaded_size < 2 * 1024 * 1024:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(0.5)

    def open_player(self, (is_error, result)):
        """ Fires up a new process with the player runing. """

        if is_error:
            self.gui_manager.report_error(
                gettext("Error pre-downloading: %s") % result)
            return

        if self.download_only:
            message = gettext("Downloading: %s")
        else:
            message = gettext("Playing: %s")

        gobject.idle_add(self.gui_manager.set_status_message,
                         message % self.file_object.name)

        player_location = self.config.get_key("player_location")
        player_args = self.config.get_key("player_arguments").split()
        player_cmd = [player_location] + player_args + [self.file_path]

        if not self.download_only:
Ejemplo n.º 24
0
class Player(object):
    """
    Class that takes care of the downloading and correctly
    playing the file.
    """
    def __init__(self,
                 gui_manager,
                 file_object,
                 file_path=None,
                 download_only=False,
                 choose_host=False):
        self.gui_manager = gui_manager
        self.config = Config.get()

        self.file_object = file_object
        self.download_only = download_only
        self.choose_host = choose_host

        self.selected_quality = None

        self._speed_list = []
        self._last_downloaded_size = 0
        self.speed = 0

        self.file_path = file_path
        if not self.file_path:
            self.file_path = self.config.get_key("cache_dir")

        self.file_path = os.path.join(self.file_path, self.get_filename())

        # Builder for the hosts selection
        self.hosts_builder = gtk.Builder()
        self.hosts_builder.add_from_file(HOSTS_GUI_FILE)
        self.hosts_builder.connect_signals(self)

        glade_objects = [
            "hosts_window", "hosts_icon_view", "hosts_icon_view_model"
        ]

        for glade_object in glade_objects:
            setattr(self, glade_object,
                    self.hosts_builder.get_object(glade_object))

        self.gui_manager.background_task(
            self.get_hosts,
            self.display_hosts,
            status_message=gettext("Fetching hosts..."),
            unfreeze=False)

    def get_hosts(self):
        """ Returns a dict with the avaliable downloaders for the file. """

        result = {}
        avaliable_downloaders = Downloaders.get_avaliable()

        hosts = self.file_object.file_hosts

        hosts["dummy"] = ""

        for host in hosts:
            host = host.lower()
            if host in avaliable_downloaders:
                result[host] = hosts[host]

        return result

    def display_hosts(self, (is_error, result)):
        """ Shows up the hosts selecting window. """

        gobject.idle_add(self.gui_manager.set_status_message, "")

        if is_error:
            self.gui_manager.report_error(gettext("Error fetching hosts: %s") % \
                                          result)
            gobject.idle_add(self.gui_manager.progress_box.hide)
            return

        if not result:
            self.gui_manager.report_error(gettext("No host found"))
            self.gui_manager.unfreeze()
            return

        automatic_start = self.config.get_key("automatic_start")

        if automatic_start and len(result) == 1 and not self.choose_host:
            host, qualities = result.items()[0]

            if len(qualities) == 1:
                gobject.idle_add(
                    self.gui_manager.set_status_message,
                    gettext("Only one host found, starting download..."))

                url = qualities.items()[0][1]
                self.downloader = Downloaders.get(host, self.gui_manager, url)
                self.downloader.process_url(self.play, self.file_path)
                return

        for host in result:
            for quality in result[host]:
                downloader = Downloaders.get(host, self.gui_manager,
                                             result[host][quality])
                icon = downloader.icon
                name = "%s (%s)" % (downloader.name, quality)

                self.hosts_icon_view_model.append([icon, name, downloader])

        self.hosts_window.show_all()
Ejemplo n.º 25
0
        except:
            raise Exception("File was removed.\n\nVisit: %s to " \
                            "make sure." % self.url)

        if not link:
            tmp_dump(page_data, link)
            raise Exception("No real file found")

        log.debug("Link obtained: %s" % link)
        return link

    def _on_megalink_finish(self, (is_error, result)):
        """ Called on finish finding the real link. """

        if is_error:
            message = gettext("Error obtaining megaupload's link: %s") % result
            self.gui_manager.report_error(message)
            return

        self.megalink = result

        self.gui_manager.background_task(self.wait_time,
                    self.start_download, unfreeze=False)

    def _download_loop(self):
        """ Actually download the file. """

        self.add_range(URL_OPEN)
        try:
            handler = URL_OPEN(self.megalink, handle=True)
        except Exception, error:
Ejemplo n.º 26
0
        real_link = page_data.split("#")[1]

        self.add_range(MAIN_URL_OPEN)
        handler = MAIN_URL_OPEN(real_link, handle=True)

        # Using the BaseDownloader download function
        self.download_to(handler, self.file_path)

    def _on_captcha_ok(self):
        self.gui_manager.background_task(self.send_captcha,
                                         self._on_captcha_finish)

    def _on_captcha_finish(self, (is_error, result)):
        if not result:
            self.gui_manager.report_error(gettext("Wrong captcha"))
            return

        self.gui_manager.background_task(self._download_loop,
                                         self._on_download_finish)

        self.play_callback()

    def _on_download_finish(self, (is_error, result)):
        if is_error:
            if "Requested Range Not Satisfiable" in str(result):
                self.file_size = self.downloaded_size
            else:
                message = gettext("Download finish with error: %s") % result
                self.gui_manager.report_error(message)
Ejemplo n.º 27
0
class Bitshare(BaseDownloader):
    """ Bitshare's Downloader. """

    name = "Bitshare"
    icon_path = HOSTS_IMAGES_DIR + SEP + "bitshare.png"
    accept_ranges = False

    def __init__(self, gui_manager, url):
        BaseDownloader.__init__(self, MAIN_URL_OPEN, gui_manager, url)

        self.gui_manager = gui_manager
        self.url = url

        self.captcha_window = CaptchaWindow(gui_manager, self._on_captcha_ok)

        CAPTCHA_URL_OPEN.add_headers({"referer": url})

    def process_url(self, play_callback, file_path):
        self.play_callback = play_callback
        self.file_path = file_path

        self.gui_manager.background_task(self.start_regular,
                                         self.on_waiting_finish,
                                         unfreeze=False)

    def start_regular(self):
        page_data = MAIN_URL_OPEN(self.url)
        self.download_id = self.url.split("?f=")[1]

        if "Error - Archivo no disponible" in page_data:
            msg = "File not avaliable anymore"
            log.warn(msg)
            raise Exception(msg)

        try:
            self.ajaxdl = AJAXDL_RE.search(page_data).group(1)
        except:
            msg = "ajaxid not found"
            log.warn(msg)
            raise DownloadError(msg)

        try:
            self.recaptcha_challenge_id = RECAPTCHA_CHALLENGE_ID_RE.search(
                page_data).group(1)
        except:
            log.error("Captcha id not found")
            self.recaptcha_challenge_id = None

        request_url = REQUEST_URL % self.download_id
        request_data = {"request": "generateID", "ajaxid": self.ajaxdl}

        page_data = MAIN_URL_OPEN(request_url, data=request_data)
        page_data = page_data.split(":")
        waiting_time = int(page_data[1])
        has_captcha = page_data[2] == "1"

        for i in range(waiting_time, 0, -1):
            gobject.idle_add(
                self.gui_manager.set_status_message,
                gettext("Please wait %d second%s...") % (i, "s" * (i > 1)))
            time.sleep(1)

        return has_captcha

    def on_waiting_finish(self, (is_error, result)):
        gobject.idle_add(self.gui_manager.set_status_message,
                         gettext("Obtaining bitshare link..."))

        if is_error:
            message = gettext("Error obtaining bitshare's link: %s") % result
            self.gui_manager.report_error(message)
            return

        has_captcha = result

        if has_captcha:
            self.gui_manager.background_task(self.request_captcha,
                                             self.captcha_window.show)
        else:
            self.gui_manager.background_task(self._download_loop,
                                             self._on_download_finish)

            self.play_callback()
Ejemplo n.º 28
0
            while self.downloader.downloaded_size < percent:
                self._update_progress()
                self.update_speed()
                time.sleep(1)
        else:
            # Waits 2MB, just an arbitrary amount
            while self.downloader.downloaded_size < 2 * 1024 * 1024:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(0.5)

    def open_player(self, (is_error, result)):
        """ Fires up a new process with the player runing. """

        if is_error:
            self.gui_manager.report_error(
                gettext("Error pre-downloading: %s") % result)
            return

        if self.download_only:
            message = gettext("Downloading: %s")
        else:
            message = gettext("Playing: %s")

        gobject.idle_add(self.gui_manager.set_status_message,
                         message % self.file_object.name)

        player_location = self.config.get_key("player_location")
        player_args = self.config.get_key("player_arguments").split()
        player_cmd = [player_location] + player_args + [self.file_path]

        if not self.download_only:
Ejemplo n.º 29
0
            while self.downloader.downloaded_size < percent:
                self._update_progress()
                self.update_speed()
                time.sleep(1)
        else:
            # Waits 2MB, just an arbitrary amount
            while self.downloader.downloaded_size < 2 * 1024 * 1024:
                gobject.idle_add(self.gui_manager.progress.pulse)
                time.sleep(0.5)

    def open_player(self, (is_error, result)):
        """ Fires up a new process with the player runing. """

        if is_error:
            self.gui_manager.report_error(gettext("Error pre-downloading: %s") % result)
            return

        if self.download_only:
            message = gettext("Downloading: %s")
        else:
            message = gettext("Playing: %s")

        gobject.idle_add(self.gui_manager.set_status_message,
                         message % self.file_object.name)

        player_location = self.config.get_key("player_location")
        player_args = self.config.get_key("player_arguments").split()
        player_cmd = [player_location] + player_args + [self.file_path]

        if not self.download_only:
Ejemplo n.º 30
0
            has_captcha = True

            try:
                self.recaptcha_challenge_id = RECAPTCHA_CHALLENGE_ID_RE.search(regular_data).group(1)
            except Exception, e:
                msg = "Captcha challenge not found!"
                log.error(msg)
                log.error(e.message)
                tmp_dump(page_data, self.url)
                raise DownloadError(msg)

        return has_captcha

    def on_waiting_finish(self, (is_error, result)):
        if is_error:
            message = gettext("Error obtaining wuploads's link: %s" % result)
            self.gui_manager.report_error(message)
            return
        else:
            has_captcha = result

            if not has_captcha:
                self._on_captcha_finish((False, None))
            else:
                self.gui_manager.background_task(self.request_captcha,
                    self.captcha_window.show)

        return None

    def request_captcha(self):
        assert self.recaptcha_challenge_id != None, "Captcha required but challenge not found"