Browse Source

Add support for Python 2 and 3 for Video Privacy Enhancer.

This PR also fixes an error that displays when debugging is turned on,
caused by the video privacy enhancer attempting to output a dictionary
in the debugging text.
Jacob Levernier 7 years ago
parent
commit
54d0701b67

File diff suppressed because it is too large
+ 8 - 14
video_privacy_enhancer/video_privacy_enhancer.py


+ 4 - 3
video_privacy_enhancer/video_service_thumbnail_url_generating_functions.py

@@ -8,7 +8,8 @@ Each function should accept one argument (the video id from that service) and sh
 LIBRARIES
 """
 
-import urllib # For downloading the video thumbnails. Not as clean as, e.g., the requests module, but installed by default in many Python distributions.
+# from urllib.request import urlopen # For downloading the video thumbnails. Not as clean as, e.g., the requests module, but installed by default in many Python distributions.
+from six.moves.urllib.request import urlopen
 
 import json
 
@@ -26,7 +27,7 @@ def generate_thumbnail_download_link_vimeo(video_id_from_shortcode):
 	"""Thumbnail URL generator for Vimeo videos."""
 	
 	# Following the Vimeo API at https://developer.vimeo.com/api#video-request, we need to request the video's metadata and get the thumbnail from that. First, then, we'll get the metadata in JSON format, and then will parse it to find the thumbnail URL.
-	video_metadata = urllib.urlopen("https://vimeo.com/api/v2/video/" + video_id_from_shortcode + ".json") # Download the video's metadata in JSON format.
-	video_metadata_parsed = json.load(video_metadata) # Parse the JSON
+	video_metadata = urlopen("https://vimeo.com/api/v2/video/" + str(video_id_from_shortcode) + ".json").read() # Download the video's metadata in JSON format.
+	video_metadata_parsed = json.loads(video_metadata.decode('utf-8')) # Parse the JSON
 	video_thumbnail_large_location = video_metadata_parsed[0]['thumbnail_large'] # Go into the JSON and get the URL of the thumbnail.
 	return video_thumbnail_large_location