{"action":"created","issue":{"url":"https://api.github.com/repos/rg3/youtube-dl/issues/7332","labels_url":"https://api.github.com/repos/rg3/youtube-dl/issues/7332/labels{/name}","comments_url":"https://api.github.com/repos/rg3/youtube-dl/issues/7332/comments","events_url":"https://api.github.com/repos/rg3/youtube-dl/issues/7332/events","html_url":"https://github.com/rg3/youtube-dl/pull/7332","id":114405647,"number":7332,"title":"Remove trailing whitespaces on sanitizing filename","user":{"login":"hakatashi","id":3126484,"avatar_url":"https://avatars.githubusercontent.com/u/3126484?v=3","gravatar_id":"","url":"https://api.github.com/users/hakatashi","html_url":"https://github.com/hakatashi","followers_url":"https://api.github.com/users/hakatashi/followers","following_url":"https://api.github.com/users/hakatashi/following{/other_user}","gists_url":"https://api.github.com/users/hakatashi/gists{/gist_id}","starred_url":"https://api.github.com/users/hakatashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hakatashi/subscriptions","organizations_url":"https://api.github.com/users/hakatashi/orgs","repos_url":"https://api.github.com/users/hakatashi/repos","events_url":"https://api.github.com/users/hakatashi/events{/privacy}","received_events_url":"https://api.github.com/users/hakatashi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-31T11:44:05Z","updated_at":"2015-10-31T12:14:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rg3/youtube-dl/pulls/7332","html_url":"https://github.com/rg3/youtube-dl/pull/7332","diff_url":"https://github.com/rg3/youtube-dl/pull/7332.diff","patch_url":"https://github.com/rg3/youtube-dl/pull/7332.patch"},"body":"Python fails to make file or directory with the exact filename when it contains trailing spaces on Windows. When you do `os.mkdir(' foo ')` the directory \" foo\" will be made, which causes errors like the following.\r\n\r\n```\r\n> python -m youtube_dl --output \"%(uploader)s/%(id)s.%(ext)s\" --username hakatasiloving@gmail.com http://www.nicovideo.jp/watch/1445497631 --verbose\r\n[debug] System config: []\r\n[debug] User config: []\r\n[debug] Command-line args: ['--output', '%(uploader)s/%(id)s.%(ext)s', '--username', 'PRIVATE', 'http://www.nicovideo.jp/watch/1445497631', '--verbose']\r\nType account password and press [Return]:\r\n[debug] Encodings: locale cp932, fs mbcs, out cp932, pref cp932\r\n[debug] youtube-dl version 2015.10.24\r\n[debug] Git HEAD: 6722ebd\r\n[debug] Python version 3.4.3 - Windows-8-6.2.9200\r\n[debug] exe versions: ffmpeg N-50911-g9efcfbe, ffprobe 2.5.2, rtmpdump 2.3\r\n[debug] Proxy map: {}\r\n[niconico] Logging in\r\n[niconico] 1445497631: Downloading webpage\r\n[niconico] 1445497631: Downloading video info page\r\n[niconico] 1445497631: Downloading flv info\r\n[debug] Invoking downloader on 'http://smile-pow23.nicovideo.jp/smile?m=27423901.53970'\r\nERROR: unable to open for writing: [Errno 2] No such file or directory: 'Peeping Life TV シーズン1 \\\\1445497631.mp4.part'\r\nTraceback (most recent call last):\r\n  File \"C:\\Users\\hakatashi\\Documents\\GitHub\\youtube-dl\\youtube_dl\\downloader\\http.py\", line 174, in real_download\r\n    (stream, tmpfilename) = sanitize_open(tmpfilename, open_mode)\r\n  File \"C:\\Users\\hakatashi\\Documents\\GitHub\\youtube-dl\\youtube_dl\\utils.py\", line 285, in sanitize_open\r\n    stream = open(encodeFilename(filename), open_mode)\r\nFileNotFoundError: [Errno 2] No such file or directory: 'Peeping Life TV シーズン1 \\\\1445497631.mp4.part'\r\n```\r\n\r\nI simply add a command for removing trailing whitespaces in `sanitize_filename` and it seems work.\r\n\r\nPlease review. Thanks."},"comment":{"url":"https://api.github.com/repos/rg3/youtube-dl/issues/comments/152728498","html_url":"https://github.com/rg3/youtube-dl/pull/7332#issuecomment-152728498","issue_url":"https://api.github.com/repos/rg3/youtube-dl/issues/7332","id":152728498,"user":{"login":"dstftw","id":1908898,"avatar_url":"https://avatars.githubusercontent.com/u/1908898?v=3","gravatar_id":"","url":"https://api.github.com/users/dstftw","html_url":"https://github.com/dstftw","followers_url":"https://api.github.com/users/dstftw/followers","following_url":"https://api.github.com/users/dstftw/following{/other_user}","gists_url":"https://api.github.com/users/dstftw/gists{/gist_id}","starred_url":"https://api.github.com/users/dstftw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dstftw/subscriptions","organizations_url":"https://api.github.com/users/dstftw/orgs","repos_url":"https://api.github.com/users/dstftw/repos","events_url":"https://api.github.com/users/dstftw/events{/privacy}","received_events_url":"https://api.github.com/users/dstftw/received_events","type":"User","site_admin":false},"created_at":"2015-10-31T12:14:11Z","updated_at":"2015-10-31T12:14:11Z","body":"It's also probably better to just replace last trailing whitespace charatcter with `#` as we do for `.`."}}