Ejemplo n.º 1
0
 def __init__(self, reddit_object):
     """
     Extracts content from hosting websites obtained from links that are posted to reddit.  Responsible for assigning
     the extractor object to be used, calling the necessary methods to extract the content, handling failed extract
     messages and logging, and storing extracted content in the supplied reddit objects content list.
     :param reddit_object: The reddit object for which contains lists of posts to be extracted.
     :type reddit_object: RedditObject
     """
     self.settings_manager = Injector.get_settings_manager()
     self.logger = logging.getLogger('DownloaderForReddit.%s' % __name__)
     self.reddit_object = reddit_object
Ejemplo n.º 2
0
 def get_nsfw_filter(reddit_object):
     """
     Returns the supplied reddit objects nsfw_filter method if the attribute exists and returns the global 
     nsfw_filter if it does not.
     :param reddit_object: The old reddit object.
     :return: The nsfw_filter appropriate for the supplied reddit object
     """
     try:
         return reddit_object.nsfw_filter
     except AttributeError:
         return Injector.get_settings_manager().nsfw_filter
Ejemplo n.º 3
0
    def __init__(self, name, list_type):
        """
        A model of reddit objects (users or subreddits) to be displayed in the GUI list views

        :param name: The name of the list
        :param list_type: The type of list (user or subreddit)

        The reddit_object_list is a list of actual objects which are instances of the RedditObjects subclasses
        The display_list is a list of the names of the items in the reddit_object_list as strings. These are what
        are actually displayed in the list view
        """
        super().__init__()
        self.logger = logging.getLogger('DownloaderForReddit.%s' % __name__)
        self.settings_manager = Injector.get_settings_manager()
        self.name = name
        self.list_type = list_type
        self.reddit_object_list = []
    def __init__(self):
        """
        A dialog class that controls settings for the UserFinder.
        """
        QDialog.__init__(self)
        self.setupUi(self)
        self.settings_manager = Injector.get_settings_manager()

        self.button_box.accepted.connect(self.accept)
        self.button_box.rejected.connect(self.close)

        self.double_click_operation_dict = {
            'DIALOG': self.open_link_in_dialog_radio,
            'BROWSER': self.open_link_in_browser_radio
        }

        self.sample_method_radio_dict = {
            'TOP': self.user_top_radio,
            'NEW': self.user_new_radio,
            'SELECTED_ONLY': self.user_selected_only_radio,
            'SELECTED_TOP': self.user_selected_top_radio,
            'SELECTED_NEW': self.user_selected_new_radio
        }

        self.run_with_main_checkbox.setChecked(
            self.settings_manager.user_finder_run_with_main)
        self.auto_add_checkbox.setChecked(
            self.settings_manager.user_finder_auto_add_found)
        self.silent_run_checkbox.setChecked(
            self.settings_manager.user_finder_auto_run_silent)
        self.show_reddit_page_checkbox.setChecked(
            self.settings_manager.user_finder_show_users_reddit_page)
        self.sample_size_spinbox.setValue(
            self.settings_manager.user_finder_sample_size)
        self.sample_method_radio_dict[
            self.settings_manager.user_finder_sample_type_method].setChecked(
                True)
        self.double_click_operation_dict[
            self.settings_manager.
            user_finder_double_click_operation].setChecked(True)
Ejemplo n.º 5
0
    def __init__(self, subreddit_list, user_blacklist, user_view_chooser_dict):
        """
        A class that takes a list of subreddits and extracts each subreddits top posts based on supplied settings then
        makes a list of the users that made the posts.  The found users top or new posts are then extracted and the the
        found user is sent to be displayed

        :param subreddit_list: A list of subreddit names to be scanned.
        :param user_blacklist: A list of reddit user names that if found by the search will not be included in the found
                               list.
        :param user_view_chooser_dict: The main window view chooser dict so that existing names can be matched and
                                       excluded from the found users list.
        """
        super().__init__()
        self.settings_manager = Injector.get_settings_manager()
        self._r = self.settings_manager.r
        self.post_filter = PostFilter()
        self.subreddit_list = subreddit_list
        self.blacklist = user_blacklist
        self.user_view_chooser_dict = user_view_chooser_dict

        self.valid_subreddit_list = []
        self.user_name_list = []
        self.valid_user_list = []
Ejemplo n.º 6
0
 def __init__(self):
     self.settings_manager = Injector.get_settings_manager()
Ejemplo n.º 7
0
    def __init__(self, url, user, post_title, subreddit, submission_id,
                 number_in_seq, file_ext, save_path, subreddit_save_method,
                 date_created, display_only):
        """
        Class that holds information about a single file extracted from a reddit submission that is to be downloaded as
        content.  Also holes the method to download the file.

        :param url: The url that the file to be downloaded is located at
        :param user:  The reddit user who submitted to content to reddit
        :param subreddit:  The subreddit the content was submitted to
        :param submission_id:  The content identifier that is to be made part of the file name when the content is saved
                (e.g. the album id if the url is from an imgur album)
        :param number_in_seq:  The number of the file in a sequence of files (e.g. if the file is from an album)
        :param file_ext:  The extension of the file, used to save the file with the correct extension
        """
        super().__init__()
        self.logger = logging.getLogger('DownloaderForReddit.%s' % __name__)
        self.settings_manager = Injector.get_settings_manager()
        self.url = url
        self.user = user
        self.post_title = post_title
        self.subreddit = subreddit
        self.submission_id = submission_id
        self.number_in_seq = number_in_seq
        self.file_ext = file_ext
        self.save_path = '%s%s' % (save_path,
                                   '/' if not save_path.endswith('/') else '')
        self.subreddit_save_method = subreddit_save_method
        self.date_created = date_created
        self.display_only = display_only
        self.output = ''
        self.setAutoDelete(False)
        self.downloaded = False
        self.check_path = None

        self.queue = None

        if not self.display_only:
            if self.subreddit_save_method is None:
                self.filename = '%s%s%s%s' % (
                    self.save_path, self.clean_filename(
                        self.submission_id), self.number_in_seq, self.file_ext)
                self.check_path = self.save_path

            elif self.subreddit_save_method == 'User Name':
                self.filename = '%s%s/%s%s%s' % (
                    self.save_path, self.user,
                    self.clean_filename(
                        self.submission_id), self.number_in_seq, self.file_ext)
                self.check_path = '%s%s/' % (self.save_path, self.user)

            elif self.subreddit_save_method == 'Subreddit Name':
                self.filename = '%s%s/%s%s%s' % (
                    self.save_path, self.subreddit,
                    self.clean_filename(
                        self.submission_id), self.number_in_seq, self.file_ext)
                self.check_path = '%s%s' % (self.save_path, self.subreddit)

            elif self.subreddit_save_method == 'Subreddit Name/User Name':
                self.filename = '%s%s/%s/%s%s%s' % (
                    self.save_path, self.subreddit, self.user,
                    self.clean_filename(
                        self.submission_id), self.number_in_seq, self.file_ext)
                self.check_path = '%s%s/%s/' % (self.save_path, self.subreddit,
                                                self.user)

            elif self.subreddit_save_method == 'User Name/Subreddit Name':
                self.filename = '%s%s/%s/%s%s%s' % (
                    self.save_path, self.user, self.subreddit,
                    self.clean_filename(
                        self.submission_id), self.number_in_seq, self.file_ext)
                self.check_path = '%s%s/%s' % (self.save_path, self.user,
                                               self.subreddit)
            else:
                self.filename = '%s%s%s%s' % (
                    self.save_path, self.clean_filename(
                        self.submission_id), self.number_in_seq, self.file_ext)
                self.check_path = self.save_path
    def __init__(self, list_model, init_item, downloader_running):
        """
        Allows reddit object settings to be changed individually.
        :param list_model: The current list model that is being displayed in the main GUI window.
        :param init_item: The item that was clicked in order to bring this dialog up and the item who's settings will
                          first be displayed.
        :type list_model: ListModel or list
        :type init_item: RedditObject
        """
        QtWidgets.QDialog.__init__(self)
        self.setupUi(self)
        self.logger = logging.getLogger('DownloaderForReddit.%s' % __name__)
        self.running = downloader_running
        try:
            self.object_list = list_model.reddit_object_list
        except AttributeError:
            self.object_list = list_model
        self.display_list = [x.name for x in self.object_list]
        self.current_object = init_item
        self.restore_defaults = False
        self.closed = False
        self.object_type = init_item.object_type

        if not self.running and len(self.current_object.content) <= 0:
            self.editing_disabled_label.setVisible(False)
            self.current_temp_object = copy.deepcopy(self.current_object)
        else:
            self.current_temp_object = None
            self.set_edit_disabled()
        self.temp_object_dict = {}

        self.settings_manager = Injector.get_settings_manager()
        geom = self.settings_manager.reddit_object_settings_dialog_geom
        state = self.settings_manager.reddit_object_settings_dialog_splitter_state
        self.restoreGeometry(geom if geom is not None else self.saveGeometry())
        self.splitter.restoreState(
            state if state is not None else self.splitter.saveState())
        self.show_downloads = True

        self.subreddit_sort_dict = {}

        if self.object_type == 'USER':
            self.sub_sort_label.setVisible(False)
            self.sub_sort_combo.setVisible(False)
            self.save_by_method_label.setVisible(False)
            self.save_by_method_combo.setVisible(False)
        else:
            self.download_object_button.setText('Download This Subreddit')
            self.save_by_method_combo.addItems(
                ('Subreddit Name', 'User Name', 'Subreddit Name/User Name',
                 'User Name/Subreddit Name'))
            self.sub_sort_combo.addItems(
                ('New', 'Hot', 'Rising', 'Controversial', 'Top - Hour',
                 'Top - Day', 'Top - Week', 'Top - Month', 'Top - Year',
                 'Top - All'))
            self.set_subreddit_sort_combo()

        self.nsfw_filter_combo.addItems(
            self.settings_manager.nsfw_filter_dict.keys())

        self.total_downloads_title_label.setText('Total %s Downloads:' %
                                                 self.object_type_str)

        self.content_icons_full_width = self.settings_manager.reddit_object_content_icons_full_width
        self.content_icon_size = self.settings_manager.reddit_object_content_icon_size

        self.current_item_display = self.settings_manager.current_reddit_object_settings_item_display_list
        self.item_display_list_model = RedditObjectItemDisplayModel(
            self.current_temp_object, self.current_item_display)
        self.item_display_list_view.setModel(self.item_display_list_model)

        self.download_object_button.clicked.connect(self.download_single)
        self.view_downloads_button.clicked.connect(self.change_page)

        for item in self.display_list:
            self.object_list_widget.addItem(item)
        self.object_list_widget.setCurrentRow(
            self.display_list.index(self.current_object.name))
        self.object_list_widget.currentRowChanged.connect(
            self.list_item_change)

        self.save_cancel_buton_box.accepted.connect(self.accept)
        self.save_cancel_buton_box.rejected.connect(self.close)
        self.restore_defaults_button.clicked.connect(self.set_restore_defaults)

        self.name_downloads_combo.addItems(('Image/Album Id', 'Post Title'))

        self.saved_content_name_dict = {}
        self.setup()

        self.page_one_geom = None
        self.page_two_geom = None

        self.restrict_date_checkbox.setToolTip(
            'Right click to reset to %s date to last downloaded link date' %
            self.object_type_str)

        self.object_list_widget.setContextMenuPolicy(
            QtCore.Qt.CustomContextMenu)
        self.object_list_widget.customContextMenuRequested.connect(
            self.object_list_right_click)
        self.object_list_widget.doubleClicked.connect(
            lambda: self.open_item_download_folder(self.object_list_widget.
                                                   currentRow()))

        self.content_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.content_list.customContextMenuRequested.connect(
            self.content_list_right_click)
        self.content_list.doubleClicked.connect(self.open_file)

        self.item_display_list_view.setContextMenuPolicy(
            QtCore.Qt.CustomContextMenu)
        self.item_display_list_view.customContextMenuRequested.connect(
            self.item_display_list_right_click)

        self.restrict_date_checkbox.setContextMenuPolicy(
            QtCore.Qt.CustomContextMenu)
        self.restrict_date_checkbox.customContextMenuRequested.connect(
            self.date_right_click)

        self.date_limit_edit.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.date_limit_edit.customContextMenuRequested.connect(
            self.date_right_click)

        self.save_by_method_combo.currentIndexChanged.connect(
            self.set_save_path_name_label)

        self.setup_window_title(None)