mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-28 18:15:47 +02:00
Add username to default video download filename & tweak playback error message
This commit is contained in:
parent
110d41e393
commit
d663cc3f64
@ -117,8 +117,8 @@ public void ScreenshotTweet(string html, int width, int height){
|
|||||||
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width, height));
|
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayVideo(string url){
|
public void PlayVideo(string url, string username){
|
||||||
form.InvokeAsyncSafe(() => form.PlayVideo(url));
|
form.InvokeAsyncSafe(() => form.PlayVideo(url, username));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixClipboard(){
|
public void FixClipboard(){
|
||||||
|
@ -541,7 +541,7 @@ public void PlayNotificationSound(){
|
|||||||
soundNotification.Play(Config.NotificationSoundPath);
|
soundNotification.Play(Config.NotificationSoundPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayVideo(string url){
|
public void PlayVideo(string url, string username){
|
||||||
if (string.IsNullOrEmpty(url)){
|
if (string.IsNullOrEmpty(url)){
|
||||||
videoPlayer?.Close();
|
videoPlayer?.Close();
|
||||||
return;
|
return;
|
||||||
@ -556,7 +556,7 @@ public void PlayVideo(string url){
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
videoPlayer.Launch(url);
|
videoPlayer.Launch(url, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideVideoOverlay(){
|
public void HideVideoOverlay(){
|
||||||
|
@ -116,7 +116,7 @@ public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser br
|
|||||||
|
|
||||||
case MenuSaveMedia:
|
case MenuSaveMedia:
|
||||||
if (IsVideo){
|
if (IsVideo){
|
||||||
TwitterUtils.DownloadVideo(GetMediaLink(parameters));
|
TwitterUtils.DownloadVideo(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
|
TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
|
||||||
|
@ -25,6 +25,7 @@ public bool Running{
|
|||||||
|
|
||||||
private readonly Form owner;
|
private readonly Form owner;
|
||||||
private string lastUrl;
|
private string lastUrl;
|
||||||
|
private string lastUsername;
|
||||||
|
|
||||||
private Process currentProcess;
|
private Process currentProcess;
|
||||||
private DuplexPipe.Server currentPipe;
|
private DuplexPipe.Server currentPipe;
|
||||||
@ -35,13 +36,14 @@ public VideoPlayer(Form owner){
|
|||||||
this.owner.FormClosing += owner_FormClosing;
|
this.owner.FormClosing += owner_FormClosing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Launch(string url){
|
public void Launch(string url, string username){
|
||||||
if (Running){
|
if (Running){
|
||||||
Destroy();
|
Destroy();
|
||||||
isClosing = false;
|
isClosing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastUrl = url;
|
lastUrl = url;
|
||||||
|
lastUsername = username;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
currentPipe = DuplexPipe.CreateServer();
|
currentPipe = DuplexPipe.CreateServer();
|
||||||
@ -84,7 +86,7 @@ private void currentPipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "download":
|
case "download":
|
||||||
TwitterUtils.DownloadVideo(lastUrl);
|
TwitterUtils.DownloadVideo(lastUrl, lastUsername);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "rip":
|
case "rip":
|
||||||
@ -157,14 +159,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 a 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(lastUrl);
|
BrowserUtils.OpenExternalBrowser(lastUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 a 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(lastUrl);
|
BrowserUtils.OpenExternalBrowser(lastUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ void OnFailure(Exception ex){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DownloadVideo(string url){
|
public static void DownloadVideo(string url, string username){
|
||||||
string filename = BrowserUtils.GetFileNameFromUrl(url);
|
string filename = BrowserUtils.GetFileNameFromUrl(url);
|
||||||
string ext = Path.GetExtension(filename);
|
string ext = Path.GetExtension(filename);
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ public static void DownloadVideo(string url){
|
|||||||
AutoUpgradeEnabled = true,
|
AutoUpgradeEnabled = true,
|
||||||
OverwritePrompt = true,
|
OverwritePrompt = true,
|
||||||
Title = "Save video",
|
Title = "Save video",
|
||||||
FileName = filename,
|
FileName = string.IsNullOrEmpty(username) ? filename : $"{username} {filename}",
|
||||||
Filter = "Video"+(string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}")
|
Filter = "Video"+(string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}")
|
||||||
}){
|
}){
|
||||||
if (dialog.ShowDialog() == DialogResult.OK){
|
if (dialog.ShowDialog() == DialogResult.OK){
|
||||||
|
@ -928,12 +928,12 @@
|
|||||||
// Block: Setup video player hooks.
|
// Block: Setup video player hooks.
|
||||||
//
|
//
|
||||||
(function(){
|
(function(){
|
||||||
window.TDGF_playVideo = function(url){
|
window.TDGF_playVideo = function(url, username){
|
||||||
$('<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);
|
||||||
}).appendTo(app);
|
}).appendTo(app);
|
||||||
|
|
||||||
$TD.playVideo(url);
|
$TD.playVideo(url, username || null);
|
||||||
};
|
};
|
||||||
|
|
||||||
var getVideoTweetLink = function(obj){
|
var getVideoTweetLink = function(obj){
|
||||||
@ -942,12 +942,16 @@
|
|||||||
return link.attr("href");
|
return link.attr("href");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var getUsername = function(tweet){
|
||||||
|
return tweet && (tweet.quotedTweet || tweet).getMainUser().screenName;
|
||||||
|
}
|
||||||
|
|
||||||
app.delegate(".js-gif-play", {
|
app.delegate(".js-gif-play", {
|
||||||
click: function(e){
|
click: function(e){
|
||||||
let src = !e.ctrlKey && $(this).closest(".js-media-gif-container").find("video").attr("src");
|
let src = !e.ctrlKey && $(this).closest(".js-media-gif-container").find("video").attr("src");
|
||||||
|
|
||||||
if (src){
|
if (src){
|
||||||
window.TDGF_playVideo(src);
|
window.TDGF_playVideo(src, getUsername(highlightedTweetObj));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$TD.openBrowser(getVideoTweetLink($(this)));
|
$TD.openBrowser(getVideoTweetLink($(this)));
|
||||||
@ -983,7 +987,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);
|
window.TDGF_playVideo(media.chooseVideoVariant().url, getUsername(this.chirp));
|
||||||
cancelModal = true;
|
cancelModal = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user