nficano commited on
Commit
aaf6096
·
2 Parent(s): 8c8aae3 9972145

Merge pull request #4 from randomchars/master

Browse files
Files changed (2) hide show
  1. pytube/__init__.py +8 -5
  2. setup.py +1 -0
pytube/__init__.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from os.path import normpath
2
  from urllib import urlencode
3
  from urllib2 import urlopen
@@ -93,8 +95,9 @@ class Video(object):
93
  path = (normpath(path) + '/' if path else '')
94
  response = urlopen(self.url)
95
  with open(path + self.filename, 'wb') as dst_file:
96
- meta_data = response.info()
97
- file_size = int(meta_data.getheaders("Content-Length")[0])
 
98
  print "Downloading: %s Bytes: %s" % (self.filename, file_size)
99
 
100
  bytes_received = 0
@@ -116,11 +119,11 @@ class Video(object):
116
  return "<Video: %s (.%s) - %s>" % (self.video_codec, self.extension,
117
  self.resolution)
118
 
119
- def __cmp__(self, other):
120
  if type(other) == Video:
121
  v1 = "%s %s" % (self.extension, self.resolution)
122
  v2 = "%s %s" % (other.extension, other.resolution)
123
- return cmp(v1, v2)
124
 
125
 
126
  class YouTube(object):
@@ -261,7 +264,7 @@ class YouTube(object):
261
  response = urlopen(YT_BASE_URL + '?' + querystring)
262
 
263
  if response:
264
- content = response.read()
265
  data = parse_qs(content)
266
  if 'errorcode' in data:
267
  error = data.get('reason', 'An unknown error has occurred')
 
1
+ from __future__ import unicode_literals
2
+
3
  from os.path import normpath
4
  from urllib import urlencode
5
  from urllib2 import urlopen
 
95
  path = (normpath(path) + '/' if path else '')
96
  response = urlopen(self.url)
97
  with open(path + self.filename, 'wb') as dst_file:
98
+ meta_data = dict(response.info().items())
99
+ file_size = int(meta_data.get("Content-Length") or
100
+ meta_data.get("content-length"))
101
  print "Downloading: %s Bytes: %s" % (self.filename, file_size)
102
 
103
  bytes_received = 0
 
119
  return "<Video: %s (.%s) - %s>" % (self.video_codec, self.extension,
120
  self.resolution)
121
 
122
+ def __lt__(self, other):
123
  if type(other) == Video:
124
  v1 = "%s %s" % (self.extension, self.resolution)
125
  v2 = "%s %s" % (other.extension, other.resolution)
126
+ return (v1 > v2) - (v1 < v2) < 0
127
 
128
 
129
  class YouTube(object):
 
264
  response = urlopen(YT_BASE_URL + '?' + querystring)
265
 
266
  if response:
267
+ content = response.read().decode()
268
  data = parse_qs(content)
269
  if 'errorcode' in data:
270
  error = data.get('reason', 'An unknown error has occurred')
setup.py CHANGED
@@ -20,6 +20,7 @@ setup(
20
  url = "https://github.com/NFicano/python-youtube-download",
21
  download_url="https://github.com/NFicano/python-youtube-download/tarball/master",
22
  packages=['pytube'],
 
23
  long_description=read('README.md'),
24
  classifiers=[
25
  "Development Status :: 4 - Beta",
 
20
  url = "https://github.com/NFicano/python-youtube-download",
21
  download_url="https://github.com/NFicano/python-youtube-download/tarball/master",
22
  packages=['pytube'],
23
+ use_2to3= True,
24
  long_description=read('README.md'),
25
  classifiers=[
26
  "Development Status :: 4 - Beta",