Repository: yt-dlp/yt-dlp

Issue:
upload_date pulls wrong date for afreecaTV
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2021.12.01**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#video-url-contains-an-ampersand-and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [ ] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

no geo-block

### Description

When I try to download a VOD from afreecaTV with the upload date as output name, it gives me 2021 January 02 or NA even if the VOD wasn't uploaded on that date. The upload_date works few months ago when I last used it.

Here are some sample links:
https://vod.afreecatv.com/PLAYER/STATION/81558503
https://vod.afreecatv.com/PLAYER/STATION/79406380



### Verbose log

```shell
K:\youtube-dl>yt-dlp -Uv https://vod.afreecatv.com/PLAYER/STATION/81558503 -o h:\%(upload_date)s-%(uploader)s-%(title)s.%(ext)s
[debug] Command-line config: ['-Uv', 'https://vod.afreecatv.com/PLAYER/STATION/81558503', '-o', 'h:\\%(upload_date)s-%(uploader)s-%(title)s.%(ext)s']
[debug] Encodings: locale cp950, fs utf-8, out utf-8, err utf-8, pref cp950
[debug] yt-dlp version 2021.12.01 [91f071a] (win_exe)
[debug] Python version 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
[debug] exe versions: ffmpeg 4.2, ffprobe 4.2
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2021.12.01, Current version: 2021.12.01
yt-dlp is up to date (2021.12.01)
[debug] [afreecatv] Extracting URL: https://vod.afreecatv.com/PLAYER/STATION/81558503
[afreecatv] 81558503: Downloading webpage
[afreecatv] 81558503: Downloading video info XML
[afreecatv] 81558503: Downloading part 1 m3u8 information
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[download] Downloading playlist: 엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ
[afreecatv] playlist 엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ: Collected 1 videos; downloading 1 of them
[download] Downloading video 1 of 1
[debug] Default format spec: bestvideo*+bestaudio/best
[info] 20211221_10C22F41_237809232_3: Downloading 1 format(s): hls-original
[debug] Invoking downloader on "http://vod-archive-global-cdn-z02.afreecatv.com/v101/hls/vod/20211221/232/237809232/REGL_10C22F41_237809232_3.smil/original/both/playlist.m3u8"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 100
[download] Destination: h:\20210102-크레용팝엘린-엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ.mp4
[download] 100% of 188.63MiB in 00:03
[debug] ffprobe command line: ffprobe -hide_banner -show_format -show_streams -print_format json "file:h:\20210102-크레 용팝엘린-엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ.mp4"
[FixupM3u8] Fixing MPEG-TS in MP4 container of "h:\20210102-크레용팝엘린-엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:h:\20210102-크레용팝엘린-엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ.mp4" -c copy -map 0 -dn -f mp4 "-bsf:a" aac_adtstoasc "file:h:\20210102-크레용팝엘린-엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ.temp.mp4"
[download] Finished downloading playlist: 엘린 세비지가쏘아올린공 허그가 당했누..'-'ㅎ
```



Discussion:
The extractor currently guesses at the upload date by looking for it at the beginning of the file key. Apparently that heuristic used to be reliable, but some time ago I discovered a small number of videos for which that heuristic didn't work. In [this commit](https://github.com/yt-dlp/yt-dlp/commit/b2eeee0ce018a50cb6f496829147fbc1f85f0487), I made the extractor reject values that were obviously invalid. In making that change, I updated the date parsing to pass through the `unified_strdate` utility function. It appears that `unified_strdate` is buggy; passing in a string of `20211221` results in `20210102` as output.

Conclusion: this bug for the AfreecaTV extractor was introduced in version 2021.09.01. However, the underlying cause is a problem in the common utilities, not the extractor itself.
Looks like (surprisingly, to me) the date format `%Y%m%d%H%M` will successfully match against one-digit month, day, hour, and minute strings (even though `%m` et. al. are documented as being zero-padded). For most of the year, the leading or trailing zero on the two-digit month prevents it from matching, but for dates in November and December, `11` can parse as January 1st, and `12` as January 2nd (with the actual day being interpreted as hour and minute).

I think a valid fix would be to add a format string of `%Y%m%d` to our supported format strings, with higher priority. It's worth noting that the parsing function doesn't exit the loop on the first successful match, so higher priority is at the *bottom* of the format list, not the top.

Resolving patch:
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -210,6 +210,7 @@ def random_user_agent():
     '%Y/%m/%d %H:%M:%S',
     '%Y%m%d%H%M',
     '%Y%m%d%H%M%S',
+    '%Y%m%d',
     '%Y-%m-%d %H:%M',
     '%Y-%m-%d %H:%M:%S',
     '%Y-%m-%d %H:%M:%S.%f',


Test patch: