Do Not Create Folders

Information and Tutorials on features in Mylar and how to use it
Post Reply
comicfan234
Posts: 5
Joined: Tue Feb 23, 2016 4:46 pm

Do Not Create Folders

Post by comicfan234 »

Is it possible to set up Mylar so that it will rename the files on post-processing, but NOT create any folders for each series? I would like all comics to be moved to one folder and no folders created. I delete the comics after reading them, so a folder structure is unnecessary. Thanks.
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: Do Not Create Folders

Post by evilhero »

comicfan234 wrote:Is it possible to set up Mylar so that it will rename the files on post-processing, but NOT create any folders for each series? I would like all comics to be moved to one folder and no folders created. I delete the comics after reading them, so a folder structure is unnecessary. Thanks.
It's not possible at this time due to the way Mylar inherently relies on folder structure in order to track/monitor existing series on your watchlist. Doing away with a folder structure in order to just dump items into a single folder would cause several issues with the management portion of mylar (namely file-tracking, status changes, etc). While it's a nice feature to have, and I'm not saying it's not possible - it's just not in the immediate future unless something changes where I have to rewrite that particular portion of code ahead of time.

If/when it does get added as an option, I'll try and update this thread so you'll be aware of the change and can use the feature.
comicfan234
Posts: 5
Joined: Tue Feb 23, 2016 4:46 pm

Re: Do Not Create Folders

Post by comicfan234 »

Thanks for the reply. I get what you're saying and that makes sense.

I think I've figured out a solution. I might try to use a post-processing script to copy the files to a specific folder. Do you know of a script that would copy the files after renaming?
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: Do Not Create Folders

Post by evilhero »

Something pretty simple (with no error-checking to see if the directory exists prior to copy, etc..) could be as follows.

You can save it as a .py file and put the complete path + filename in the extra_scripts portion of Mylar's post-processing to have it run after a post-processing run:

Code: Select all

#!/usr/bin/env python
import sys
from shutil import copyfile

#---user variables (start)---
file_mode = 'copy'  # select 'copy' or 'move'
destination_folder = '/some/location/here'
#---user variables (end)---

src = os.path.join(sys.argv[3], sys.argv[2])
dst = os.path.join(destination_folder, sys.argv[2])

if file_mode == 'copy':
    file_operation = shutil.copy
else:
    file_operation = shutil.move

try:
    file_operation(src, dst)
except IOError:
    print 'unable to copy file to dst : ' + dst
comicfan234
Posts: 5
Joined: Tue Feb 23, 2016 4:46 pm

Re: Do Not Create Folders

Post by comicfan234 »

That script does seem pretty simple. However, it's not copying the file. I created the .py file, added my destination folder to the code, made sure the .py was executable in Terminal, and added the script location to the post processing section of Mylar settings. From what I can tell in the log is that Mylar isn't attempting to use the extra script after post processing, but just doing the usual post processing of renaming the file and moving it to where the comics are stored. Any ideas?
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: Do Not Create Folders

Post by evilhero »

Ah crap.. I just noticed I forgot an import statement.

Right after the import sys, on a new line add:

Code: Select all

import os
And change the 'from shutil import copyfile' to:

Code: Select all

import shutil
Save it, and try. If you added the extra script and didn't restart mylar after saving the configuration that would cause some problems as well.
comicfan234
Posts: 5
Joined: Tue Feb 23, 2016 4:46 pm

Re: Do Not Create Folders

Post by comicfan234 »

It still doesn't seem to work. I made the changes and restarted Mylar. Here is what the code looks like now:

Code: Select all

#!/usr/bin/env python
import sys
import os
import shutil

#---user variables (start)---
file_mode = 'copy'  # select 'copy' or 'move'
destination_folder = '/Users/mediacenter/Dropbox/New_Comics'
#---user variables (end)---

src = os.path.join(sys.argv[3], sys.argv[2])
dst = os.path.join(destination_folder, sys.argv[2])

if file_mode = 'copy':
    file_operation = shutil.copy
else:
    file_operation = shutil.move

try:
    file_operation(src, dst)
except IOError:
    print 'unable to copy file to dst : ' + dst
Thanks for all your help. It's appreciated.
User avatar
evilhero
Site Admin
Posts: 2883
Joined: Sat Apr 20, 2013 3:43 pm
Contact:

Re: Do Not Create Folders

Post by evilhero »

Sorry, I got the argv variables mixed up, that's my fault:

Code: Select all

nzbname = sys.argv[1]
temp_nzb_folder = sys.argv[2]
new_filename = sys.argv[3]
series_path + filename = sys.argv[4]
issue_metadata = sys.argv[5] [ issue_metadata = {'name', 'comicyear', 'comicid', 'issueid', 'issueyear','issue','publisher'} ]
So the final code should be (with the right arg variables and fixing the lack of a double equals sign):

Code: Select all

#!/usr/bin/env python
import sys
import os
import shutil

#---user variables (start)---
file_mode = 'copy'  # select 'copy' or 'move'
destination_folder = '/Users/mediacenter/Dropbox/New_Comics'
#---user variables (end)---

src = os.path.join(sys.argv[4])
dst = os.path.join(destination_folder, sys.argv[3])

if file_mode == 'copy':
    file_operation = shutil.copy
else:
    file_operation = shutil.move

try:
    file_operation(src, dst)
except IOError:
    print 'unable to copy file to dst : ' + dst
else:
    print 'Successfully copied to dst : ' + dst
I just tested this one mine and it ran perfectly fine - hopefully it will for you too now ;)
comicfan234
Posts: 5
Joined: Tue Feb 23, 2016 4:46 pm

Re: Do Not Create Folders

Post by comicfan234 »

I just wanted to write back to say that the latest code changes worked. Everything now is working exactly how I want it to. Thanks so much for all your help in troubleshooting the issues and in developing a great piece of software.
Post Reply