Skip to content

feat(Attachment.Box): stream attachments by default #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Services/Helpers/Video.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class Tuba.Helper.Video {
private static Soup.Session session;
private static Soup.Cache cache;

public static void clear_cache () {
new Helper.Video ();
cache.clear ();
}

public static void flush_cache () {
new Helper.Video ();
cache.flush ();
cache.dump ();
}

static construct {
cache = new Soup.Cache (
GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S, Tuba.cache_path, "soup", "videos"),
Soup.CacheType.SINGLE_USER
);
cache.load ();
cache.set_max_size (1024 * 1024 * 100 * 2);

session = new Soup.Session.with_options ("max-conns", 64, "max-conns-per-host", 64) {
user_agent = @"$(Build.NAME)/$(Build.VERSION) libsoup/$(Soup.get_major_version()).$(Soup.get_minor_version()).$(Soup.get_micro_version()) ($(Soup.MAJOR_VERSION).$(Soup.MINOR_VERSION).$(Soup.MICRO_VERSION))" // vala-lint=line-length
};
session.add_feature (cache);
}

public static async InputStream request (string? url) throws Oopsie {
if (url == null || url == "") throw new Tuba.Oopsie.INTERNAL ("No url provided");
new Helper.Video ();

var download_msg = new Soup.Message ("GET", url);
try {
return yield session.send_async (download_msg, 0, null);
} catch (Error e) {
throw new Tuba.Oopsie.INTERNAL (@"Failed to get video at \"$url\": $(e.message)");
}
}
}
1 change: 1 addition & 0 deletions src/Services/Helpers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ sources += files(
'Blurhash.vala',
'Entity.vala',
'Image.vala',
'Video.vala',
)
12 changes: 10 additions & 2 deletions src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,16 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
item = new Item (video, final_friendly_url, final_preview, true);

if (stream) {
File file = File.new_for_uri (url);
video.set_file (file);
Helper.Video.request.begin (url, (obj, res) => {
try {
video.set_media_stream (Gtk.MediaFile.for_input_stream (Helper.Video.request.end (res)));
add_todo_item (item);
} catch (Oopsie e) {
warning (e.message);
var dlg = app.inform (_("Error"), e.message);
dlg.present (app.main_window);
}
});
} else if (!as_is) {
download_video.begin (url, (obj, res) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/Attachment/Box.vala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class Tuba.Widgets.Attachment.Box : Adw.Bin {
false,
attachment_widgets[i].pic.alternative_text,
null,
false,
true,
is_main,
is_main == null
);
Expand Down
Loading