Pārlūkot izejas kodu

Updated plugin to enhance privacy with video embeds.

This plugin is a conceptual replication of the Electronic Frontier
Foundation's MyTube plugin, which pre-caches thumbnails of embedded
YouTube videos so that users are not tracked by Google until they
explicitly "opt-in" by clicking on the thumbnail (at which point the
thumbnail is replaced by the video embed iframe).

The plugin now supports both YouTube and Vimeo, and is now easier to extend for other video services.
Jacob Levernier 9 gadi atpakaļ
vecāks
revīzija
642062d4ca

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 26 - 4
video_privacy_enhancer/Readme.md


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 128 - 86
video_privacy_enhancer/video_privacy_enhancer.py


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 24 - 4
video_privacy_enhancer/video_privacy_enhancer_jquery.js


+ 32 - 0
video_privacy_enhancer/video_service_thumbnail_url_generating_functions.py

@@ -0,0 +1,32 @@
+"""A function for each service to download the video thumbnail
+
+Each function should accept one argument (the video id from that service) and should return the download URL for the video's thumbnail.
+
+"""
+
+"""
+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.
+
+import json
+
+"""
+END OF LIBRARIES
+"""
+
+def generate_thumbnail_download_link_youtube(video_id_from_shortcode):
+	"""Thumbnail URL generator for YouTube videos."""
+	
+	thumbnail_download_link="https://img.youtube.com/vi/" + video_id_from_shortcode + "/0.jpg"
+	return thumbnail_download_link
+
+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. To do this, we'll use the requests module both to get and parse the JSON for this task.
+	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_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