Skip to content

Commit

Permalink
Add Python function for testing YTDL url support
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Oct 12, 2021
1 parent 065c49d commit b4d617e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 64 deletions.
33 changes: 1 addition & 32 deletions sailfish/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
9 changes: 9 additions & 0 deletions sailfish/qml/ytdl_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 1 addition & 32 deletions ubuntu-touch/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit b4d617e

Please sign in to comment.