Created
August 31, 2016 21:04
-
-
Save jceloria/cf31f181f2dcf68072bacbf453b558fa to your computer and use it in GitHub Desktop.
Remove completed torrents in Transmission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| ################################################################################ | |
| """ | |
| Remove completed torrents in Transmission. | |
| Copyright © 2016 by John Celoria <[REDACTED]>. | |
| This program is free software; you can redistribute it and/or modify | |
| it under the terms of the GNU General Public License as published by | |
| the Free Software Foundation; either version 2, or (at your option) | |
| any later version. | |
| This program is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| GNU General Public License for more details. | |
| You should have received a copy of the GNU General Public License | |
| along with this program; if not, write to the Free Software Foundation, | |
| Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| """ | |
| ################################################################################ | |
| ## Set some defaults | |
| __author__ = 'John Celoria' | |
| __version__ = '0.2' | |
| ################################################################################ | |
| ## Library imports | |
| import argparse, logging, os, sys | |
| # pip install transmission-fluid | |
| from transmission import Transmission | |
| ################################################################################ | |
| logging.basicConfig(level=logging.WARNING) | |
| logger = logging.getLogger(__name__) | |
| def isFinished(torrent): | |
| if torrent['isFinished'] is True: | |
| logger.info(torrent['name']+" is completed.") | |
| return torrent | |
| def main(arguments): | |
| parser = argparse.ArgumentParser(description=__doc__, | |
| formatter_class=argparse.RawDescriptionHelpFormatter) | |
| parser.add_argument('-H', '--host', default="localhost", | |
| help = "Transmission host") | |
| parser.add_argument('-P', '--port', default="9091", | |
| help = "Transmission port") | |
| args = parser.parse_args(arguments) | |
| logger.info("#########################################################") | |
| logger.info("## ..::[{}]::.. ##".format(os.path.basename(__file__))) | |
| logger.info("#########################################################") | |
| client = Transmission(host=args.host, port=int(args.port)) | |
| torrents = client('torrent-get', fields=['id', 'isFinished', 'name'])['torrents'] | |
| ids = [torrent['id'] for torrent in torrents if isFinished(torrent)] | |
| client('torrent-remove', ids=ids) | |
| if __name__ == '__main__': | |
| sys.exit(main(sys.argv[1:])) | |
| ################################################################################ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment