示例#1
0
    def add_plex_server(self, **kwargs) -> Union[PlexServer, None]:
        """
        Add a Plex Media Server to dizqueTV

        :param kwargs: keyword arguments of setting names and values
        :return: PlexServer object or None
        :rtype: PlexServer
        """
        if helpers._settings_are_complete(new_settings_dict=kwargs,
                                          template_settings_dict=PLEX_SERVER_SETTINGS_TEMPLATE,
                                          ignore_keys=['_id', 'id']) \
                and self._put(endpoint='/plex-servers', data=kwargs):
            return self.get_plex_server(server_name=kwargs['name'])
        return None
示例#2
0
    def add_filler_list(self,
                        content: List[Union[Program, Video, Movie, Episode]],
                        plex_server: PServer = None,
                        handle_errors: bool = False,
                        **kwargs) -> Union[FillerList, None]:
        """
        Add a filler list to dizqueTV
        Must include at least one program to create

        :param content: At least one Program or PlexAPI Video, Movie or Episode to add to the new filler list
        :type content: List[Union[Program, Video, Movie, Episode]]
        :param plex_server: plexapi.server.PlexServer (optional, required if adding PlexAPI Video, Movie or Episode)
        :type plex_server: plexapi.server.PlexServer, optional
        :param kwargs: keyword arguments of setting names and values
        :param handle_errors: Suppress error if they arise (ex. add redirect if no program is included)
        :type handle_errors: bool, optional
        :return: new FillerList object or None
        :rtype: FillerList
        """
        kwargs['content'] = []
        for item in content:
            if type(item) == FillerItem:
                kwargs['content'].append(item)
            else:
                if not plex_server:
                    raise ItemCreationError(
                        "You must include a plex_server if you are adding PlexAPI Video, "
                        "Movie or Episodes as programs")
                kwargs['content'].append(
                    convert_plex_item_to_filler_item(
                        plex_item=item, plex_server=plex_server)._data)
        kwargs = self._fill_in_default_filler_list_settings(
            settings_dict=kwargs, handle_errors=handle_errors)
        if helpers._settings_are_complete(
                new_settings_dict=kwargs,
                template_settings_dict=FILLER_LIST_SETTINGS_TEMPLATE,
                ignore_keys=['_id', 'id']):
            response = self._put(endpoint="/filler", data=kwargs)
            if response:
                return self.get_filler_list(
                    filler_list_id=response.json()['id'])
        return None
示例#3
0
    def add_channel(self,
                    programs: List[Union[Program, Redirect, Video, Movie,
                                         Episode]] = [],
                    plex_server: PServer = None,
                    handle_errors: bool = True,
                    **kwargs) -> Union[Channel, None]:
        """
        Add a channel to dizqueTV

        :param programs: Program, Redirect or PlexAPI Video, Movie or Episode objects to add to the new channel
        :type programs: List[Union[Program, Redirect, plexapi.video.Video, plexapi.video.Movie, plexapi.video.Episode]], optional
        :param plex_server: plexapi.server.PlexServer (optional, required if adding PlexAPI Video, Movie or Episode)
        :type plex_server: plexapi.server.PlexServer, optional
        :param kwargs: keyword arguments of setting names and values
        :param handle_errors: Suppress error if they arise (ex. alter invalid channel number, add Flex Time if no program is included)
        :type handle_errors: bool, optional
        :return: new Channel object or None
        :rtype: Channel
        """
        kwargs['programs'] = []
        for item in programs:
            if type(item) in [Program, Redirect]:
                kwargs['programs'].append(item._data)
            else:
                if not plex_server:
                    raise ItemCreationError(
                        "You must include a plex_server if you are adding PlexAPI Video, "
                        "Movie or Episodes as programs")
                kwargs['programs'].append(
                    convert_plex_item_to_program(
                        plex_item=item, plex_server=plex_server)._data)
        if kwargs.get('iconPosition'):
            kwargs['iconPosition'] = helpers.convert_icon_position(
                position_text=kwargs['iconPosition'])
        kwargs = self._fill_in_default_channel_settings(
            settings_dict=kwargs, handle_errors=handle_errors)
        if helpers._settings_are_complete(new_settings_dict=kwargs,
                                          template_settings_dict=CHANNEL_SETTINGS_TEMPLATE,
                                          ignore_keys=['_id', 'id']) \
                and self._put(endpoint="/channel", data=kwargs):
            return self.get_channel(channel_number=kwargs['number'])
        return None
示例#4
0
    def add_filler(self,
                   plex_item: Union[Video, Movie, Episode, Track] = None,
                   plex_server: PServer = None,
                   filler: FillerItem = None,
                   **kwargs) -> bool:
        """
        Add a filler item to this filler list

        :param plex_item: plexapi.video.Video, plexapi.video.Moviem plexapi.video.Episode or plexapi.audio.Track object (optional)
        :type plex_item: Union[plexapi.video.Video, plexapi.video.Movie, plexapi.video.Episode, plexapi.audio.Track], optional
        :param plex_server: plexapi.server.PlexServer object (optional)
        :type plex_server: plexapi.server.PlexServer, optional
        :param filler: FillerItem item (optional)
        :type filler: FillerItem, optional
        :param kwargs: keyword arguments of FillerItem settings names and values
        :return: True if successful, False if unsuccessful (FillerList reloads in place)
        :rtype: bool
        """
        if not plex_item and not filler and not kwargs:
            raise MissingParametersError(
                "Please include either a program, a plex_item/plex_server combo, or kwargs"
            )
        if plex_item and plex_server:
            temp_filler = self._dizque_instance.convert_plex_item_to_filler(
                plex_item=plex_item, plex_server=plex_server)
            kwargs = temp_filler._data
        if filler:
            if type(filler) == CustomShow:
                # pass CustomShow handling to add_programs, since multiple programs need to be added
                return self.add_fillers(fillers=[filler])
            kwargs = filler._data
        if helpers._settings_are_complete(
                new_settings_dict=kwargs,
                template_settings_dict=FILLER_ITEM_TEMPLATE,
                ignore_keys=['_id', 'id']):
            filler_list_data = self._data
            filler_list_data['content'].append(kwargs)
            if filler_list_data.get('duration'):
                filler_list_data['duration'] += kwargs['duration']
            return self.update(**filler_list_data)
        return False