]> git.wh0rd.org - tt-rss.git/commitdiff
Replace tumblr videos with HD versions
authorSelf-Perfection <alexander.s.m+git@gmail.com>
Sat, 14 Jul 2018 13:29:39 +0000 (16:29 +0300)
committerSelf-Perfection <alexander.s.m+git@gmail.com>
Sat, 14 Jul 2018 16:16:40 +0000 (19:16 +0300)
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.

plugins/af_tumblr_1280/init.php

index d74253b57636d9c1c9b85ed35fee0e7bb545ad1e..8aba0e65239e2618e839931e430b6efd46305159 100755 (executable)
@@ -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();