[add] deluge - Rename top-level torrent folder#1790
[add] deluge - Rename top-level torrent folder#1790liiight merged 11 commits intoFlexget:developfrom andocromn:develop
Conversation
Adds the option container_directory to the Deluge plugin container_directory is a jinja2 template used by client.core.rename_folder to rename the top level folder - which is effectively the torrent name in deluge added 'name' to status_keys array to support this
flexget/plugins/clients/deluge.py
Outdated
| opts.get('main_file_ratio') * 100)) | ||
|
|
||
| if config.get('container_directory'): | ||
| log.info('Renaming Folder %s to %s' % (status['name'], pathscrub(entry.render(config.get('container_directory'))))) |
There was a problem hiding this comment.
Let the logger do its own string interpolation, pass it the args directly
There was a problem hiding this comment.
removed the pathscrub. better?
There was a problem hiding this comment.
Why not just render it once into a variable and then pass that variable to both the logger and the Deluge function? Saves a bit of processing.
flexget/plugins/clients/deluge.py
Outdated
| config.setdefault('magnetization_timeout', 0) | ||
| config.setdefault('keep_subs', True) # does nothing without 'content_filename' or 'main_file_only' enabled | ||
| config.setdefault('hide_sparse_files', False) # does nothing without 'main_file_only' enabled | ||
| config.setdefault('container_directory', '') |
There was a problem hiding this comment.
Setting an empty default seems redundant to me
There was a problem hiding this comment.
agreed, line removed
|
I haven't worked with Deluge's rename_folder before, but I wonder if it's smart enough to know if the something passed to it is not actually a folder, given that you can rename a complete folder structure by calling rename_file. If not, and the user sets container_directory with a single-file torrent that has no directory structure, it's going to end up renaming the file itself, since that's the torrent's name. I don't think I'd rely on torrent name in either case. I'd split the (big?) file by os.sep and then call rename_folder on whichever portions you want, in your case just the top one I guess. (I'd suggest revising the PR's name to "[add] deluge - Rename top-level torrent folder" so the changelog can pick it up easily. :)) |
added code to check that there is more than 1 file and abort if the torrent is a single file
flexget/plugins/clients/deluge.py
Outdated
|
|
||
| if config.get('container_directory'): | ||
| if len(status['files']) > 1: | ||
| log.info('Renaming Folder %s to %s', status['name'], entry.render(config.get('container_directory'))) |
There was a problem hiding this comment.
I think info is a bit much for this. Maybe verbose?
flexget/plugins/clients/deluge.py
Outdated
| log.info('Renaming Folder %s to %s', status['name'], entry.render(config.get('container_directory'))) | ||
| main_file_dlist.append(client.core.rename_folder(torrent_id, status['name'], pathscrub(entry.render(config.get('container_directory'))))) | ||
| else: | ||
| log.info('container_directory specified however the number of files is not greater than 1 - skipping rename') |
There was a problem hiding this comment.
same here, info is too much, maybe even debug for this one
changed verification from file count greater than 1 to check for a folder structure changed to folder_rename to use name extracted from folder structure instead of torrent name removed 'name' from status_keys - thanks tubedogg for the suggestions and assistance
| log.info('Renaming Folder %s to %s', status['name'], entry.render(config.get('container_directory'))) | ||
| main_file_dlist.append(client.core.rename_folder(torrent_id, status['name'], pathscrub(entry.render(config.get('container_directory'))))) | ||
| if opts.get('content_filename') or opts.get('main_file_only'): | ||
| folder_structure = big_file_name.split(os.sep) |
There was a problem hiding this comment.
This will throw the error local variable 'big_file_name' referenced before assignment if content_filename or main_file_only are set but there isn't one file above the "big" (main) file threshold, or if content_filename is not set (line 626). I'd add big_file_name = '' above line 562 to ensure it's always assigned to something, and then just do if big_file_name: here.
changed logging to verbose / debug per liiight's suggestion
changed container_directory to variable retrieved from config or set entry - container_directory option did not work if configured by set
per tubedogg's recommendation
|
I've tested as many scenarios as i can think of. I tested to make sure it doesn't break anything if used in conjunction with content_filename and main_file_only. It's a bit kludgy because it ends up replacing the top level folder in content_filename with the container_directory, but it works. Probably would put a note in the wiki recommending against using both, I can't really think of a real world scenario where both would be used I also also tested magnet links, there was an issue because the magnet has no files. I added code to check that the array 'files' is populated and cancel the rename_folder if there are no files. container_directory can be used with magnet links if convert_magnet: yes is used |
|
You guys tested the shit out of this right? Is it ready to be merged? |
|
Yeah it should be good to go. |
|
Yes, I did a lot of testing. there are some notes in my last comment about kludgy behaviour when using both container_directory and content_filename, it doesn't cause a problem or any errors. I could change the way this is handled, but I don't think anyone would need to use both. Just let me know if you'd like any further updates |
Motivation for changes:
Currently there is no way of doing this. content_filename will rename the folder only if a main file can be identified. This does not work well with Season Packs which support has recently been added for.
Detailed changes:
Config usage if relevant (new plugin or updated schema):
To Do: