{"action":"created","issue":{"url":"https://api.github.com/repos/rg3/youtube-dl/issues/6523","labels_url":"https://api.github.com/repos/rg3/youtube-dl/issues/6523/labels{/name}","comments_url":"https://api.github.com/repos/rg3/youtube-dl/issues/6523/comments","events_url":"https://api.github.com/repos/rg3/youtube-dl/issues/6523/events","html_url":"https://github.com/rg3/youtube-dl/pull/6523","id":100212307,"number":6523,"title":"Use `{title}` style for --output templates rather than `%(title)s`","user":{"login":"cousteaulecommandant","id":6584870,"avatar_url":"https://avatars.githubusercontent.com/u/6584870?v=3","gravatar_id":"","url":"https://api.github.com/users/cousteaulecommandant","html_url":"https://github.com/cousteaulecommandant","followers_url":"https://api.github.com/users/cousteaulecommandant/followers","following_url":"https://api.github.com/users/cousteaulecommandant/following{/other_user}","gists_url":"https://api.github.com/users/cousteaulecommandant/gists{/gist_id}","starred_url":"https://api.github.com/users/cousteaulecommandant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cousteaulecommandant/subscriptions","organizations_url":"https://api.github.com/users/cousteaulecommandant/orgs","repos_url":"https://api.github.com/users/cousteaulecommandant/repos","events_url":"https://api.github.com/users/cousteaulecommandant/events{/privacy}","received_events_url":"https://api.github.com/users/cousteaulecommandant/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-11T02:31:38Z","updated_at":"2015-09-10T20:54:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rg3/youtube-dl/pulls/6523","html_url":"https://github.com/rg3/youtube-dl/pull/6523","diff_url":"https://github.com/rg3/youtube-dl/pull/6523.diff","patch_url":"https://github.com/rg3/youtube-dl/pull/6523.patch"},"body":"Currently youtube-dl uses Python's native string interpolation for automated output file naming.  For example, `%(title)s` will be replaced with the video's title.  However, this syntax is ugly and counter-intuitive, specially for people who are not familiar with Python but still want to use this program.\r\n\r\nThis patch replaces the `%` interpolation with str.format() formatting, so that instead of `%(title)s` the user can just write `{title}`, which in my opinion looks quite better.  Plus it seems to be the preferred formatting method nowadays and it has more options.\r\n\r\nBackwards compatibility is provided by replacing all `%(whatever)s` in the template string with `{whatever}` using a regex, and `%%` with `%`; however this is a temporary (and ugly) workaround that can probably be removed in a future when users have gotten used to the new format.\r\n\r\nThis change requires Python 2.6 or greater to work, since `str.format()` is new in version 2.6 (if that version can be considered \"new\" at all nowadays).\r\n\r\nPS: I moved the call to `sanitize_path()` AFTER formatting the file name; it makes little sense to sanitize a format string rather than an actual file name/path."},"comment":{"url":"https://api.github.com/repos/rg3/youtube-dl/issues/comments/139376092","html_url":"https://github.com/rg3/youtube-dl/pull/6523#issuecomment-139376092","issue_url":"https://api.github.com/repos/rg3/youtube-dl/issues/6523","id":139376092,"user":{"login":"cousteaulecommandant","id":6584870,"avatar_url":"https://avatars.githubusercontent.com/u/6584870?v=3","gravatar_id":"","url":"https://api.github.com/users/cousteaulecommandant","html_url":"https://github.com/cousteaulecommandant","followers_url":"https://api.github.com/users/cousteaulecommandant/followers","following_url":"https://api.github.com/users/cousteaulecommandant/following{/other_user}","gists_url":"https://api.github.com/users/cousteaulecommandant/gists{/gist_id}","starred_url":"https://api.github.com/users/cousteaulecommandant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cousteaulecommandant/subscriptions","organizations_url":"https://api.github.com/users/cousteaulecommandant/orgs","repos_url":"https://api.github.com/users/cousteaulecommandant/repos","events_url":"https://api.github.com/users/cousteaulecommandant/events{/privacy}","received_events_url":"https://api.github.com/users/cousteaulecommandant/received_events","type":"User","site_admin":false},"created_at":"2015-09-10T20:54:56Z","updated_at":"2015-09-10T20:54:56Z","body":"In order to print a warning, I think the easiest way would be checking whether the template string has changed after the backwards compatibility hack, i.e.\r\n\r\n    tmpl2 = re.sub(r'(?<!%)((?:%)*)\\1%\\(([^)]*)\\)s', r'\\1{\\2}', tmpl).replace('%%','%')\r\n    if tmpl != tmpl2:\r\n        print \"%(key)s formatting style is deprecated; please use {key} style instead\"\r\n        tmpl = tmpl2\r\n\r\nHowever this should be done only once, maybe right after parsing the options.  If it's done where I'm doing it right now, the user would get one warning per downloaded file.  (Plus it does the replacement multiple times which doesn't feel OK)"}}