[vlc-devel] [PATCH 3/4] ytdl: extract playlist non-recursively ("flat")

RĂ©mi Denis-Courmont remi at remlab.net
Mon Sep 21 18:02:22 CEST 2020


This uses the extract-flat mode of YoutubeDL, which skips parsing
individual items within a playlist. We define a dedicated MRL scheme
to track a YoutubeDL playlist item, and parse it only when the item is
actually opened.

This has two benefits:
1) Extracting a playlist is dramatically faster.
2) Expiring media URL can be played even if the playlist is long.

This does *not* solve the remaining problem that expiring URLs cannot
be saved and replayed later.
---
 modules/access/ytdl.c |  2 +-
 share/ytdl-extract.py | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/modules/access/ytdl.c b/modules/access/ytdl.c
index 4a47f4491e..6b4fa8b93d 100644
--- a/modules/access/ytdl.c
+++ b/modules/access/ytdl.c
@@ -193,7 +193,7 @@ vlc_module_begin()
     set_category(CAT_INPUT)
     set_subcategory(SUBCAT_INPUT_STREAM_FILTER)
     set_capability("access", 10)
-    add_shortcut("http", "https")
+    add_shortcut("http", "https", "ytdl")
     set_callbacks(Open, Close)
     add_bool("ytdl", true, N_("Enable YT-DL"), N_("Enable YT-DL"), true)
         change_safe()
diff --git a/share/ytdl-extract.py b/share/ytdl-extract.py
index 71c79e0156..4e7ea09aa6 100755
--- a/share/ytdl-extract.py
+++ b/share/ytdl-extract.py
@@ -17,6 +17,7 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 
 import sys
+import urllib.parse
 import youtube_dl
 
 class logger(object):
@@ -68,6 +69,11 @@ def entry_extract(entry):
     if 'title' in entry:
         print('#EXTINF:,,' + entry['title'].splitlines()[0])
 
+    if 'ie_key' in fmt:
+        # Flat-extracted playlist entry
+        print('ytdl:///?' + urllib.parse.urlencode(fmt))
+        return
+
     if 'url' in fmt:
         print('#EXTVLCOPT:no-ytdl') # don't parse recursively
         print(fmt['url'])
@@ -76,6 +82,7 @@ def entry_extract(entry):
 
 def url_extract(url):
     opts = {
+        'extract_flat': True,
         'logger': logger(),
     }
 
@@ -98,5 +105,27 @@ def url_extract(url):
         # URL is a single media
         entry_extract(infos)
 
+def url_process(ie_url):
+    opts = {
+        'logger': logger(),
+    }
+
+    dl = youtube_dl.YoutubeDL(opts)
+
+    # Rebuild the original IE entry
+    entry = { }
+
+    for p in urllib.parse.parse_qsl(url[9:]):
+        entry[p[0]] = p[1]
+
+    entry = dl.process_ie_result(entry, download=False)
+    print('#EXTM3U')
+    entry_extract(entry)
+
+url = sys.argv[1]
+
+if url.startswith('ytdl:///?'):
+    url_process(url)
+else:
+    url_extract(url)
 
-url_extract(sys.argv[1])
-- 
2.28.0



More information about the vlc-devel mailing list