mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-09 06:15:49 +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));
|
||||
}
|
||||
|
||||
public void PlayVideo(string url, string username){
|
||||
form.InvokeAsyncSafe(() => form.PlayVideo(url, username));
|
||||
public void PlayVideo(string videoUrl, string tweetUrl, string username){
|
||||
form.InvokeAsyncSafe(() => form.PlayVideo(videoUrl, tweetUrl, username));
|
||||
}
|
||||
|
||||
public void FixClipboard(){
|
||||
|
@ -508,8 +508,8 @@ public void OnTweetSound(){
|
||||
AnalyticsFile.SoundNotifications.Trigger();
|
||||
}
|
||||
|
||||
public void PlayVideo(string url, string username){
|
||||
if (string.IsNullOrEmpty(url)){
|
||||
public void PlayVideo(string videoUrl, string tweetUrl, string username){
|
||||
if (string.IsNullOrEmpty(videoUrl)){
|
||||
videoPlayer?.Close();
|
||||
return;
|
||||
}
|
||||
@ -521,8 +521,8 @@ public void PlayVideo(string url, string username){
|
||||
browser.HideVideoOverlay(true);
|
||||
};
|
||||
}
|
||||
|
||||
videoPlayer.Launch(url, username);
|
||||
|
||||
videoPlayer.Launch(videoUrl, tweetUrl, username);
|
||||
AnalyticsFile.VideoPlays.Trigger();
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public VideoPlayer(FormBrowser owner){
|
||||
this.owner.FormClosing += owner_FormClosing;
|
||||
}
|
||||
|
||||
public void Launch(string url, string username){
|
||||
public void Launch(string videoUrl, string tweetUrl, string username){
|
||||
if (Running){
|
||||
Destroy();
|
||||
isClosing = false;
|
||||
@ -40,11 +40,11 @@ public void Launch(string url, string username){
|
||||
|
||||
if ((process = Process.Start(new ProcessStartInfo{
|
||||
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,
|
||||
RedirectStandardOutput = true
|
||||
})) != null){
|
||||
currentInstance = new Instance(process, pipe, url, username);
|
||||
currentInstance = new Instance(process, pipe, videoUrl, tweetUrl, username);
|
||||
|
||||
process.EnableRaisingEvents = true;
|
||||
process.Exited += process_Exited;
|
||||
@ -81,7 +81,7 @@ private void pipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e){
|
||||
case "download":
|
||||
if (currentInstance != null){
|
||||
owner.AnalyticsFile.DownloadedVideos.Trigger();
|
||||
TwitterUtils.DownloadVideo(currentInstance.Url, currentInstance.Username);
|
||||
TwitterUtils.DownloadVideo(currentInstance.VideoUrl, currentInstance.Username);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -145,7 +145,7 @@ private void process_Exited(object sender, EventArgs e){
|
||||
}
|
||||
|
||||
int exitCode = currentInstance.Process.ExitCode;
|
||||
string url = currentInstance.Url;
|
||||
string tweetUrl = currentInstance.TweetUrl;
|
||||
|
||||
currentInstance.Dispose();
|
||||
currentInstance = null;
|
||||
@ -153,14 +153,14 @@ private void process_Exited(object sender, EventArgs e){
|
||||
switch(exitCode){
|
||||
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)){
|
||||
BrowserUtils.OpenExternalBrowser(url);
|
||||
BrowserUtils.OpenExternalBrowser(tweetUrl);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
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)){
|
||||
BrowserUtils.OpenExternalBrowser(url);
|
||||
BrowserUtils.OpenExternalBrowser(tweetUrl);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -184,13 +184,15 @@ public bool Running{
|
||||
public Process Process { get; }
|
||||
public DuplexPipe.Server Pipe { get; }
|
||||
|
||||
public string Url { get; }
|
||||
public string VideoUrl { get; }
|
||||
public string TweetUrl { 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.Pipe = pipe;
|
||||
this.Url = url;
|
||||
this.VideoUrl = videoUrl;
|
||||
this.TweetUrl = tweetUrl;
|
||||
this.Username = username;
|
||||
}
|
||||
|
||||
|
@ -1212,14 +1212,14 @@
|
||||
// Block: Setup video player hooks.
|
||||
//
|
||||
execSafe(function setupVideoPlayer(){
|
||||
window.TDGF_playVideo = function(url, username){
|
||||
return if !url;
|
||||
window.TDGF_playVideo = function(videoUrl, tweetUrl, username){
|
||||
return if !videoUrl;
|
||||
|
||||
$('<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);
|
||||
|
||||
$TD.playVideo(url, username || null);
|
||||
$TD.playVideo(videoUrl, tweetUrl || videoUrl, username || null);
|
||||
};
|
||||
|
||||
const getGifLink = function(ele){
|
||||
@ -1239,13 +1239,14 @@
|
||||
app.delegate(".js-gif-play", {
|
||||
click: function(e){
|
||||
let src = !e.ctrlKey && getGifLink($(this).closest(".js-media-gif-container").find("video"));
|
||||
let tweet = getVideoTweetLink($(this));
|
||||
|
||||
if (src){
|
||||
let hovered = getHoveredTweet();
|
||||
window.TDGF_playVideo(src, getUsername(hovered && hovered.obj));
|
||||
window.TDGF_playVideo(src, tweet, getUsername(hovered && hovered.obj));
|
||||
}
|
||||
else{
|
||||
$TD.openBrowser(getVideoTweetLink($(this)));
|
||||
$TD.openBrowser(tweet);
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
@ -1279,7 +1280,7 @@
|
||||
let media = this.chirp.getMedia().find(media => media.mediaId === this.clickedMediaEntityId);
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
@ -120,10 +120,18 @@
|
||||
// Block: Setup bridges to global functions.
|
||||
//
|
||||
window.TDPF_getColumnName = window.TDGF_getColumnName;
|
||||
window.TDPF_playVideo = window.TDGF_playVideo;
|
||||
window.TDPF_reloadColumns = window.TDGF_reloadColumns;
|
||||
window.TDPF_prioritizeNewestEvent = window.TDGF_prioritizeNewestEvent;
|
||||
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"
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user