Skip to content

Instantly share code, notes, and snippets.

@craigpalermo
Last active January 17, 2017 04:24
Show Gist options
  • Save craigpalermo/7d78ed5596f7a90034f95362b8b6015b to your computer and use it in GitHub Desktop.
Save craigpalermo/7d78ed5596f7a90034f95362b8b6015b to your computer and use it in GitHub Desktop.
Import a DOGnzb watchlist into your CouchPotato wanted list
"""
Description: Import DOGnzb watchlist into CouchPotato
Author: Craig Palermo
Date: 1/14/2017
"""
import argparse
import json
import logging
import sys
import requests
parser = argparse.ArgumentParser()
parser.add_argument('--file',
dest='filename',
required=True,
help='Filename of DOGnzb watchlist export (MUST BE IN SAME DIRECTORY AS THIS SCRIPT)')
parser.add_argument('--cb_apikey',
dest='cb_api_key',
required=True,
help='API key of your CouchPotato server (see CP settings)')
parser.add_argument('--cb_port',
dest='cb_port',
default=5050,
help='CouchPotato port, default is 5050')
parser.add_argument('--cb_host',
dest='cb_host',
default='localhost',
help='CouchPotato hostname, default is localhost')
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
class CPMovie:
def __init__(self, name, identifier):
self.name = name
self.identifier = identifier
class CPClient:
def __init__(self, args):
self.args = args
self.api_url = 'http://{}:{}/api/{}/'.format(args.cb_host, args.cb_port, args.cb_api_key)
def movie_add(self, movie: CPMovie):
"""
Add a movie to CouchPotato's wanted list. Requires object containing movie name and IMDb identifier
from the DOGnzb export.
:param movie:
:return:
"""
logging.info('Adding "{}" to CouchPotato wanted'.format(movie.name))
r = requests.post(''.join((self.api_url, 'movie.add')), data={
'title': movie.name,
'identifier': movie.identifier
})
if r.status_code == 200:
logging.info('Successfully added "{}" to CouchPotato wanted'.format(movie.name))
return True
else:
logging.warning('Unable to add "{}" to CouchPotato wanted'.format(movie.name))
return False
def main():
args = parser.parse_args()
filename = args.filename
logging.info('=== STARTING NEW RUN ===')
# open file for reading
logging.debug('Reading dognzbd watchlist from file')
file = open(filename, 'r')
# decode json string
logging.debug('Loading dognzbd watchlist from JSON and extracting movie data')
watchlist = json.load(file)
movies = [CPMovie(x['name'], x['ids']['IMDb']) for x in watchlist['items']]
# add items in watchlist to couchpotato watchlist
logging.debug('Adding movies to CouchPotato wanted list')
cp = CPClient(args)
result = [cp.movie_add(x) for x in movies]
# count results
success = len(filter(lambda x: x, result))
error = len(result) - success
logging.debug(
'Program successfully added {} and failed to add {} titles to your CouchPotato watch list'.format(
success,
error
)
)
if __name__ == '__main__':
main()
requests==2.12.4
{
"attributes": {
"version": "1.0",
"items": "51"
},
"items": [
{
"name": "The Founder",
"ids": {
"IMDb": "tt4276820"
},
"quality": "144"
},
{
"name": "Jack Reacher: Never Go Back",
"ids": {
"IMDb": "tt3393786"
},
"quality": "144"
},
{
"name": "Doctor Strange",
"ids": {
"IMDb": "tt1211837"
},
"quality": "144"
},
{
"name": "Logan",
"ids": {
"IMDb": "tt3315342"
},
"quality": "144"
},
{
"name": "John Wick: Chapter Two",
"ids": {
"IMDb": "tt4425200"
},
"quality": "144"
},
{
"name": "Hacksaw Ridge",
"ids": {
"IMDb": "tt2119532"
},
"quality": "144"
},
{
"name": "Nocturnal Animals",
"ids": {
"IMDb": "tt4550098"
},
"quality": "144"
},
{
"name": "Bad Santa 2",
"ids": {
"IMDb": "tt1798603"
},
"quality": "144"
},
{
"name": "Allied",
"ids": {
"IMDb": "tt3640424"
},
"quality": "144"
},
{
"name": "Office Christmas Party",
"ids": {
"IMDb": "tt1711525"
},
"quality": "144"
},
{
"name": "Passengers",
"ids": {
"IMDb": "tt1355644"
},
"quality": "144"
},
{
"name": "Silence",
"ids": {
"IMDb": "tt0490215"
},
"quality": "144"
},
{
"name": "Patriots Day",
"ids": {
"IMDb": "tt4572514"
},
"quality": "144"
},
{
"name": "Why Him?",
"ids": {
"IMDb": "tt4501244"
},
"quality": "144"
},
{
"name": "The Promise",
"ids": {
"IMDb": "tt4552298"
},
"quality": "144"
},
{
"name": "The Mountain II",
"ids": {
"IMDb": "tt5813916"
},
"quality": "144"
},
{
"name": "Arrival",
"ids": {
"IMDb": "tt2543164"
},
"quality": "144"
},
{
"name": "The Ivory Game",
"ids": {
"IMDb": "tt5952266"
},
"quality": "144"
},
{
"name": "Paterson",
"ids": {
"IMDb": "tt5247022"
},
"quality": "144"
},
{
"name": "Street Level",
"ids": {
"IMDb": "tt4438594"
},
"quality": "144"
},
{
"name": "Wish For Christmas",
"ids": {
"IMDb": "tt4700190"
},
"quality": "144"
},
{
"name": "The Edge of Seventeen",
"ids": {
"IMDb": "tt1878870"
},
"quality": "144"
},
{
"name": "Manchester by the Sea",
"ids": {
"IMDb": "tt4034228"
},
"quality": "144"
},
{
"name": "Mars",
"ids": {
"IMDb": "tt4939064"
},
"quality": "144"
},
{
"name": "Peter and the Farm",
"ids": {
"IMDb": "tt5535814"
},
"quality": "144"
},
{
"name": "Moana",
"ids": {
"IMDb": "tt3521164"
},
"quality": "144"
},
{
"name": "Inner Workings",
"ids": {
"IMDb": "tt5807512"
},
"quality": "144"
},
{
"name": "Rillington Place",
"ids": {
"IMDb": "tt5568438"
},
"quality": "144"
},
{
"name": "Gilmore Girls: A Year in the Life",
"ids": {
"IMDb": "tt5435008"
},
"quality": "144"
},
{
"name": "La La Land",
"ids": {
"IMDb": "tt3783958"
},
"quality": "144"
},
{
"name": "The Legend of Ben Hall",
"ids": {
"IMDb": "tt3844876"
},
"quality": "144"
},
{
"name": "Jackie",
"ids": {
"IMDb": "tt1619029"
},
"quality": "144"
},
{
"name": "A Cinderella Christmas",
"ids": {
"IMDb": "tt6185074"
},
"quality": "144"
},
{
"name": "Dear Zindagi",
"ids": {
"IMDb": "tt5946128"
},
"quality": "144"
},
{
"name": "Marathon: The Patriots Day Bombing",
"ids": {
"IMDb": "tt6047906"
},
"quality": "144"
},
{
"name": "Uno: The Movie",
"ids": {
"IMDb": "tt6290024"
},
"quality": "144"
},
{
"name": "Spectral",
"ids": {
"IMDb": "tt2106651"
},
"quality": "144"
},
{
"name": "Heaven Sent",
"ids": {
"IMDb": "tt3920060"
},
"quality": "144"
},
{
"name": "The Trans List",
"ids": {
"IMDb": "tt5784340"
},
"quality": "144"
},
{
"name": "Leap!",
"ids": {
"IMDb": "tt2261287"
},
"quality": "144"
},
{
"name": "Sing",
"ids": {
"IMDb": "tt3470600"
},
"quality": "144"
},
{
"name": "Don't Hang Up",
"ids": {
"IMDb": "tt3610746"
},
"quality": "144"
},
{
"name": "The OA",
"ids": {
"IMDb": "tt4635282"
},
"quality": "144"
},
{
"name": "Hidden Figures",
"ids": {
"IMDb": "tt4846340"
},
"quality": "144"
},
{
"name": "Fences",
"ids": {
"IMDb": "tt2671706"
},
"quality": "144"
},
{
"name": "Dangal",
"ids": {
"IMDb": "tt5074352"
},
"quality": "144"
},
{
"name": "To Walk Invisible",
"ids": {
"IMDb": "tt5594080"
},
"quality": "144"
},
{
"name": "20th Century Women",
"ids": {
"IMDb": "tt4385888"
},
"quality": "144"
},
{
"name": "LBJ",
"ids": {
"IMDb": "tt4778988"
},
"quality": "144"
},
{
"name": "Shooting Clerks",
"ids": {
"IMDb": "tt3449200"
},
"quality": "144"
},
{
"name": "Endless Poetry",
"ids": {
"IMDb": "tt4451458"
},
"quality": "144"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment