You are not logged in.
I have this script for use with sabnzbd, what it does is rename all folders in the desired directory, replacing any spaces with dots (example: Movie 2011 HD -> Movie.2011.HD).
#!/usr/bin/env python2
workdir = '/media/stuff/movies' #### CHANGE this line to your movie directory
for path, dirnames, filenames in os.walk(workdir):
print "path:", path
for dirname in dirnames:
if dirname.find(' ') > -1 :
# Yes, a space in the directory name, so replace it:
newname = dirname.replace(' ','.')
fulldirname = path + '/' + dirname
fullnewname = path + '/' + newname
print "Rename" , fulldirname, " ", fullnewname
os.rename(fulldirname, fullnewname)
What I would like it to do is 1. rename only the movie I run the script on (instead of /media/stuff/movies as above, the entire movie folder), and then 2. move the movie into /media/stuff/movies. Or vice versa! (I'd just prefer not to have it run on the entire movie directory).
Appreciate any help!
Offline
I just use simple bash function find. This is what I use to move torrents
find ~/downloads/torrents -type d -exec mv {} ~/media/downloads \;
you can probably add a new name in it
and this is what I use to clean up the torrent and remove unnecessary files like .nfo etc.
find ~/downloads/torrents -type f \( -name "*.txt" -o -name "*.nfo" \) -exec rm -rf {} +;
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
Okay, so the moving part is clear, how in bash would I find and replace spaces in the name with dots? I can refer to $1, that's built-in to sabnzbd as the folder of the download. So I want to find all the spaces in $1 and replace with dots, then move $1 over.
Offline
Just my two cents:
I would not use walkdir but as usual a combination of find and python.
A simplified version of the script could look like this:
#!/usr/bin/python
# -*- coding: utf8 -*-
import os, shutil
# Define target dir
target_dir = "/media/stuff/movies/"
# Loop through all found files
for source_file in os.popen ("find ."):
# Remove \n
source_file = source_file[:-1]
extension = source_file[-3:]
# Only process video files
if (extension == 'mkv') or (extension == 'avi') or (extension == 'mp4'):
target_file = source_file.split('/')
target = target_file[len(target_file)-1]
target = target.replace(' ','.')
shutil.copy (source_file, targetdir + target)
Of course you might first want to print out instead of really copy files.
My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick
Offline
detox might be useful.
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
Sorry how do I do that? (print out instead of copy).
Offline
Sorry how do I do that? (print out instead of copy).
Sorry, I thought this is obvious !
Replace this line:
shutil.copy (source_file, targetdir + target)
with this line:
print source_file + ' ' + targetdir + target
BTW: cfr is right ! detox also looks promising for your purpose:
http://linux.die.net/man/1/detox
HTH,
D$
Last edited by Darksoul71 (2012-07-17 08:07:57)
My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick
Offline