Repository: ytdl-org/youtube-dl

Issue:
unified_strdate returns None on dates with "3rd" and "23rd"
<!--

######################################################################
  WARNING!
  IGNORING THE FOLLOWING TEMPLATE WILL RESULT IN ISSUE CLOSED AS INCOMPLETE
######################################################################

-->


## Checklist

<!--
Carefully read and work through this check list in order to prevent the most common mistakes and misuse of youtube-dl:
- First of, make sure you are using the latest version of youtube-dl. Run `youtube-dl --version` and ensure your version is 2019.11.22. If it's not, see https://yt-dl.org/update on how to update. Issues with outdated version will be REJECTED.
- Make sure that all provided video/audio/playlist URLs (if any) are alive and playable in a browser.
- Make sure that all URLs and arguments with special characters are properly quoted or escaped as explained in http://yt-dl.org/escape.
- Search the bugtracker for similar issues: http://yt-dl.org/search-issues. DO NOT post duplicates.
- Read bugs section in FAQ: http://yt-dl.org/reporting
- Finally, put x into all relevant boxes (like this [x])
-->

- [ ] I'm reporting a broken site support issue
- [x] I've verified that I'm running youtube-dl version **2019.11.22**
- [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
- [x] I've searched the bugtracker for similar bug reports including closed ones
- [x] I've read bugs section in FAQ


## Verbose log

<!--
Provide the complete verbose output of youtube-dl that clearly demonstrates the problem.
Add the `-v` flag to your command line you run youtube-dl with (`youtube-dl -v <your command line>`), copy the WHOLE output and insert it below. It should look similar to this:
 [debug] System config: []
 [debug] User config: []
 [debug] Command-line args: [u'-v', u'http://www.youtube.com/watch?v=BaW_jenozKcj']
 [debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
 [debug] youtube-dl version 2019.11.22
 [debug] Python version 2.7.11 - Windows-2003Server-5.2.3790-SP2
 [debug] exe versions: ffmpeg N-75573-g1d0487f, ffprobe N-75573-g1d0487f, rtmpdump 2.4
 [debug] Proxy map: {}
 <more lines>
-->

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['https://www.bitchute.com/video/KDAtOH7nEUGe/', '--no-check-certificate', '--verbose']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2019.11.22
[debug] Git HEAD: 8267f2fa9
[debug] Python version 3.7.4 (CPython) - Linux-5.3.8-gnu-x86_64-with-glibc2.2.5
[debug] exe versions: ffmpeg 4.2.1, ffprobe 4.2.1
[debug] Proxy map: {}
[BitChute] KDAtOH7nEUGe: Downloading webpage
[BitChute] KDAtOH7nEUGe: Checking video URL

(Custom output snipped. See description for details.)




## Description

<!--
Provide an explanation of your issue in an arbitrary form. Please make sure the description is worded well enough to be understood, see https://github.com/ytdl-org/youtube-dl#is-the-description-of-the-issue-itself-sufficient. Provide any additional information, suggested solution and as much context and examples as possible.
If work on your issue requires account credentials please provide them or explain how one can obtain them.
-->

"unified_strdate" from utils returns None instead of a date if the string sent contains "3rd" or "23rd".

I initially discovered this issue when creating pull #23193. Other sites (such as youtube) don't seem to have prefixes such as "*st", "*nd", "*rd", etc, on the day of the month, and thus don't seem to run into this problem when getting dates.

I hacked together a quick test patch that runs through all possible dates and displays them along with the converted version from unified_strdate. The full output and the test patch are attached. To run it, just apply the patch and tell youtube-dl to download any bitchute video (I used "https://www.bitchute.com/video/KDAtOH7nEUGe/" in this example, but any video will work).

[date_test_patch.txt](https://github.com/ytdl-org/youtube-dl/files/3884233/date_test_patch.txt)
[output.txt](https://github.com/ytdl-org/youtube-dl/files/3884234/output.txt)

As you can see from this snippet, all of the 3rd and 23rd days return "None" instead of a date. The full output also has "None" in days that do not exist (such as February 31st), since this was just a quick hack to check which dates worked and which didn't.

```
January 1st, 2019:  20190101
January 2nd, 2019:  20190102
January 3rd, 2019:  None
January 4th, 2019:  20190104
...
January 22nd, 2019:  20190122
January 23rd, 2019:  None
January 24th, 2019:  20190124
...
February 2nd, 2019:  20190202
February 3rd, 2019:  None
February 4th, 2019:  20190204
...
```


Discussion:

Resolving patch:
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1718,13 +1718,16 @@ def random_user_agent():
     '%B %d %Y',
     '%B %dst %Y',
     '%B %dnd %Y',
+    '%B %drd %Y',
     '%B %dth %Y',
     '%b %d %Y',
     '%b %dst %Y',
     '%b %dnd %Y',
+    '%b %drd %Y',
     '%b %dth %Y',
     '%b %dst %Y %I:%M',
     '%b %dnd %Y %I:%M',
+    '%b %drd %Y %I:%M',
     '%b %dth %Y %I:%M',
     '%Y %m %d',
     '%Y-%m-%d',


Test patch:
diff --git a/test/test_utils.py b/test/test_utils.py
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -340,6 +340,8 @@ def test_unified_dates(self):
         self.assertEqual(unified_strdate('July 15th, 2013'), '20130715')
         self.assertEqual(unified_strdate('September 1st, 2013'), '20130901')
         self.assertEqual(unified_strdate('Sep 2nd, 2013'), '20130902')
+        self.assertEqual(unified_strdate('November 3rd, 2019'), '20191103')
+        self.assertEqual(unified_strdate('October 23rd, 2005'), '20051023')
 
     def test_unified_timestamps(self):
         self.assertEqual(unified_timestamp('December 21, 2010'), 1292889600)