mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-22 17:34:06 +02:00
Make video player open tweet URL instead of video URL if playback fails
This commit is contained in:
parent
a369c65451
commit
af5da76f72
Core
Resources/Scripts
@ -100,8 +100,8 @@ public void ScreenshotTweet(string html, int width){
|
|||||||
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width));
|
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayVideo(string url, string username){
|
public void PlayVideo(string videoUrl, string tweetUrl, string username){
|
||||||
form.InvokeAsyncSafe(() => form.PlayVideo(url, username));
|
form.InvokeAsyncSafe(() => form.PlayVideo(videoUrl, tweetUrl, username));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixClipboard(){
|
public void FixClipboard(){
|
||||||
|
@ -508,8 +508,8 @@ public void OnTweetSound(){
|
|||||||
AnalyticsFile.SoundNotifications.Trigger();
|
AnalyticsFile.SoundNotifications.Trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayVideo(string url, string username){
|
public void PlayVideo(string videoUrl, string tweetUrl, string username){
|
||||||
if (string.IsNullOrEmpty(url)){
|
if (string.IsNullOrEmpty(videoUrl)){
|
||||||
videoPlayer?.Close();
|
videoPlayer?.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -521,8 +521,8 @@ public void PlayVideo(string url, string username){
|
|||||||
browser.HideVideoOverlay(true);
|
browser.HideVideoOverlay(true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
videoPlayer.Launch(url, username);
|
videoPlayer.Launch(videoUrl, tweetUrl, username);
|
||||||
AnalyticsFile.VideoPlays.Trigger();
|
AnalyticsFile.VideoPlays.Trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public VideoPlayer(FormBrowser owner){
|
|||||||
this.owner.FormClosing += owner_FormClosing;
|
this.owner.FormClosing += owner_FormClosing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Launch(string url, string username){
|
public void Launch(string videoUrl, string tweetUrl, string username){
|
||||||
if (Running){
|
if (Running){
|
||||||
Destroy();
|
Destroy();
|
||||||
isClosing = false;
|
isClosing = false;
|
||||||
@ -40,11 +40,11 @@ public void Launch(string url, string username){
|
|||||||
|
|
||||||
if ((process = Process.Start(new ProcessStartInfo{
|
if ((process = Process.Start(new ProcessStartInfo{
|
||||||
FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"),
|
FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"),
|
||||||
Arguments = $"{owner.Handle} {(int)Math.Floor(100F * owner.GetDPIScale())} {Config.VideoPlayerVolume} \"{url}\" \"{pipe.GenerateToken()}\"",
|
Arguments = $"{owner.Handle} {(int)Math.Floor(100F * owner.GetDPIScale())} {Config.VideoPlayerVolume} \"{videoUrl}\" \"{pipe.GenerateToken()}\"",
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = true
|
RedirectStandardOutput = true
|
||||||
})) != null){
|
})) != null){
|
||||||
currentInstance = new Instance(process, pipe, url, username);
|
currentInstance = new Instance(process, pipe, videoUrl, tweetUrl, username);
|
||||||
|
|
||||||
process.EnableRaisingEvents = true;
|
process.EnableRaisingEvents = true;
|
||||||
process.Exited += process_Exited;
|
process.Exited += process_Exited;
|
||||||
@ -81,7 +81,7 @@ private void pipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e){
|
|||||||
case "download":
|
case "download":
|
||||||
if (currentInstance != null){
|
if (currentInstance != null){
|
||||||
owner.AnalyticsFile.DownloadedVideos.Trigger();
|
owner.AnalyticsFile.DownloadedVideos.Trigger();
|
||||||
TwitterUtils.DownloadVideo(currentInstance.Url, currentInstance.Username);
|
TwitterUtils.DownloadVideo(currentInstance.VideoUrl, currentInstance.Username);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -145,7 +145,7 @@ private void process_Exited(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int exitCode = currentInstance.Process.ExitCode;
|
int exitCode = currentInstance.Process.ExitCode;
|
||||||
string url = currentInstance.Url;
|
string tweetUrl = currentInstance.TweetUrl;
|
||||||
|
|
||||||
currentInstance.Dispose();
|
currentInstance.Dispose();
|
||||||
currentInstance = null;
|
currentInstance = null;
|
||||||
@ -153,14 +153,14 @@ private void process_Exited(object sender, EventArgs e){
|
|||||||
switch(exitCode){
|
switch(exitCode){
|
||||||
case 3: // CODE_LAUNCH_FAIL
|
case 3: // CODE_LAUNCH_FAIL
|
||||||
if (FormMessage.Error("Video Playback Error", "Error launching video player, this may be caused by missing Windows Media Player. Do you want to open the video in your browser?", FormMessage.Yes, FormMessage.No)){
|
if (FormMessage.Error("Video Playback Error", "Error launching video player, this may be caused by missing Windows Media Player. Do you want to open the video in your browser?", FormMessage.Yes, FormMessage.No)){
|
||||||
BrowserUtils.OpenExternalBrowser(url);
|
BrowserUtils.OpenExternalBrowser(tweetUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: // CODE_MEDIA_ERROR
|
case 4: // CODE_MEDIA_ERROR
|
||||||
if (FormMessage.Error("Video Playback Error", "The video could not be loaded, most likely due to unknown format. Do you want to open the video in your browser?", FormMessage.Yes, FormMessage.No)){
|
if (FormMessage.Error("Video Playback Error", "The video could not be loaded, most likely due to unknown format. Do you want to open the video in your browser?", FormMessage.Yes, FormMessage.No)){
|
||||||
BrowserUtils.OpenExternalBrowser(url);
|
BrowserUtils.OpenExternalBrowser(tweetUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -184,13 +184,15 @@ public bool Running{
|
|||||||
public Process Process { get; }
|
public Process Process { get; }
|
||||||
public DuplexPipe.Server Pipe { get; }
|
public DuplexPipe.Server Pipe { get; }
|
||||||
|
|
||||||
public string Url { get; }
|
public string VideoUrl { get; }
|
||||||
|
public string TweetUrl { get; }
|
||||||
public string Username { get; }
|
public string Username { get; }
|
||||||
|
|
||||||
public Instance(Process process, DuplexPipe.Server pipe, string url, string username){
|
public Instance(Process process, DuplexPipe.Server pipe, string videoUrl, string tweetUrl, string username){
|
||||||
this.Process = process;
|
this.Process = process;
|
||||||
this.Pipe = pipe;
|
this.Pipe = pipe;
|
||||||
this.Url = url;
|
this.VideoUrl = videoUrl;
|
||||||
|
this.TweetUrl = tweetUrl;
|
||||||
this.Username = username;
|
this.Username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1212,14 +1212,14 @@
|
|||||||
// Block: Setup video player hooks.
|
// Block: Setup video player hooks.
|
||||||
//
|
//
|
||||||
execSafe(function setupVideoPlayer(){
|
execSafe(function setupVideoPlayer(){
|
||||||
window.TDGF_playVideo = function(url, username){
|
window.TDGF_playVideo = function(videoUrl, tweetUrl, username){
|
||||||
return if !url;
|
return if !videoUrl;
|
||||||
|
|
||||||
$('<div id="td-video-player-overlay" class="ovl" style="display:block"></div>').on("click contextmenu", function(){
|
$('<div id="td-video-player-overlay" class="ovl" style="display:block"></div>').on("click contextmenu", function(){
|
||||||
$TD.playVideo(null, null);
|
$TD.playVideo(null, null, null);
|
||||||
}).appendTo(app);
|
}).appendTo(app);
|
||||||
|
|
||||||
$TD.playVideo(url, username || null);
|
$TD.playVideo(videoUrl, tweetUrl || videoUrl, username || null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGifLink = function(ele){
|
const getGifLink = function(ele){
|
||||||
@ -1239,13 +1239,14 @@
|
|||||||
app.delegate(".js-gif-play", {
|
app.delegate(".js-gif-play", {
|
||||||
click: function(e){
|
click: function(e){
|
||||||
let src = !e.ctrlKey && getGifLink($(this).closest(".js-media-gif-container").find("video"));
|
let src = !e.ctrlKey && getGifLink($(this).closest(".js-media-gif-container").find("video"));
|
||||||
|
let tweet = getVideoTweetLink($(this));
|
||||||
|
|
||||||
if (src){
|
if (src){
|
||||||
let hovered = getHoveredTweet();
|
let hovered = getHoveredTweet();
|
||||||
window.TDGF_playVideo(src, getUsername(hovered && hovered.obj));
|
window.TDGF_playVideo(src, tweet, getUsername(hovered && hovered.obj));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$TD.openBrowser(getVideoTweetLink($(this)));
|
$TD.openBrowser(tweet);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@ -1279,7 +1280,7 @@
|
|||||||
let media = this.chirp.getMedia().find(media => media.mediaId === this.clickedMediaEntityId);
|
let media = this.chirp.getMedia().find(media => media.mediaId === this.clickedMediaEntityId);
|
||||||
|
|
||||||
if (media && media.isVideo && media.service === "twitter"){
|
if (media && media.isVideo && media.service === "twitter"){
|
||||||
window.TDGF_playVideo(media.chooseVideoVariant().url, getUsername(this.chirp));
|
window.TDGF_playVideo(media.chooseVideoVariant().url, this.chirp.getChirpURL(), getUsername(this.chirp));
|
||||||
cancelModal = true;
|
cancelModal = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -120,10 +120,18 @@
|
|||||||
// Block: Setup bridges to global functions.
|
// Block: Setup bridges to global functions.
|
||||||
//
|
//
|
||||||
window.TDPF_getColumnName = window.TDGF_getColumnName;
|
window.TDPF_getColumnName = window.TDGF_getColumnName;
|
||||||
window.TDPF_playVideo = window.TDGF_playVideo;
|
|
||||||
window.TDPF_reloadColumns = window.TDGF_reloadColumns;
|
window.TDPF_reloadColumns = window.TDGF_reloadColumns;
|
||||||
window.TDPF_prioritizeNewestEvent = window.TDGF_prioritizeNewestEvent;
|
window.TDPF_prioritizeNewestEvent = window.TDGF_prioritizeNewestEvent;
|
||||||
window.TDPF_injectMustache = window.TDGF_injectMustache;
|
window.TDPF_injectMustache = window.TDGF_injectMustache;
|
||||||
|
|
||||||
|
window.TDPF_playVideo = function(urlOrObject, username){
|
||||||
|
if (typeof urlOrObject === "string"){
|
||||||
|
window.TDGF_playVideo(urlOrObject, null, username);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
window.TDGF_playVideo(urlOrObject.videoUrl, urlOrObject.tweetUrl, urlOrObject.username);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#import "scripts/plugins.base.js"
|
#import "scripts/plugins.base.js"
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user