# Author: Benjamin Johnson
# License: Public domain code
import cookielib
-import datetime
import htmlentitydefs
import httplib
import locale
from cgi import parse_qs
std_headers = {
- 'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.11) Gecko/20101019 Firefox/3.6.11',
+ 'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101028 Firefox/3.6.12',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5',
simple_title_chars = string.ascii_letters.decode('ascii') + string.digits.decode('ascii')
+month_name_to_number = {
+ 'January': '01',
+ 'February': '02',
+ 'March': '03',
+ 'April': '04',
+ 'May': '05',
+ 'June': '06',
+ 'July': '07',
+ 'August': '08',
+ 'September': '09',
+ 'October': '10',
+ 'November': '11',
+ 'December': '12',
+}
+
def preferredencoding():
"""Get preferred encoding.
_AGE_URL = 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'
_NETRC_MACHINE = 'youtube'
# Listed in order of quality
- _available_formats = ['38', '37', '22', '45', '35', '34', '43', '18', '6', '5', '17', '13']
+ _available_formats = ['38', '37', '45', '22', '43', '35', '34', '18', '6', '5', '17', '13']
_video_extensions = {
'13': '3gp',
'17': 'mp4',
upload_date = u'NA'
mobj = re.search(r'id="eow-date".*?>(.*?)</span>', video_webpage, re.DOTALL)
if mobj is not None:
- upload_date = mobj.group(1).split()
- format_expressions = ['%d %B %Y', '%B %d, %Y']
- for expression in format_expressions:
- try:
- upload_date = datetime.datetime.strptime(upload_date, expression).strftime('%Y%m%d')
- except:
- pass
+ try:
+ if ',' in mobj.group(1):
+ # Month Day, Year
+ m, d, y = mobj.group(1).replace(',', '').split()
+ else:
+ # Day Month Year, we'll suppose
+ d, m, y = mobj.group(1).split()
+ m = month_name_to_number[m]
+ d = '%02d' % (long(d))
+ upload_date = '%s%s%s' % (y, m, d)
+ except:
+ upload_date = u'NA'
# description
video_description = 'No description available.'
'id': video_id.decode('utf-8'),
'url': video_real_url.decode('utf-8'),
'uploader': video_uploader.decode('utf-8'),
- 'uploaddate': upload_date,
+ 'upload_date': upload_date,
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
'id': video_id.decode('utf-8'),
'url': video_url.decode('utf-8'),
'uploader': video_uploader.decode('utf-8'),
- 'uploaddate': u'NA',
+ 'upload_date': u'NA',
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
'id': video_id.decode('utf-8'),
'url': video_url.decode('utf-8'),
'uploader': video_uploader.decode('utf-8'),
- 'uploaddate': u'NA',
+ 'upload_date': u'NA',
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
'id': video_id.decode('utf-8'),
'url': video_url.decode('utf-8'),
'uploader': u'NA',
- 'uploaddate': u'NA',
+ 'upload_date': u'NA',
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
'id': video_id.decode('utf-8'),
'url': video_url.decode('utf-8'),
'uploader': video_uploader,
- 'uploaddate': u'NA',
+ 'upload_date': u'NA',
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
'id': video_id.decode('utf-8'),
'url': video_url,
'uploader': video_uploader,
- 'uploaddate': u'NA',
+ 'upload_date': u'NA',
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
'id': video_id.decode('utf-8'),
'url': video_url.decode('utf-8'),
'uploader': video_uploader,
- 'uploaddate': u'NA',
+ 'upload_date': u'NA',
'title': video_title,
'stitle': simple_title,
'ext': video_extension.decode('utf-8'),
# Parse command line
parser = optparse.OptionParser(
usage='Usage: %prog [options] url...',
- version='2010.10.24',
+ version='2010.11.19',
conflict_handler='resolve',
)