Repository: ytdl-org/youtube-dl

Issue:
Home variable not expanded in config file.
### Make sure you are using the _latest_ version: run `youtube-dl --version` and ensure your version is _2016.05.01_. If it's not read [this FAQ entry](https://github.com/rg3/youtube-dl/blob/master/README.md#how-do-i-update-youtube-dl) and update. Issues with outdated version will be rejected.
- [x] I've **verified** and **I assure** that I'm running youtube-dl **2016.05.01**
### Before submitting an _issue_ make sure you have:
- [x] At least skimmed through [README](https://github.com/rg3/youtube-dl/blob/master/README.md) and **most notably** [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones
### What is the purpose of your _issue_?
- [x] Bug report (encountered problems with youtube-dl)
- [ ] Site support request (request for adding support for a new site)
- [ ] Feature request (request for a new functionality)
- [ ] Question
- [ ] Other

---

I have the following config file:

``` bash
$ cat ~/.config/youtube-dl.conf 
--batch-file ~/watch-later.txt
```

When I call the CLI, it find the config file but fail to parse the `--batch-file` parameter because of the usage of the `~` shortcut:

``` bash
$ youtube-dl -v
[debug] System config: []
[debug] User config: [u'--batch-file', u'~/watch-later.txt']
[debug] Command-line args: [u'-v']
ERROR: batch file could not be read
```

The the thing is, `~` is properly extended when the CLI is called from a shell:

``` bash
$ youtube-dl -v --batch-file ~/watch-later.txt
[debug] System config: []
[debug] User config: [u'--batch-file', u'~/watch-later.txt']
[debug] Command-line args: [u'-v', u'--batch-file', u'/Users/kdeldycke/watch-later.txt']
[debug] Batch file urls: [u'http://youtu.be/Y-rmzh0PI3c']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2016.05.01
[debug] Python version 2.7.11 - Darwin-15.4.0-x86_64-i386-64bit
[debug] exe versions: ffmpeg 3.0.1, ffprobe 3.0.1, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] Y-rmzh0PI3c: Downloading webpage
[youtube] Y-rmzh0PI3c: Downloading video info webpage
[youtube] Y-rmzh0PI3c: Extracting video information
[youtube] Y-rmzh0PI3c: Downloading MPD manifest
[debug] Invoking downloader on u'https://r5---sn-4gxx-25g6.googlevideo.com/videoplayback?dur=730.615&key=yt6&lmt=1439788345379730&fexp=9405991%2C9413138%2C9416126%2C9416891%2C9419277%2C9421352%2C9422596%2C9423347%2C9427789%2C9428398%2C9428790%2C9431012%2C9431270%2C9432365%2C9433096%2C9433946%2C9434606%2C9435331%2C9435667%2C9436129&usequic=no&ipbits=0&initcwndbps=765000&mime=video%2Fmp4&requiressl=yes&signature=C00C6529010C74C3564A05B1C52041959ADCBA94.E29705494DC729653F7D161F085D7415D9A16BA8&source=youtube&upn=AYLUoR11-rM&ms=au&itag=22&pl=15&mt=1462642550&mn=sn-4gxx-25g6&mm=31&mv=m&id=o-ADVWV25T1VWCApkACwdrsxRXqBGpnsvxqW-DHAKYA8LD&sver=3&ratebypass=yes&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cusequic%2Cexpire&ip=88.190.24.238&expire=1462664348'
[download] Resuming download at byte 2096128
[download] Destination: /Users/kevin/Cosmos Laundromat - First Cycle. Official Blender Foundation release.-Y-rmzh0PI3c.mp4
[download]  23.2% of 164.11MiB at 18.81MiB/s ETA 00:06
(...)
```

I think this bug can be fixed by always expanding the `~` home variable when normalizing the batch file parameter.



Discussion:
Just found out there's already a `compat_expanduser()` method defined in the project to handle this case at: https://github.com/rg3/youtube-dl/blob/536a55dabd7bcc2f34195beb84211028c934ed7a/youtube_dl/compat.py#L375


Resolving patch:
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -86,7 +86,9 @@ def _real_main(argv=None):
             if opts.batchfile == '-':
                 batchfd = sys.stdin
             else:
-                batchfd = io.open(opts.batchfile, 'r', encoding='utf-8', errors='ignore')
+                batchfd = io.open(
+                    compat_expanduser(opts.batchfile),
+                    'r', encoding='utf-8', errors='ignore')
             batch_urls = read_batch_urls(batchfd)
             if opts.verbose:
                 write_string('[debug] Batch file urls: ' + repr(batch_urls) + '\n')


Test patch: