📜 ⬆️ ⬇️

Python3 serials extension support

As an introduction I should say that I use macOS and therefore some parts:



will be specific to this OS. However, if you are interested in the project, I think, changing a couple of ways and slightly correcting several functions to get this code to work with your notification system, yaml and, say, crown, will not be difficult.


So, to the point.


It is annoying to check the trackers for updates of your favorite television shows, to remember when a new episode came out, whether you watched the previous one. In addition, as you know, everything that needs to be done more than twice is worth automating. The project was launched in haste and is likely to be improved.


What does it contain?


  1. Parser class in parser.py
  2. Loader class in core.py
  3. Plugins inheriting bootloader classes in plugins directory
  4. Config plugin configuration files in the configs directory
  5. The icons directory for notification icons
  6. The main.py file jerking plugins
  7. Install.py file

Parsing class


Since almost all TV series websites have their own RSS feeds, it was decided to simplify the process of writing plugins to blind the parsing function, which allows parsing rss automatically by reference and displaying a list of pairs (title, link) with the possibility of specifying an encoding.


A little later came the need for simple parsing of html, and then it was thought that some sites could give links via api in json format.


So the function turned into a class that stores the session (requests Session) for sites that require authorization and returns a response object with the methods html () , rss () , json () and auto () . The latter tries to guess the contents (xml, html or json) and the encoding by the 'Content-Type' header. The default is 'utf-8' and html.



Loader class


Provides plugins with parse () and download () methods.



Plugins


Classes that inherit the loader class, implement the start () method in which it is necessary to parse and call the download () method with the expected parameters.


Plugin configuration files


* .plist


Contain:



Directory icons


A folder in which you can put the icon files that will be used when notifying you about downloading / ending the loading of episodes from relevant sources. The names of the icons should match the names of the plug-ins, but with the extension jpg / ico / png.


main.py


Alternately, the start () method of all plugins in the plugins directory is pulled alternately.


install.py



Autoload


The install.py file will do it for you, but if you decide to do everything manually, then ...


Instruction

I was not able to tell launchd about $ HOME, therefore you will have to replace the text below $ HOME with the path to your users / Users / Username home directory and, possibly, change the path to the scripts directory if you put them in another place.


<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Disabled</key> <false/> <key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/local/bin</string> </dict> <key>KeepAlive</key> <dict> <key>SuccessfulExit</key> <false/> </dict> <key>Label</key> <string>series_downloader</string> <key>ProgramArguments</key> <array> <string>python3</string> <string>$HOME/.NB-series-downloader/main.py</string> </array> <key>RunAtLoad</key> <true/> <key>StartInterval</key> <integer>900</integer> <key>WorkingDirectory</key> <string>$HOME/.NB-series-downloader</string> </dict> </plist> 

The file itself with this content should be called series_downloader.plist and put in ~ / Library / LaunchAgents / .
You can download the tasks described in this file immediately with the command


 launchctl load ~/Library/LaunchAgents/series_downloader.plist 

Otherwise, the 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


Link to Github .


Honestly, the first thing I post there, so I could screw it up. Tell me, if something goes wrong.


Notification about the start of the download:


Notification about the start of the download
After downloading, the message "Download started" will change to "Download finished."
That's all that we will see as a result of the plug-in, 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 the self.series_dir class of the downloader in core.py ).


And to view the downloaded series I wrote the workflow for Alfred 3 :
TV series list
After viewing each episode, he suggests:



But this is all - is another story ...


')

Source: https://habr.com/ru/post/304770/


All Articles