manolomartinez / greg

A command-line podcast aggregator
GNU General Public License v3.0
296 stars 37 forks source link

downloadhandler vs spaces #84

Closed kousu closed 6 years ago

kousu commented 6 years ago

I set

downloadhandler = wget "{link}" -O "{directory}/{title}.mp3"

and if {title} has spaces in it, like most do, I get

$ greg download 1-193
Downloading 7.20- Where Do You Draw The Line? -- 7.20-_Where_Do_You_Draw_The_Line__Master.mp3
/home/kousu/Podcasts/Revolutions/7.20- Where Do You Draw The Line?.mp3: No such file or directory
Traceback (most recent call last):
  File "/usr/bin/greg", line 11, in <module>
    load_entry_point('Greg==0.4.7', 'console_scripts', 'greg')()
  File "/usr/lib/python3.6/site-packages/greg/parser.py", line 138, in main
    function(vars(args))
  File "/usr/lib/python3.6/site-packages/greg/commands.py", line 247, in download
    feed.download_entry(entry)
  File "/usr/lib/python3.6/site-packages/greg/classes.py", line 329, in download_entry
    aux.download_handler(self, placeholders)
  File "/usr/lib/python3.6/site-packages/greg/aux_functions.py", line 231, in download_handler
    raise URLError
TypeError: __init__() missing 1 required positional argument: 'reason'

I know there's {filename_title} (and using it does work) but I like having nice pretty unmangled titles. I even double-quoted the variables! They should be okay to pass through to a shell command.

kousu commented 6 years ago

I think the bug is here:

        value_list = shlex.split(value)
        instruction_list = [substitute_placeholders(part, placeholders) for
part in value_list]

Doing the subsitutions after the parsing is backwards. You should substitute then let shlex get at it so that it can properly parse anything that got substituted in. (by the way, thanks for using shlex! and your really good docs! and nice clean unixey design! it gives me a lot of good feelings using your code).

        value_list = shlex.split(substitute_placeholders(value, placeholders))
kousu commented 6 years ago

Er, actually I tried that and it didn't affect instruction_list. Both ways turned out the same.

The real issue, I think, is that my filesystem in question is exFAT and so it rejects '?' in filenames.