mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-13 18:15:48 +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));
|
||||
}
|
||||
|
||||
public void PlayVideo(string url){
|
||||
form.InvokeAsyncSafe(() => form.PlayVideo(url));
|
||||
public void PlayVideo(string url, string username){
|
||||
form.InvokeAsyncSafe(() => form.PlayVideo(url, username));
|
||||
}
|
||||
|
||||
public void FixClipboard(){
|
||||
|
@ -541,7 +541,7 @@ public void PlayNotificationSound(){
|
||||
soundNotification.Play(Config.NotificationSoundPath);
|
||||
}
|
||||
|
||||
public void PlayVideo(string url){
|
||||
public void PlayVideo(string url, string username){
|
||||
if (string.IsNullOrEmpty(url)){
|
||||
videoPlayer?.Close();
|
||||
return;
|
||||
@ -556,7 +556,7 @@ public void PlayVideo(string url){
|
||||
};
|
||||
}
|
||||
|
||||
videoPlayer.Launch(url);
|
||||
videoPlayer.Launch(url, username);
|
||||
}
|
||||
|
||||
public void HideVideoOverlay(){
|
||||
|
@ -116,7 +116,7 @@ public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser br
|
||||
|
||||
case MenuSaveMedia:
|
||||
if (IsVideo){
|
||||
TwitterUtils.DownloadVideo(GetMediaLink(parameters));
|
||||
TwitterUtils.DownloadVideo(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault());
|
||||
}
|
||||
else{
|
||||
TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
|
||||
|
@ -25,6 +25,7 @@ public bool Running{
|
||||
|
||||
private readonly Form owner;
|
||||
private string lastUrl;
|
||||
private string lastUsername;
|
||||
|
||||
private Process currentProcess;
|
||||
private DuplexPipe.Server currentPipe;
|
||||
@ -35,14 +36,15 @@ public VideoPlayer(Form owner){
|
||||
this.owner.FormClosing += owner_FormClosing;
|
||||
}
|
||||
|
||||
public void Launch(string url){
|
||||
public void Launch(string url, string username){
|
||||
if (Running){
|
||||
Destroy();
|
||||
isClosing = false;
|
||||
}
|
||||
|
||||
lastUrl = url;
|
||||
|
||||
lastUsername = username;
|
||||
|
||||
try{
|
||||
currentPipe = DuplexPipe.CreateServer();
|
||||
currentPipe.DataIn += currentPipe_DataIn;
|
||||
@ -84,7 +86,7 @@ private void currentPipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e){
|
||||
break;
|
||||
|
||||
case "download":
|
||||
TwitterUtils.DownloadVideo(lastUrl);
|
||||
TwitterUtils.DownloadVideo(lastUrl, lastUsername);
|
||||
break;
|
||||
|
||||
case "rip":
|
||||
@ -157,14 +159,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 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);
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
|
@ -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 ext = Path.GetExtension(filename);
|
||||
|
||||
@ -111,7 +111,7 @@ public static void DownloadVideo(string url){
|
||||
AutoUpgradeEnabled = true,
|
||||
OverwritePrompt = true,
|
||||
Title = "Save video",
|
||||
FileName = filename,
|
||||
FileName = string.IsNullOrEmpty(username) ? filename : $"{username} {filename}",
|
||||
Filter = "Video"+(string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}")
|
||||
}){
|
||||
if (dialog.ShowDialog() == DialogResult.OK){
|
||||
|
@ -928,12 +928,12 @@
|
||||
// Block: Setup video player hooks.
|
||||
//
|
||||
(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(){
|
||||
$TD.playVideo(null, null);
|
||||
}).appendTo(app);
|
||||
|
||||
$TD.playVideo(url);
|
||||
$TD.playVideo(url, username || null);
|
||||
};
|
||||
|
||||
var getVideoTweetLink = function(obj){
|
||||
@ -942,12 +942,16 @@
|
||||
return link.attr("href");
|
||||
}
|
||||
|
||||
var getUsername = function(tweet){
|
||||
return tweet && (tweet.quotedTweet || tweet).getMainUser().screenName;
|
||||
}
|
||||
|
||||
app.delegate(".js-gif-play", {
|
||||
click: function(e){
|
||||
let src = !e.ctrlKey && $(this).closest(".js-media-gif-container").find("video").attr("src");
|
||||
|
||||
if (src){
|
||||
window.TDGF_playVideo(src);
|
||||
window.TDGF_playVideo(src, getUsername(highlightedTweetObj));
|
||||
}
|
||||
else{
|
||||
$TD.openBrowser(getVideoTweetLink($(this)));
|
||||
@ -981,9 +985,9 @@
|
||||
|
||||
TD.components.MediaGallery.prototype._loadTweet = appendToFunction(TD.components.MediaGallery.prototype._loadTweet, function(){
|
||||
let media = this.chirp.getMedia().find(media => media.mediaId === this.clickedMediaEntityId);
|
||||
|
||||
|
||||
if (media && media.isVideo && media.service === "twitter"){
|
||||
window.TDGF_playVideo(media.chooseVideoVariant().url);
|
||||
window.TDGF_playVideo(media.chooseVideoVariant().url, getUsername(this.chirp));
|
||||
cancelModal = true;
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user