Skip to content
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

feat(mv): enable caching for clapper #1010

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions build-aux/clapper/clapper.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
{
"type": "git",
"url": "https://github.com/Rafostar/clapper.git",
"branch": "master"
}
"branch": "df371c698add3598a4e2b94f6bf3a1f939706fd8"
},
{
"type": "shell",
"commands": ["sed -i \"s/version: '0.7.0',/version: '0.8.0',/g\" meson.build"]
}
]
}
}
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ if clapper_support and clapper_dep.found () and clapper_dep.version().version_co
if (clapper_dep.get_variable('features').split().contains('mpris'))
add_project_arguments(['--define=CLAPPER_MPRIS'], language: 'vala')
endif

if clapper_dep.version().version_compare('>=0.8.0')
add_project_arguments(['--define=CLAPPER_0_8'], language: 'vala')
endif
endif

if gtk_dep.version().version_compare('>=4.14')
Expand Down
34 changes: 33 additions & 1 deletion src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,14 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
}
}

#if CLAPPER
string clapper_cache_dir;
Gee.HashMap<string, Clapper.MediaItem> clapper_cached_items;
GeopJr marked this conversation as resolved.
Show resolved Hide resolved
#endif
construct {
#if CLAPPER
clapper_cached_items = new Gee.HashMap<string, Clapper.MediaItem> ();
clapper_cache_dir = GLib.Path.build_path (GLib.Path.DIR_SEPARATOR_S, Tuba.cache_path, "clapper");
// Clapper can have > 1.0 volumes
last_used_volume = settings.media_viewer_last_used_volume;
#else
Expand Down Expand Up @@ -546,6 +552,9 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
~MediaViewer () {
debug ("Destroying MediaViewer");
context_menu.unparent ();
#if CLAPPER_0_8
clapper_cached_items.clear ();
#endif
}

private void on_visible_toggle () {
Expand Down Expand Up @@ -948,6 +957,13 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
valign = Gtk.Align.END,
fullscreenable = false
});

#if CLAPPER_0_8
video.player.download_dir = clapper_cache_dir;
video.player.download_enabled = true;
video.player.download_complete.connect (on_clapper_download_complete);
#endif

#if CLAPPER_MPRIS
var mpris = new Clapper.Mpris (
"org.mpris.MediaPlayer2.Tuba",
Expand Down Expand Up @@ -977,7 +993,17 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
item = new Item (video, final_friendly_url, final_preview, true);

#if CLAPPER
var clp_item = new Clapper.MediaItem (url);
Clapper.MediaItem clp_item;
#if CLAPPER_0_8
if (clapper_cached_items.has_key (url)) {
clp_item = clapper_cached_items.get (url);
} else {
#endif
clp_item = new Clapper.MediaItem (url);
#if CLAPPER_0_8
}
#endif

video.player.queue.add_item (clp_item);
video.player.queue.select_item (clp_item);
add_todo_item (item);
Expand Down Expand Up @@ -1030,6 +1056,12 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
if (as_is || stream) add_todo_item (item);
}

#if CLAPPER_0_8
private void on_clapper_download_complete (Clapper.MediaItem clp_media_item, string location) {
clapper_cached_items.set (clp_media_item.uri, clp_media_item);
}
#endif

private Gee.ArrayList<string> todo_items = new Gee.ArrayList<string> ();
private void add_todo_item (Item todo_item) {
if (revealed) {
Expand Down
Loading