def get_server_name(self, serverid, isdm=False):
        """Get the server name by its ID.

        :param serverid: The server ID.
        :param isdm: A flag to check whether we're in a DM or not.
        """

        if isdm:
            return serverid

        request = SimpleRequest(self.headers).request
        server = request.grab_page('https://discordapp.com/api/%s/guilds/%s' %
                                   (self.api, serverid))

        if server is not None and len(server) > 0:
            return '%s_%s' % (serverid, safe_name(server['name']))

        else:
            error(
                'Unable to fetch server name from id, generating one instead.')
            return '%s_%s' % (serverid, random_str(12))
    def get_channel_name(self, channelid, isdm=False):
        """Get the channel name by its ID.

        :param channelid: The channel ID.
        :param isdm: A flag to check whether we're in a DM or not.
        """

        if isdm:
            return channelid

        request = SimpleRequest(self.headers).request
        channel = request.grab_page(
            'https://discordapp.com/api/%s/channels/%s' %
            (self.api, channelid))

        if channel is not None and len(channel) > 0:
            return '%s_%s' % (channelid, safe_name(channel['name']))

        else:
            error(
                'Unable to fetch channel name from id, generating one instead.'
            )
            return '%s_%s' % (channelid, random_str(12))
    def grab_data(self, folder, server, channel, isdm=False):
        """Scan and grab the attachments.

        :param folder: The folder name.
        :param server: The server name.
        :param channel: The channel name.
        :param isdm: A flag to check whether we're in a DM or not.
        """

        date = datetime.today()

        while date.year >= 2017:
            request = SimpleRequest(self.headers).request
            today = get_day(date.day, date.month, date.year)

            if not isdm:
                request.set_header(
                    'referer', 'https://discordapp.com/channels/%s/%s' %
                    (server, channel))
                content = request.grab_page(
                    'https://discordapp.com/api/%s/guilds/%s/messages/search?channel_id=%s&min_id=%s&max_id=%s&%s'
                    % (self.api, server, channel, today['00:00'],
                       today['23:59'], self.query))
            else:
                request.set_header(
                    'referer',
                    'https://discordapp.com/channels/@me/%s' % channel)
                content = request.grab_page(
                    'https://discordapp.com/api/%s/channels/%s/messages/search?min_id=%s&max_id=%s&%s'
                    % (self.api, channel, today['00:00'], today['23:59'],
                       self.query))

            try:
                if content['messages'] is not None:
                    for messages in content['messages']:
                        for message in messages:
                            self.check_config_mimetypes(message, folder)

                            if self.types['text'] is True:
                                if len(message['content']) > 0:
                                    self.insert_text(server, channel, message)
            except TypeError:
                continue

            date += timedelta(days=-1)
            time.sleep(1)
    def download(self, url, folder):
        """Download the contents of a URL.

        :param url: The target URL.
        :param folder: The target folder.
        """

        request = SimpleRequest(self.headers).request
        request.set_header(
            'user-agent',
            'Mozilla/5.0 (X11; Linux x86_64) Chrome/78.0.3904.87 Safari/537.36'
        )

        filename = safe_name('%s_%s' %
                             (url.split('/')[-2], url.split('/')[-1]))
        if not path.exists(filename):
            request.stream_file(url, folder, filename, self.buffer)