Browse Source

Replace tumblr videos with HD versions

Alternative approach might be extracting replacement URL from "hdUrl"
field of custom property "data-crt-options", but stripping last segment
of video URL is way easier and seems equally robust.
Self-Perfection 5 years ago
parent
commit
1cb3084d53
1 changed files with 14 additions and 1 deletions
  1. 14 1
      plugins/af_tumblr_1280/init.php

+ 14 - 1
plugins/af_tumblr_1280/init.php

@@ -4,7 +4,7 @@ class Af_Tumblr_1280 extends Plugin {
 
 	function about() {
 		return array(1.0,
-			"Replace Tumblr pictures with largest size if available (requires CURL)",
+			"Replace Tumblr pictures and videos with largest size if available (requires CURL)",
 			"fox");
 	}
 
@@ -64,6 +64,19 @@ class Af_Tumblr_1280 extends Plugin {
 				}
 			}
 
+			$video_sources = $xpath->query('//video/source[contains(@src, \'.tumblr.com/video_file\')]');
+
+			foreach ($video_sources as $source) {
+				$src = $source->getAttribute("src");
+
+				$new_src = preg_replace("/\/\d{3}$/", "", $src);
+
+				if ($src != $new_src) {
+					$source->setAttribute("src", $new_src);
+					$found = true;
+				}
+			}
+
 			if ($found) {
 				$doc->removeChild($doc->firstChild); //remove doctype
 				$article["content"] = $doc->saveHTML();