MoviePilot is a very handy NAS media platform automation tool, formerly known as NasTool. MP supports many additional features through plugins, including automatic subscription for DouBan’s watchlist. However, I recently abandoned DouBan, so I developed a NeoDB plugin based on the original DouBan plugin, which allows for adding subscriptions and executing downloads automatically when marking something as “want to watch” on NeoDB.
Developing Plugins for MoviePilot
A MP plugin is essentially a Python script that can automate tasks through calling MP’s API. The plugin repository is here. Developing a plugin is very simple; you only need to inherit the _PluginBase class and then implement a few main methods. In fact, most methods are consistent with those of the DouBan sync plugin, and you basically only need to modify the sync method.
The idea behind the plugin implementation is to first obtain the NeoDB user Token from the plugin configuration page. There can be multiple accounts’ Tokens. Then, it retrieves the user’s watchlist records through NeoDB’s API and adds subscriptions through MP’s API.
defsync(self):"""
Sync wish-to-watch data from users' RSS
"""ifnotself._tokens:return# Iterate through all usersfortokeninself._tokens.split(","):ifnottoken:continue# Header includes Tokenheaders={"Authorization":f"Bearer {token}"}# Get usernameusername=self.__get_username(token)# Sync data for each NeoDB userlogger.info(f"Starting to sync wish-to-watch data for NeoDB user {username} ...")results=[]try:movie_response=requests.get(self._movie_url,headers=headers)movie_response.raise_for_status()tv_response=requests.get(self._tv_url,headers=headers)tv_response.raise_for_status()try:results=movie_response.json().get("data",[])+tv_response.json().get("data",[])exceptValueError:logger.error("Failed to parse user data")continueexceptExceptionase:logger.error(f"Failed to retrieve data: {str(e)}")continueifnotresults:logger.info(f"No wish-to-watch data for user {username}")continue# Iterate through all wish-to-watch entries for that userforresultinresults:try:# Take the url as the unique identifier. For example: /movie/2fEdnxYWozPayayizQmk5Mitem_id=result['item']['url']title=result['item']['title']category=result['item']['category']api_url=result['item']['api_url']# Check if it's within the date rangeifnotself.__is_in_date_range(result.get("created_time"),title):continue# Check if it's already processedifnotitem_idoritem_idin[h.get("neodb_id")forhinhistory]:logger.info(f'Title: {title}, NeoDB ID: {item_id} has been processed')continue# Get detailed information of the item (item_info)try:item_info=requests.get(f"https://neodb.social{api_url}").json()exceptExceptionase:logger.error(f"Failed to get item details: {str(e)}")continue# Then, identify media information, add subscriptions, download, and store plugin history records through MP API