Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken wcsftime in uClibc yields to broken unified_strdate (was: youtube-dl not works with python 3.5) #9557

Closed
MrDini123 opened this issue May 21, 2016 · 25 comments
Labels

Comments

@MrDini123
Copy link

@MrDini123 MrDini123 commented May 21, 2016

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like that [x])
  • Use Preview tab to see how your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2016.05.16. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2016.05.16

Before submitting an issue make sure you have:

  • At least skimmed through README and most notably FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • 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

The following sections concretize particular purposed issues, you can erase any section (the contents between triple ---) not applicable to your issue


If the purpose of this issue is a bug report, site support request or you are not completely sure provide the full verbose output as follows:

Add -v flag to your command line you run youtube-dl with, copy the whole output and insert it here. It should look similar to one below (replace it with your log inserted between triple ```):

youtube-dl -v http://youtu.be/3wjb3HtD32c
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['-v', 'http://youtu.be/3wjb3HtD32c']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2016.05.16
[debug] Python version 3.5.1 - Linux-2.6.31.8-armv5tel-with-libc0
[debug] exe versions: ffmpeg 2.1.8-compiled_by_barmalej2_for_ffp0.7arm, ffprobe 2.1.8-compiled_by_barmalej2_for_ffp0.7arm, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] 3wjb3HtD32c: Downloading webpage
[youtube] 3wjb3HtD32c: Downloading video info webpage
[youtube] 3wjb3HtD32c: Extracting video information
[youtube] {22} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] 3wjb3HtD32c: Downloading player https://s.ytimg.com/yts/jsbin/player-en_US-vflGaNMBw/base.js
[youtube] {43} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {18} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {5} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {36} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {17} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {137} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {248} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {136} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {247} signature length 40.39, html5 player en_US-vflGaNMBw
[youtube] 3wjb3HtD32c: Downloading player https://s.ytimg.com/yts/jsbin/player-en_US-vflGaNMBw/base.js
[youtube] {135} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {244} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {134} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {243} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {133} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {242} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {160} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {278} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {140} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {171} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {249} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {250} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {251} signature length 40.41, html5 player en_US-vflGaNMBw
Traceback (most recent call last):
  File "/ffp/bin/youtube-dl", line 11, in <module>
    sys.exit(main())
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 421, in main
    _real_main(argv)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 411, in _real_main
    retcode = ydl.download(all_urls)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1736, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 687, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 733, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1382, in process_video_result
    self.process_info(new_info)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1453, in process_info
    reason = self._match_entry(info_dict, incomplete=False)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 620, in _match_entry
    if date not in dateRange:
  File "/ffp/lib/python3.5/site-packages/youtube_dl/utils.py", line 1138, in __contains__
    date = date_from_str(date)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/utils.py", line 1101, in date_from_str
    return datetime.datetime.strptime(date_str, '%Y%m%d').date()
  File "/ffp/lib/python3.5/_strptime.py", line 500, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/ffp/lib/python3.5/_strptime.py", line 337, in _strptime
    (data_string, format))
ValueError: time data '' does not match format '%Y%m%d'


Description of your issue, suggested solution and other information

Hi!

I'm using the youtube-dl tool about a few year ago and it works perfectly. But now I updated my python to 3.5.1, from the old 2.7 version. And if I try to download something it says a lot of errors. The errors Can be seen at the command line output part of the issue.

I installed it with pip, but if I compile it, the output is the same...

Thanks!

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

Run the command youtube-dl -vF "http://youtu.be/3wjb3HtD32c" --dump-pages > output.txt and upload output.txt.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented May 21, 2016

Duplicate of #7875.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

Well both occur on ARM. @MrDini123 Which board are you using and how did you install Python?

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

Okay, here it is:

http://pastebin.com/raw/iEskWDsP

(Sorry, but it was too long to paste it here.)

I'm using a ZyXEL nas with FFp. It has arm5 based processor. And with an old 2.6.31.8 kernel... :/ But it works really cool. The only bad thing is, I have to compile all of packages that I want... So the python is my compile too. But I didn't disabled anything at the configure and it works with some other python codes.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

Seems the following code segment in youtube_dl/extractor/youtube.py causes the failure:

        # upload date
        upload_date = self._html_search_meta(
            'datePublished', video_webpage, 'upload date', default=None)
        if not upload_date:
            upload_date = self._search_regex(
                [r'(?s)id="eow-date.*?>(.*?)</span>',
                 r'id="watch-uploader-info".*?>.*?(?:Published|Uploaded|Streamed live|Started) on (.+?)</strong>'],
                video_webpage, 'upload date', default=None)
            if upload_date:
                upload_date = ' '.join(re.sub(r'[/,-]', r' ', mobj.group(1)).split())
        upload_date = unified_strdate(upload_date)

On your board the final value of upload_date is an empty string '', but it should never be. Could you add some debugging print(upload_date) calls to track changes of its value?

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

Certainly.

youtube-dl -v http://youtu.be/3wjb3HtD32c       [debug] System config: []
[debug] User config: []
[debug] Command-line args: ['-v', 'http://youtu.be/3wjb3HtD32c'][debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8[debug] youtube-dl version 2016.05.16
[debug] Python version 3.5.1 - Linux-2.6.31.8-armv5tel-with-libc0
[debug] exe versions: ffmpeg 2.1.8-compiled_by_barmalej2_for_ffp0.7arm, ffprobe 2.1.8-compiled_by_barmalej2_for_ffp0.7arm, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] 3wjb3HtD32c: Downloading webpage
[youtube] 3wjb3HtD32c: Downloading video info webpage
[youtube] 3wjb3HtD32c: Extracting video information

[youtube] {22} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {43} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {18} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {5} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {36} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {17} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {137} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {248} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {136} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {247} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {135} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {244} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {134} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {243} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {133} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {242} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {160} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {278} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {140} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {171} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {249} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {250} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {251} signature length 40.41, html5 player en_US-vflGaNMBw
Traceback (most recent call last):
  File "/ffp/bin/youtube-dl", line 11, in <module>
    sys.exit(main())
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 421, in main
    _real_main(argv)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 411, in _real_main
    retcode = ydl.download(all_urls)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1736, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 687, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 733, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1382, in process_video_result
    self.process_info(new_info)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1453, in process_info
    reason = self._match_entry(info_dict, incomplete=False)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 620, in _match_entry
    if date not in dateRange:
  File "/ffp/lib/python3.5/site-packages/youtube_dl/utils.py", line 1138, in __contains__
    date = date_from_str(date)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/utils.py", line 1101, in date_from_str
    return datetime.datetime.strptime(date_str, '%Y%m%d').date()  File "/ffp/lib/python3.5/_strptime.py", line 500, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/ffp/lib/python3.5/_strptime.py", line 337, in _strptime    (data_string, format))
ValueError: time data '' does not match format '%Y%m%d'

This is the verbose output with print. But I Can't see the print's output in this out...

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

[youtube] 3wjb3HtD32c: Extracting video information

[youtube] {22} signature length 40.41, html5 player en_US-vflGaNMBw

It's indeed an empty string. print('------%s------' % upload_date) should make things clear.

Could you try the following minimal script?

import re
import urllib.request

webpage = urllib.request.urlopen('http://youtu.be/3wjb3HtD32c').read().decode('utf-8')

mobj = re.search(
    r'''(?isx)<meta
        (?=[^>]+(?:itemprop|name|property|id|http-equiv)=(["\']?)%s\1)
        [^>]+?content=(["\'])(?P<content>.*?)\2''' % re.escape('datePublished'), webpage)

print(repr(mobj))
print(repr(mobj.group('content')))
@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

 python ./test.py
  File "./test.py", line 11
    print(repr(mobj))
    ^
IndentationError: unexpected indent
@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

Oh. It don't like if I paste a code via mc. But if I modify the py file by vi it works and says this:

<_sre.SRE_Match object; span=(103467, 103518), match='<meta itemprop="datePublished" content="2016-03-1>
'2016-03-11'

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

Where did you insert print(upload_date)?

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

After this:

upload_date = unified_strdate(upload_date)
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

What are the values of upload_date just before unified_strdate and just after self._html_search_regex? Use print(repr(upload_date)) so that empty strings are printed as ''.

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

I tried to paste the print out of the if, but it says sg like this:

youtube-dl -v http://youtu.be/3wjb3HtD32c
Traceback (most recent call last):
  File "/ffp/lib/python3.5/site-packages/youtube_dl/extractor/__init__.py", line 4, in <module>
    from .lazy_extractors import *
ImportError: No module named 'youtube_dl.extractor.lazy_extractors'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/ffp/bin/youtube-dl", line 7, in <module>
    from youtube_dl import main
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 43, in <module>
    from .extractor import gen_extractors, list_extractors
  File "/ffp/lib/python3.5/site-packages/youtube_dl/extractor/__init__.py", line 9, in <module>
    from .extractors import *
  File "/ffp/lib/python3.5/site-packages/youtube_dl/extractor/extractors.py", line 39, in <module>
    from .ard import (
  File "/ffp/lib/python3.5/site-packages/youtube_dl/extractor/ard.py", line 7, in <module>
    from .generic import GenericIE
  File "/ffp/lib/python3.5/site-packages/youtube_dl/extractor/generic.py", line 10, in <module>
    from .youtube import YoutubeIE
  File "/ffp/lib/python3.5/site-packages/youtube_dl/extractor/youtube.py", line 1421
    print(repr(upload_date))
                           ^
IndentationError: unindent does not match any outer indentation level
@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

And here is the wrong part of the code:

       # upload date
        upload_date = self._html_search_meta(
            'datePublished', video_webpage, 'upload date', default=None)
        if not upload_date:
            upload_date = self._search_regex(
                [r'(?s)id="eow-date.*?>(.*?)</span>',
                 r'id="watch-uploader-info".*?>.*?(?:Published|Uploaded|Streamed live|Started) on (.+?)</strong>'],
                video_webpage, 'upload date', default=None)
            if upload_date:
                upload_date = ' '.join(re.sub(r'[/,-]', r' ', mobj.group(1)).split())
        upload_date = unified_strdate(upload_date)
     print(repr(upload_date))
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

Python enforces strict code identation. The following codes should work:

        # upload date
        upload_date = self._html_search_meta(
            'datePublished', video_webpage, 'upload date', default=None)
        print(repr(upload_date))
        if not upload_date:
            upload_date = self._search_regex(
                [r'(?s)id="eow-date.*?>(.*?)</span>',
                 r'id="watch-uploader-info".*?>.*?(?:Published|Uploaded|Streamed live|Started) on (.+?)</strong>'],
                video_webpage, 'upload date', default=None)
            print(repr(upload_date))
            if upload_date:
                upload_date = ' '.join(re.sub(r'[/,-]', r' ', mobj.group(1)).split())
        print(repr(upload_date))
        upload_date = unified_strdate(upload_date)
        print(repr(upload_date))
@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

Right! :)

youtube-dl -v http://youtu.be/3wjb3HtD32c
[debug] System config: []
[debug] User config: []
[debug] Command-line args: ['-v', 'http://youtu.be/3wjb3HtD32c'][debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8[debug] youtube-dl version 2016.05.16
[debug] Python version 3.5.1 - Linux-2.6.31.8-armv5tel-with-libc0
[debug] exe versions: ffmpeg 2.1.8-compiled_by_barmalej2_for_ffp0.7arm, ffprobe 2.1.8-compiled_by_barmalej2_for_ffp0.7arm, rtmpdump 2.4
[debug] Proxy map: {}
[youtube] 3wjb3HtD32c: Downloading webpage
[youtube] 3wjb3HtD32c: Downloading video info webpage
[youtube] 3wjb3HtD32c: Extracting video information
'2016-03-11'
'2016-03-11'
''
[youtube] {22} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {43} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {18} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {5} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {36} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {17} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {137} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {248} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {136} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {247} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {135} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {244} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {134} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {243} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {133} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {242} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {160} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {278} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {140} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {171} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {249} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {250} signature length 40.41, html5 player en_US-vflGaNMBw
[youtube] {251} signature length 40.41, html5 player en_US-vflGaNMBw
Traceback (most recent call last):
  File "/ffp/bin/youtube-dl", line 11, in <module>
    sys.exit(main())
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 421, in main
    _real_main(argv)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/__init__.py", line 411, in _real_main
    retcode = ydl.download(all_urls)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1736, in download
    url, force_generic_extractor=self.params.get('force_generic_extractor', False))
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 687, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 733, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1382, in process_video_result
    self.process_info(new_info)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 1453, in process_info
    reason = self._match_entry(info_dict, incomplete=False)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/YoutubeDL.py", line 620, in _match_entry
    if date not in dateRange:
  File "/ffp/lib/python3.5/site-packages/youtube_dl/utils.py", line 1138, in __contains__
    date = date_from_str(date)
  File "/ffp/lib/python3.5/site-packages/youtube_dl/utils.py", line 1101, in date_from_str
    return datetime.datetime.strptime(date_str, '%Y%m%d').date()  File "/ffp/lib/python3.5/_strptime.py", line 500, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/ffp/lib/python3.5/_strptime.py", line 337, in _strptime    (data_string, format))
ValueError: time data '' does not match format '%Y%m%d'
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

Now we know unified_strdate is broken. Please save the following codes as test_unified_strdate.py and run it with Python:

import datetime
import email
import re

date_str = '2016-03-11'

upload_date = None
# %z (UTC offset) is only supported in python>=3.2
if not re.match(r'^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$', date_str):
    date_str = re.sub(r' ?(\+|-)[0-9]{2}:?[0-9]{2}$', '', date_str)
# Remove AM/PM + timezone
date_str = re.sub(r'(?i)\s*(?:AM|PM)(?:\s+[A-Z]+)?', '', date_str)
print(repr(date_str))

format_expressions = [
    '%d %B %Y',
    '%d %b %Y',
    '%B %d %Y',
    '%b %d %Y',
    '%b %dst %Y %I:%M',
    '%b %dnd %Y %I:%M',
    '%b %dth %Y %I:%M',
    '%Y %m %d',
    '%Y-%m-%d',
    '%Y/%m/%d',
    '%Y/%m/%d %H:%M:%S',
    '%Y-%m-%d %H:%M:%S',
    '%Y-%m-%d %H:%M:%S.%f',
    '%d.%m.%Y %H:%M',
    '%d.%m.%Y %H.%M',
    '%Y-%m-%dT%H:%M:%SZ',
    '%Y-%m-%dT%H:%M:%S.%fZ',
    '%Y-%m-%dT%H:%M:%S.%f0Z',
    '%Y-%m-%dT%H:%M:%S',
    '%Y-%m-%dT%H:%M:%S.%f',
    '%Y-%m-%dT%H:%M',
    '%d-%m-%Y',
    '%d.%m.%Y',
    '%d/%m/%Y',
    '%d/%m/%y',
    '%d/%m/%Y %H:%M:%S',
]
for expression in format_expressions:
    try:
        print(expression)
        upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d')
        print(repr(upload_date))
    except ValueError:
        pass
if upload_date is None:
    timetuple = email.utils.parsedate_tz(date_str)
    print(repr(timetuple))
    if timetuple:
        upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
if upload_date is not None:
    print(repr(str(upload_date)))
@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

Here it is:

python ./test_unified_strdate.py
'2016-03-11'
%d %B %Y
%d %b %Y
%B %d %Y
%b %d %Y
%b %dst %Y %I:%M
%b %dnd %Y %I:%M
%b %dth %Y %I:%M
%Y %m %d
%Y-%m-%d
''
%Y/%m/%d
%Y/%m/%d %H:%M:%S
%Y-%m-%d %H:%M:%S
%Y-%m-%d %H:%M:%S.%f
%d.%m.%Y %H:%M
%d.%m.%Y %H.%M
%Y-%m-%dT%H:%M:%SZ
%Y-%m-%dT%H:%M:%S.%fZ
%Y-%m-%dT%H:%M:%S.%f0Z
%Y-%m-%dT%H:%M:%S
%Y-%m-%dT%H:%M:%S.%f
%Y-%m-%dT%H:%M
%d-%m-%Y
%d.%m.%Y
%d/%m/%Y
%d/%m/%y
%d/%m/%Y %H:%M:%S
''
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

And how about it?

import datetime

t = datetime.datetime.strptime('2016-03-11', '%Y-%m-%d')
print(repr(t))
s = t.strftime('%Y%m%d')
print(repr(s))
t = datetime.datetime(2016, 3, 11, 0, 0)
print(repr(t))
s = t.strftime('%Y%m%d')
print(repr(s))

On my machine (Python 3.5.1 on x86_64 PC), the result is:

datetime.datetime(2016, 3, 11, 0, 0)
'20160311'
datetime.datetime(2016, 3, 11, 0, 0)
'20160311'

If you got something different, your Python needs a fix.

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

Unfortunatelly it is different...

python ./test_unified_strdate.py
datetime.datetime(2016, 3, 11, 0, 0)
''
datetime.datetime(2016, 3, 11, 0, 0)
''

What Do You think, what compile parameter is missing?

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

I guess strftime on your system is broken. Please try the following two C programs:

#include <stdio.h>
#include <string.h>
#include <time.h>

int main()
{
    char buf[1024];
    struct tm t;
    memset(buf, 0, sizeof(buf));
    memset(&t, 0, sizeof(t));
    t.tm_year = 2016 - 1900;
    t.tm_mon = 3 - 1;
    t.tm_mday = 11;
    strftime(buf, 1024, "%Y%m%d", &t);
    printf("%s\n", buf);
    return 0;
}

And:

#include <string.h>
#include <time.h>
#include <wchar.h>

int main()
{
    wchar_t buf[1024];
    struct tm t;
    memset(buf, 0, sizeof(buf));
    memset(&t, 0, sizeof(t));
    t.tm_year = 2016 - 1900;
    t.tm_mon = 3 - 1;
    t.tm_mday = 11;
    wcsftime(buf, 1024, L"%Y%m%d", &t);
    wprintf(L"%ls\n", buf);
    return 0;
}

Both programs should print 20160311. If any not, ask your board vendor or support forums. If C programs give correct outputs while Python not, go to https://bugs.python.org/ and file a bug.

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 21, 2016

I think it isn't a python bug:

root@NSA320S:~# ./first.out
20160311
root@NSA320S:~# ./second.out

Ok, many thanks for Your help, I will ask it in the nas forum. I'm going to close this and if it won't be solved, I will reopen it.

@MrDini123 MrDini123 closed this May 21, 2016
@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 21, 2016

wcsftime is broken on your sys while strftime works fine. You can manually disable wcsftime in pyconfig.h.in.

@MrDini123
Copy link
Author

@MrDini123 MrDini123 commented May 22, 2016

Hi!

It is an uClibc bug. Because the wcsftime() doesn't backported to 0.9.33 branch...

So I solved the problem by removing wcsftime from the configure script and I had to recompile it. Because the python 3.* by default try to use the wcsftime and only in case when the wcsftime isn't available try to use rhe strptime.

Or as a second solution (as a forum member at my nas's topic said) i Could manualy bacport it to the uClibc.

And now, it works perfectly! :)

Thanks a lot!

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented May 22, 2016

Great! Thanks for helping testing.

@yan12125 yan12125 changed the title youtube-dl not works with python 3.5 Broken wcsftime in uClibc yields to broken unified_strdate (was: youtube-dl not works with python 3.5) May 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.