From b4d617e5edc29f6646557d949c88524e1aa908f5 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Tue, 12 Oct 2021 09:11:49 +0200 Subject: [PATCH] Add Python function for testing YTDL url support --- sailfish/qml/main.qml | 33 +-------------------------------- sailfish/qml/ytdl_wrapper.py | 9 +++++++++ ubuntu-touch/main.qml | 33 +-------------------------------- 3 files changed, 11 insertions(+), 64 deletions(-) diff --git a/sailfish/qml/main.qml b/sailfish/qml/main.qml index e4ff87f..36b57bd 100644 --- a/sailfish/qml/main.qml +++ b/sailfish/qml/main.qml @@ -65,39 +65,8 @@ ApplicationWindow { } function isUrlSupported(url) { - // TODO: now simply matches url against our own simple list. We should query YTDL itself. //console.log("testing ytdl support for url " + url) - if (/^https?:\/\/((www|m)\.)?youtube\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((www|m)\.)?youtu\.be\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((www)\.)?streamable\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((www)\.)?livestream\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/my\.mixtape\.moe\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(.+\.)?twitch.tv\/.+/.test(url)) { - return true; -// } else if (/^https?:\/\/((www)\.)?vimeo.com\/.+/.test(url)) { -// return true; - } else if (/^https?:\/\/(www\.)?gfycat\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((i|m)\.)?imgur\.com\/.+\.gifv$/.test(url)) { - return true; - } else if (/^https?:\/\/v\.redd\.it\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?pornhub\.com\/view_video\.php.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?hooktube\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?dailymotion\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?bitchute\.com\/.+/.test(url)) { - return true; - } else { - return false; - } + return call_sync('ytdl_wrapper.isVideoUrlSupported', [url.toString()] ) } onError: { diff --git a/sailfish/qml/ytdl_wrapper.py b/sailfish/qml/ytdl_wrapper.py index 6798452..bbb5837 100644 --- a/sailfish/qml/ytdl_wrapper.py +++ b/sailfish/qml/ytdl_wrapper.py @@ -39,6 +39,15 @@ def retrieveVideoInfo(url): except youtube_dl.utils.DownloadError as e: pyotherside.send('fail', ','.join(e.args)) +def isVideoUrlSupported(url): + for ie in youtube_dl.list_extractors(false): + if ie.suitable(url): + if not ie.working(): + logger.debug('extractor ' + ie + " currently broken") + continue + return True + return False + def downloadVideo(url): logger.debug('downloadVideo ' + str(url)) # not implemented yet diff --git a/ubuntu-touch/main.qml b/ubuntu-touch/main.qml index fd53063..ed32132 100644 --- a/ubuntu-touch/main.qml +++ b/ubuntu-touch/main.qml @@ -525,39 +525,8 @@ ApplicationWindow { } function isUrlSupported(url) { - // TODO: now simply matches url against our own simple list. We should query YTDL itself. //console.log("testing ytdl support for url " + url) - if (/^https?:\/\/((www|m)\.)?youtube\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((www|m)\.)?youtu\.be\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((www)\.)?streamable\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((www)\.)?livestream\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/my\.mixtape\.moe\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(.+\.)?twitch.tv\/.+/.test(url)) { - return true; - // } else if (/^https?:\/\/((www)\.)?vimeo.com\/.+/.test(url)) { - // return true; - } else if (/^https?:\/\/(www\.)?gfycat\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/((i|m)\.)?imgur\.com\/.+\.gifv$/.test(url)) { - return true; - } else if (/^https?:\/\/v\.redd\.it\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?pornhub\.com\/view_video\.php.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?hooktube\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?dailymotion\.com\/.+/.test(url)) { - return true; - } else if (/^https?:\/\/(www\.)?bitchute\.com\/.+/.test(url)) { - return true; - } else { - return false; - } + return call_sync('ytdl_wrapper.isVideoUrlSupported', [url.toString()] ) } onError: {