From b08df3fbe9d1727b18ab88b998bc8bea98c2a9fc Mon Sep 17 00:00:00 2001
From: Floris Lambrechts <florisla@gmail.com>
Date: Tue, 31 Oct 2017 17:00:18 +0100
Subject: [PATCH] Support Google Drive URLs of the form /file/d/[id]/[whatever]

This is the URL structure I encounter when I query google.com
for videos with inurl:drive.google.com.
The 'whatever' part is usually 'edit', 'view' or 'preview'.
---
 .../video_embed_field/Provider/GoogleDrive.php     | 25 ++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/Plugin/video_embed_field/Provider/GoogleDrive.php b/src/Plugin/video_embed_field/Provider/GoogleDrive.php
index 0c537ae..0f6cc02 100644
--- a/src/Plugin/video_embed_field/Provider/GoogleDrive.php
+++ b/src/Plugin/video_embed_field/Provider/GoogleDrive.php
@@ -49,13 +49,26 @@ class GoogleDrive extends ProviderPluginBase {
    * {@inheritdoc}
    */
   public static function getIdFromInput($input) {
-    if (strpos($input, 'drive.google.com') !== FALSE) {
-      // e.g. https://drive.google.com/open?id=0B8e8g71GefzHQmdmMnBCZDZsUkE,
-      // not working for other url structures atm.
-      $parts = parse_url($input);
-      parse_str($parts['query'], $query);
-      return isset($query['id']) ? $query['id'] : FALSE;
+    $parts = parse_url($input);
+
+    if ('drive.google.com' != $parts['host']) {
+        return FALSE;
+    }
+
+    if ($parts['path'] == '/open' && isset($parts['query'])) {
+        parse_str($parts['query'], $query);
+        if (!isset($query['id'])) {
+            return FALSE;
+        }
+        return $query['id'];
     }
+
+    if ("/file/d/" == substr($parts['path'], 0, 8)) {
+        $id = substr($parts['path'], 8);
+        $id = substr($id, 0, strpos($id, '/'));
+        return $id;
+    }
+
     return FALSE;
   }

--
1.9.1
