
Python3 series download extension support
As an introduction, it’s worth saying that I use macOS and therefore some parts:
- Autostart (launchd)
- Format of configuration files (plist)
- The program used for notifications (terminal-notifier)
will be specific to this OS. However, if you are interested in the project, I think changing a couple of paths and slightly correcting several functions to make this code work with your notification system, yaml and, let's say, krone, is not difficult.
So to the point.
Checking trackers for updates of your favorite television shows, recalling when a new episode came out, whether you watched the previous one, is boring. In addition, as you know, all you need to do more than two times is to automate. The project was started in haste and is likely to be improved.
What does it contain?
- Parser class in parser.py
- Loader class in core.py
- Plugins inheriting the loader class in the plugins directory
- Config plugin configuration files in configs directory
- Icons directory for notification icons
- Main.py file pulling plugins
- Install.py file
Parsing class
Since almost all series sites have their own RSS feeds, it was decided to simplify the process of writing plugins to create a parsing function that allows you to automatically parse rss by link and display a list of pairs (title, link) with the ability to specify the encoding.
A little later, the need came for simple html parsing, and then it was thought that some sites could also give links via api in json format.
So the function turned into a class that stores the session (requests Session) for sites requiring authorization and returns a response object with the html () , rss () , json () and auto () methods . The latter tries to guess the content (xml, html or json) and the encoding by the 'Content-Type' header. The default is 'utf-8' and html.
- Html () method returns beautifulsoup object of the whole page
- The rss () method returns an array of tuples (header, link)
- The json () method returns the object obtained by the json.loads method of the page text
Bootloader class
Provides plugins with parse () and download () methods .
- The parse () method provides the ability to pass the link and url parameters. It also checks for 'If-Modified-Since' if the site provides information about the last change. Returns the response object from the parse.py file .
- The download () method accepts a dictionary with information about the name of the series, episode, link and other trifles, as well as http-headers and cookies. And then independently produces all the magic. Loads the file into the folder “Serial_Name [plugin_class_name]” previously created by him, where it is assumed that the class name of the plugin is the name of the recording studio / site from which the download takes place. If the file is a torrent, downloads the episode from the torrent and deletes the torrent file. Download is performed using aria2c , which must be installed on the system and located in one of the directories specified in $ PATH. Then the save () method is called , which saves the links to the configuration file to prevent reloading.
- The __notify () method , which is called when the download starts and ends, if the corresponding application is found along the path / usr / local / bin / terminal-notifier . You can see how it looks a little lower.
Plugins
Classes that inherit the bootloader class that implement the start () method in which to parse and call the download () method with the expected parameters.
Plugin Configuration Files
* .plist
Contain:
- Quality of interest
- Subscription List
- Exclusion list ("full season", for example)
- last_modified for sites giving information about the last change
- A list of links will be written here to prevent reloading.
Directory icons
A folder in which you can put icon files that will be used when notifying of the loading / completion of downloading episodes from relevant sources. The names of the icons should match the names of the plugins, but with the extension jpg / ico / png.
main.py
The start () method of all plugins in the plugins directory is pulled one by one .
install.py
- Install dependencies
- Move project files to ~ / .NB-series-downloader
- Will create an autorun file
- Delete the directory of the cloned repository
Autoload
The install.py file will do this for you, but if you decide to do everything manually, then ...
I was not able to tell launchd about $ HOME, so you have to replace the text below $ HOME yourself with the path to your user’s home directory / Users / Username and possibly change the path to the script directory if you put them in another place.
Disabled EnvironmentVariables PATH /usr/local/bin KeepAlive SuccessfulExit Label series_downloader ProgramArguments python3 $HOME/.NB-series-downloader/main.py RunAtLoad StartInterval 900 WorkingDirectory $HOME/.NB-series-downloader
The file itself with these contents should be called series_downloader.plist and put in ~ / Library / LaunchAgents / .
You can immediately download the tasks described in this file using the command
launchctl load ~/Library/LaunchAgents/series_downloader.plist
Otherwise, tasks are activated the next time the computer boots.
These actions will cause main.py, located in the $ HOME / .NB-series-downloader / directory , to run every 900 seconds (15 minutes).
Total
Honestly, the first thing I put there, so I could screw up. Tell me if something is wrong.
Start Download Notification:
After downloading, the inscription “Download started” will change to “Download completed”.
That's all that we will see as a result of the plugin, and the episodes will be neatly folded into a daddy and wait in the wings.
Series in my case are added to Series in the same directory (you can specify a different place in self.series_dir of the downloader class in core.py ).
And for viewing the downloaded series, I wrote a workflow for Alfred 3 :
After viewing each series, it offers:
- Delete it (I do not store the archive, everything viewed is sent to the basket)
- It asks for the rating of the episode from 1 to 5, and also notes the just viewed one in my account on myshows.me and sets the rating of the episode using their api
- Displays a notification that everything went well
- By clicking on the notification, you can open the page of the episode you just watched on myshows
But that's all - it's a completely different story ...