Skip to content

Commit

Permalink
Added functionality for downloading videos
Browse files Browse the repository at this point in the history
This doesn't download the videos through any
Cordova libraries or OS level operations, but it
will open the link in a web browser. With that
link, you can download the file through your
default web browser if you really are jones-in
 for that file. This fix is related to #6
  • Loading branch information
MarmadileManteater committed Aug 14, 2022
1 parent ab03be0 commit e5a02ca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions _scripts/cordova-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const archiver = require('archiver');
rendererContent = rendererContent.replace(/const store (= localforage.createInstance)/g, 'const store = window.dataStore $1')
rendererContent = rendererContent.replace(/{openExternalLink\({rootState:t},e\){/g, "{openExternalLink:window.openExternalLink,electronOpenExternalLink({rootState:t},e){")
rendererContent = rendererContent.replace(/navigator.clipboard.writeText\(/g, "window.copyToClipboard\(")
rendererContent = rendererContent.replace(/,async downloadMedia\({rootState:t,dispatch:e},{url:i,title:s,extension:n,fallingBackPath:a}\){/g,", downloadMedia(state, mediaFormat) { window.downloadExternalLink(state, mediaFormat.url); return new Promise(function (resolve, reject) { resolve() }) }, async oldDownloadMedia({rootState:t,dispatch:e},{url:i,title:s,extension:n,fallingBackPath:a}){")
if (exportType === 'cordova') {
rendererContent = rendererContent.replace(/this.invidiousGetVideoInformation\(this.videoId\).then\(/g, 'this.invidiousGetVideoInformation(this.videoId).then(updatePlayingVideo);this.invidiousGetVideoInformation\(this.videoId\).then(')
rendererContent = rendererContent.replace('systemTheme:function(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}', 'systemTheme:function () { return window.isDarkMode }')
Expand Down Expand Up @@ -557,6 +558,13 @@ const archiver = require('archiver');
a.setAttribute("target", "_blank");
a.click();
};
window.downloadExternalLink = function ({ rootState }, link) {
var a = document.createElement("a");
a.setAttribute("href", link);
a.setAttribute("target", "_blank");
a.download = 'download';
a.click();
}
` + ((exportType === 'cordova')
? `
window.copyToClipboard = function (content) {
Expand Down

0 comments on commit e5a02ca

Please sign in to comment.