Code Monkey home page Code Monkey logo

putiocallbackcatcher's Introduction

PutioCallbackCatcher

A callback catcher for the put.io service

The aim of this project is to provide a simple to use Python server which can be run on a server and is capable of receiving and processing "download complete" notifications from the Put.io service.

This tool specifically has the functionality to download the completed file/folder, and additional custom commands may be defined in the config file to enable archiving, moving, deletion, and notification of completed downloads.

Usage

The start.sh and stop.sh scripts may be used as a convenience to start and stop the putiocatcher.py application. Starting the server using this method causes is to be backgrounded, and for stdout and stderr to be redirected to appropriately named files.

The application has sensible defaults, as can be seen in the pcc.config file, as well as in the source code. However, at a minimum you will need to enter your Put.io OAuth token in the config file in order to enable downloads of completed files.

Example usage:

./start.sh ./stop.sh

Put.io OAuth Token

The easiest way I have found to get a put.io OAuth token to use with this application is to:

  1. Visit https://put.io
  2. Login to your account if necessary
  3. Navigate to Settings along the left hand menu bar.
  4. Scroll down, and click on "Manage OAuth Applications"
  5. Click the "CREATE A NEW OAUTH APP" button.
  6. Enter whatever you like (for the most part) and click Save
  7. Click on the Key icon to the right of the Application name you just created.
  8. This will open up a new page which will contain a field entitled "OAUTH TOKEN", copy the value of this field, it is the OAuth token that you need to put in the pcc.config file.

Config File

The config file contains mandatory as well as optional sections, the sections currently supported are: WebServer, Execute, and PutioCreds.

For example, the WebServer section allows you to set the hostname/IP on which the server will listen, the port that it will listen on, as well as the download directory (where new files will go), and the archive directory (where completed files will be moved/archived to).

[WebServer]
Host: 0.0.0.0
Port: 9001
ArchiveDir: ./Complete/
DownloadDir: ./Downloads/

The PutioCreds section is where you need to enter your OAuth token. Fill it in on the right hand side of the OauthToken key:

[PutioCreds]
OauthToken: <Your Putio OAuth token>

The Execute section allows you to specify what shell commands to run in order to perform certain actions. Sensible defaults have been provided for archiving and removing, however you will need to update the Notify command with your own token and userid, or replace it with another command entirely.

Note: While the application should work without any of these config options defined, it has not been thoroughly tested. This is a work in progress.

[Execute]
Notify: curl -s -F "token=<Your pushover token>" \
    -F "user=<Your user token>" \
    -F "title=%TITLE%" \
    -F "message=%MESSAGE%" https://api.pushover.net/1/messages.json > /dev/null 2>&1
ArchiveCommand: tar -cf "%ARCHIVE_DIR%%NAME%.tar" "%DOWNLOAD_DIR%%NAME%"
RemoveCommand: rm -rvf "%DOWNLOAD_DIR%%NAME%"

The command specified in Notify will be run with an appropriate title and message substituted at certain points in the server processing process. Such as when a new POST request arrives from put.io, when the download of a new request is completed, and when archiving and removal has completed. Some error conditions may also trigger a notification. You are encourage to extend this as you like.

If the archive command is specified, whenever a directory is downloaded it will be archived (using tar with no compression) and then moved to the archive directory. If the completed download is not a directory, and is a single file, it will simply be moved to the archive directory if specified.

The remove command will only be run after a download has been successfully completed, and archived (so only directories), and will remove the directory that was downloaded initially from the download directory. This aims to allow for all complete 'processed' downloads to be moved to their own directory for further processing, and leave the download directory for new incoming downloads.

The %ARCHIVE_DIR%, %DOWNLOAD_DIR%, and %NAME% sequences show in archive command and remove command and replaced in the Python code by the actual values of these. The name represents the actual name of the file downloaded from put.io.

Configuring Put.io to use your callback server

Once you have your server configured and up and running the last step is to specify the address of your server in the put.io settings.

In order to do this you will either need to run the server on a physcial or virtual server that has a public IP address, and ensure that your firewall is set to allow the incoming connection. Or you if you run this on your home Internet connection where you have a dynamic IP address and are behind a NAT router, you will need to port forward the relevant port in your router, and make use of a dynamic DNS service to ensure that the callback always reaches you.

Information regarding port forwarding, dynamic DNS, NAT, and firewalls can be found online and will not be repeated here.

Perform the following steps to configure your put.io account to notify your server of completed downloads:

  1. Visit https://put.io and login if necessary.
  2. Click on Settings on the left hand menu bar.
  3. Scroll down to the "CALLBACK URL" field.
  4. Enter the web address of the server on which you are running PutioCallbackCatcher. You may use either an IP address or a domain name, be sure to include the port, for e.g. http://127.0.0.1:9001/
  5. Click Save.

Once you have done this, you should test to ensure it works as expected.

  1. Start up your server and tail the stdout log file ./start.sh; tail -f stdout.log
  2. Add a new download to your Put.io account.
  3. Watch your server logs and you should see a new POST request come in once the download on put.io is complete.
  4. Depending how you've configured your server, the request will trigger download, archive, and push notification actions.

If you are having any trouble be sure to check the stderr.log file to troubleshooting.

putiocallbackcatcher's People

Contributors

snyk-bot avatar yestinj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

putiocallbackcatcher's Issues

Improve start and stop scripts

Improve the start and stop scripts to do things such as checking if the script really starts, really exits, and so on.

Notification flags

Add support for notification flags to allow fine grained control over when to send a notification.

Initial ideas include: On new download arrival, on download completion, on download archive, on original download file removal, on any error, on serious error.

Improve path handling on config file and code

Improve the path handling in the source code, ensure that relative and absolute paths work correctly.

Improve the definition of paths in the config file to allow for more flexibility.

Add filters for catching only certain downloads

Add the option to specify filters that will cause only certain files to be downloaded when a callback is received.

Initial ideas on criteria:

  1. File size (less than, greater than)
  2. Parent directory (is, is not)
  3. Whitelist of keywords in download name (i.e. only download ubuntu-64-bit.
  4. Blacklist for keywords in download name (i.e. don't download fedora)

Improve code quality and design

Improve the design and quality of the code in use.

Make use of PEP8 standards, add comments, docstrings, better naming and error handling. More modularity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.