Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Broken wcsftime in uClibc yields to broken unified_strdate (was: youtube-dl not works with python 3.5) #9557
Comments
|
Run the command |
|
Duplicate of #7875. |
|
Well both occur on ARM. @MrDini123 Which board are you using and how did you install Python? |
|
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. |
|
Seems the following code segment in # 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 |
|
Certainly.
This is the verbose output with print. But I Can't see the print's output in this out... |
It's indeed an empty string. 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'))) |
|
|
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:
|
|
Where did you insert |
|
After this:
|
|
What are the values of |
|
I tried to paste the print out of the if, but it says sg like this:
|
|
And here is the wrong part of the code:
|
|
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)) |
|
Right! :)
|
|
Now we know 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))) |
|
Here it is:
|
|
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:
If you got something different, your Python needs a fix. |
|
Unfortunatelly it is different...
What Do You think, what compile parameter is missing? |
|
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. |
|
I think it isn't a python bug:
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. |
|
wcsftime is broken on your sys while strftime works fine. You can manually disable wcsftime in |
|
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! |
|
Great! Thanks for helping testing. |
Please follow the guide below
xinto all the boxes [ ] relevant to your issue (like that [x])Make sure you are using the latest version: run
youtube-dl --versionand ensure your version is 2016.05.16. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.Before submitting an issue make sure you have:
What is the purpose of your issue?
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
-vflag 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 ```):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!