From 0cef6ebbb5fd6924f80022c3cb0f0eb77dc8244f Mon Sep 17 00:00:00 2001 From: Raymond Wagner Date: Fri, 29 Apr 2011 00:55:49 -0400 Subject: [PATCH] Add two more scripts. One to hash any content with a hash of 'NULL', and the other to remove any files with duplicate hashes. (cherry picked from commit 71a489768c83b80b328fb3d0665bcbf3591fbccc) --- python/hash_videos.py | 24 ++++++++++++ python/remove_duplicate_videos.py | 64 +++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100755 python/hash_videos.py create mode 100755 python/remove_duplicate_videos.py diff --git a/python/hash_videos.py b/python/hash_videos.py new file mode 100755 index 0000000..3322f7a --- /dev/null +++ b/python/hash_videos.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +#--------------------------- +# Name: hash_videos.py +# Python Script +# Author: Raymond Wagner +# Purpose +# This script will regenerate the hash values associated with +# videos in the MythVideo database. +#--------------------------- + +from MythTV import Video + +def print_aligned(left, right): + indent = 100 - len(left) + print left, indent*' ', right + +for vid in Video.getAllEntries(): + if vid.hash != 'NULL': + print_aligned(vid.filename, 'skipped') + continue + vid.hash = vid.getHash() + vid.update() + print_aligned(vid.filename, vid.hash) diff --git a/python/remove_duplicate_videos.py b/python/remove_duplicate_videos.py new file mode 100755 index 0000000..67b51e4 --- /dev/null +++ b/python/remove_duplicate_videos.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +#--------------------------- +# Name: remove_duplicate_videos.py +# Python Script +# Author: Raymond Wagner +# Purpose +# For reasons unknown, some people continue to get duplicate file +# entries in their MythVideo database. This script will detail those +# duplicate files based off hash number, and optionally delete them. +#--------------------------- +__title__ = "Remove Duplicate Videos" +__author__ = "Raymond Wagner" +__version__= "v0.5.0" + +from optparse import OptionParser +from MythTV import Video + +def format_name(vid): + # returns a string in the format 'TITLE[ - SEASONxEPISODE][ - SUBTITLE]' + s = vid.title + if vid.season: + s += ' - %dx%02d' % (vid.season, vid.episode) + if vid.subtitle: + s += ' - '+vid.subtitle + return s + +def FindDuplicates(dodelete): + dupvids = [] + vids = sorted(Video.getAllEntries(), key=lambda v: v.hash) + + for i in range(len(vids)-1): + if vids[i].hash == 'NULL': + continue + if vids[i].hash == vids[i+1].hash: + dupvids.append(vids[i+1]) + + if dodelete: + for vid in dupvids: + vid.delete() + + return dupvids + +def main(): + parser = OptionParser(usage="usage: %prog [options] [jobid]") + + parser.add_option("-s", "--dry-run", action="store_true", default=False, + dest="dryrun", help="Print out duplicates but do not delete.") + + opts, args = parser.parse_args() + + dups = FindDuplicates(not opts.dryrun) + + if len(dups): + print len(dups), 'Duplicates Found!' + print '----------------------' + for vid in dups: + print ' '+format_name(vid) + else: + print 'No Duplicates Found!' + +if __name__ == "__main__": + main() +