From 7187b074002c2b7e7061f15d1aab3b4eafe16fdb Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Sun, 23 Nov 2008 20:23:05 +0000 Subject: [PATCH] Added a --rename option that renames all converted programmes to the current naming scheme. --- src/recordtv | 7 +++++++ src/rtv_convert.py | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/recordtv b/src/recordtv index 09e1e8b..c7b6133 100755 --- a/src/recordtv +++ b/src/recordtv @@ -23,6 +23,10 @@ def main(): dest="convert", default=False, help="convert recorded programmes to a different format") + parser.add_option("-r", "--rename", action="store_true", + dest="rename", default=False, + help="renamed converted programmes to the current naming scheme") + parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False, help="ask the user if input is needed") @@ -56,6 +60,9 @@ def main(): if options.convert: rtv_convert.convert( config ) + if options.rename: + rtv_convert.rename( config ) + if options.generate_html: rtv_tvguide.generate( config ) diff --git a/src/rtv_convert.py b/src/rtv_convert.py index 3446da6..de64910 100644 --- a/src/rtv_convert.py +++ b/src/rtv_convert.py @@ -1,6 +1,7 @@ #!/usr/bin/python import os +import os.path import re import shutil import rtv_utils, rtv_programmeinfo @@ -72,8 +73,42 @@ def convert( config ): print "Conversion of '%s' returned an error." % fn continue - shutil.move( rtvinfo, - os.path.join( config.converted_progs_dir, rtvinfo_new ) ) + if os.path.isfile( rtvinfo ): + shutil.move( rtvinfo, + os.path.join( config.converted_progs_dir, rtvinfo_new ) ) +def rename( config ): + for ( dirpath, dirnames, filenames ) in os.walk( config.converted_progs_dir ): + for fn in filenames: + if fn[-4:] != ".flv": + continue + + fn_stem = os.path.join( dirpath, fn[ : fn.rfind( "." ) ] ) + + rtvinfo_orig = os.path.join( config.converted_progs_dir, + fn_stem + ".rtvinfo" ) + + flv_orig = os.path.join( config.converted_progs_dir, + fn_stem + ".flv" ) + + (flv_dir, flv_stem) = _get_flv_file_path( rtvinfo_orig, fn_stem ) + + rtv_utils.ensure_dir_exists( + os.path.join( config.converted_progs_dir, flv_dir ) ) + + flv_after = os.path.join( config.converted_progs_dir, + flv_stem + ".flv" ) + + rtvinfo_after = os.path.join( config.converted_progs_dir, + flv_stem + ".rtvinfo" ) + + if flv_orig != flv_after: + print "mv %s -> %s" % ( flv_orig, flv_after ) + shutil.move( flv_orig, flv_after ) + + if rtvinfo_orig != rtvinfo_after: + print "mv %s -> %s" % ( rtvinfo_orig, rtvinfo_after ) + shutil.move( rtvinfo_orig, rtvinfo_after ) + -- 2.11.4.GIT