Skip to content

Commit

Permalink
improved json storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Rieck committed Dec 11, 2015
1 parent 37835b0 commit ce0288c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions perplex.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Copyright (c) 2015 Konrad Rieck ([email protected])

import argparse
import sqlite3
import gzip
import json
import os
import shutil
import json
import gzip
import sqlite3
import sys

import progressbar as pb

# Default path to metadata database
Expand Down Expand Up @@ -59,7 +61,11 @@ def build_map(movies, mapping=[]):


def copy_rename(mapping, dest):
pbar = pb.ProgressBar()
""" Copy and rename files to destination """

widgets = [pb.Percentage(), ' ', pb.Bar(), ' ', pb.ETA()]
pbar = pb.ProgressBar(widgets=widgets)

for old_name, new_name in pbar(mapping):
dp = os.path.join(dest, os.path.dirname(new_name))
fp = os.path.join(dp, os.path.basename(new_name))
Expand All @@ -83,23 +89,23 @@ def copy_rename(mapping, dest):
parser.add_argument('--dest', metavar='<dir>', type=str,
help='copy and rename files to directory')
parser.add_argument('--save', metavar='<file>', type=str,
help='save mapping of movie titles')
help='save database of movie titles and files')
parser.add_argument('--load', metavar='<file>', type=str,
help='load mapping of movie titles')
help='load database of movie titles and files')

args = parser.parse_args()

if args.plex:
movies = build_db(args.plex)
mapping = build_map(movies)
elif args.load:
mapping = json.load(gzip.open(args.load))
movies, mapping = json.load(gzip.open(args.load))
else:
print "Error: Provide a Plex database or database of movie titles."
print "Error: Provide a Plex database or stored database."
sys.exit(-1)

if args.save:
json.dump(mapping, gzip.open(args.save, 'w'))
json.dump((movies, mapping), gzip.open(args.save, 'w'))

if args.dest:
copy_rename(mapping, args.dest)

0 comments on commit ce0288c

Please sign in to comment.