nficano commited on
Commit
a45d9ef
·
2 Parent(s): 79e3d84 dd5bf45

Merge branch 'master' of github.com:NFicano/pytube

Browse files

* 'master' of github.com:NFicano/pytube:
adding test around create youtube object from a url. Added a test file for testing on python3
fixed issue #88. Cause because of str and bytes difference in python3

Files changed (3) hide show
  1. pytube/api.py +1 -1
  2. tests/test_p3_pytube.py +18 -0
  3. tests/test_pytube.py +6 -0
pytube/api.py CHANGED
@@ -363,7 +363,7 @@ class YouTube(object):
363
  response = urlopen(url)
364
  if not response:
365
  raise PytubeError("Unable to open url: {0}".format(self.url))
366
- self._js_cache = response.read()
367
  try:
368
  matches = reg_exp.search(self._js_cache)
369
  if matches:
 
363
  response = urlopen(url)
364
  if not response:
365
  raise PytubeError("Unable to open url: {0}".format(self.url))
366
+ self._js_cache = response.read().decode()
367
  try:
368
  matches = reg_exp.search(self._js_cache)
369
  if matches:
tests/test_p3_pytube.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ from __future__ import unicode_literals
4
+ import warnings
5
+ import mock
6
+ from nose.tools import eq_, raises
7
+ from pytube import api
8
+ from pytube.exceptions import MultipleObjectsReturned, AgeRestricted, \
9
+ DoesNotExist, PytubeError
10
+
11
+
12
+ class TestPytube(object):
13
+ def setUp(self):
14
+ self.url = 'http://www.youtube.com/watch?v=9bZkp7q19f0'
15
+
16
+ def test_YT_create_from_url(self):
17
+ 'test creation of YouYube Object from url'
18
+ yt = api.YouTube(self.url)
tests/test_pytube.py CHANGED
@@ -132,3 +132,9 @@ class TestPytube(object):
132
  def test_get_json_offset_with_bad_html(self):
133
  """Raise exception if json offset cannot be found"""
134
  self.yt._get_json_offset('asdfasdf')
 
 
 
 
 
 
 
132
  def test_get_json_offset_with_bad_html(self):
133
  """Raise exception if json offset cannot be found"""
134
  self.yt._get_json_offset('asdfasdf')
135
+
136
+ def test_YT_create_from_url(self):
137
+ 'test creation of YouYube Object from url'
138
+ url = 'http://www.youtube.com/watch?v=9bZkp7q19f0'
139
+
140
+ yt = api.YouTube(url)