Skip to content
Browse files

GTK Youtube Viewer became much more portable;

New module requirement: File::ShareDir;
The 'gcap' is auto-detected (even if it installed after the first run of youtube-viewer or gtk-youtube-viewer);
'youtube-viewer' is detected well better by 'gtk-youtube-viewer' (no more additional copy in the 'share' dir)
  • Loading branch information...
1 parent d957b6b commit 37f1c20e0d26f7e255556f97c16a8e8d9cdd9202 @trizen committed
View
74 WWW-YoutubeViewer/Build.PL
@@ -98,7 +98,6 @@ $builder->requires(
'perl' => '5.016',
'Data::Dump' => 0,
'File::Spec::Functions' => 0,
- 'File::Basename' => 0,
'File::Path' => 0,
'Getopt::Long' => 0,
'HTTP::Request' => 0,
@@ -110,76 +109,13 @@ $builder->requires(
'URI::Escape' => 0,
$gtk_youtube_viewer
- ? ('Gtk2' => 0)
+ ? (
+ 'Gtk2' => 0,
+ 'File::ShareDir' => 0,
+ )
: (),
);
$builder->script_files(['bin/youtube-viewer', ($gtk_youtube_viewer ? 'bin/gtk-youtube-viewer' : ())]);
+$builder->dist_dir('share') if $gtk_youtube_viewer;
$builder->create_build_script();
-
-# Intalling the files for GTK YouTube Viewer
-if ($gtk_youtube_viewer) {
-
- use autouse 'File::Basename' => qw(dirname);
- use autouse 'File::Spec::Functions' => qw(rel2abs catfile catdir rootdir);
- use autouse 'File::Copy' => qw(copy);
- use autouse 'File::Path' => qw(make_path);
-
- my $dest_dir = $builder->destdir // rootdir();
- my $main_dir = dirname(rel2abs($0));
- my $main_share_dir = catdir($main_dir, qw(share));
-
- my $share_dir = catdir($dest_dir, qw(usr share));
- my $pixmaps_dir = catdir($share_dir, qw(pixmaps));
- my $applications_dir = catdir($share_dir, qw(applications));
- my $gtk_youtube_viewer_dir = catdir($share_dir, qw(gtk-youtube-viewer));
- my $gtk_youtube_viewer_icons = catdir($gtk_youtube_viewer_dir, qw(icons));
-
- if (my @dirs_to_create = grep({not -d} $gtk_youtube_viewer_icons, $applications_dir, $pixmaps_dir)) {
- make_path(
- @dirs_to_create,
- {
- verbose => 1,
- mode => 0755,
- }
- )
- or die "Creating path failed: $!";
- }
-
- my $desktop_file = q(gtk-youtube-viewer.desktop);
- my $glade_file = q(gtk-youtube-viewer.glade);
-
- foreach my $dest (
- [catfile($main_share_dir, $desktop_file) => catfile($applications_dir, $desktop_file)],
- [catfile($main_dir, qw(bin youtube-viewer)) => catfile($gtk_youtube_viewer_dir, qw(youtube-viewer))],
- [catfile($main_share_dir, $glade_file) => catfile($gtk_youtube_viewer_dir, $glade_file)],
- ) {
- copy($dest->[0], $dest->[1]) or die "Can't copy `$dest->[0]' to `$dest->[1]': $!";
- }
-
- foreach my $copy_instructions (
- {
- icon_dir => 'icons',
- dest_dir => $pixmaps_dir,
- },
- {
- icon_dir => 'gtk-youtube-viewer-icons',
- dest_dir => $gtk_youtube_viewer_icons,
- }
- ) {
- my $main_icons_dir = catdir($main_share_dir, $copy_instructions->{icon_dir});
- opendir(my $dir_h, $main_icons_dir) or die "Can't open dir '$main_icons_dir': $!";
-
- while (defined(my $file = readdir($dir_h))) {
-
- my $full_file_path = catfile($main_icons_dir, $file);
- $full_file_path =~ /\.(?:png|jpg|gif)\z/i or next;
-
- my $destination = catfile($copy_instructions->{dest_dir}, $file);
- print STDERR "cp '$full_file_path' '$destination'\n";
-
- copy($full_file_path => $destination) or die "Copy failed: $!";
- }
- closedir $dir_h;
- }
-}
View
1 WWW-YoutubeViewer/META.json
@@ -31,7 +31,6 @@
},
"requires" : {
"Data::Dump" : "0",
- "File::Basename" : "0",
"File::Path" : "0",
"File::Spec::Functions" : "0",
"Getopt::Long" : "0",
View
1 WWW-YoutubeViewer/META.yml
@@ -40,7 +40,6 @@ recommends:
XML::Fast: 0
requires:
Data::Dump: 0
- File::Basename: 0
File::Path: 0
File::Spec::Functions: 0
Getopt::Long: 0
View
1 WWW-YoutubeViewer/Makefile.PL
@@ -7,7 +7,6 @@ WriteMakefile
'VERSION_FROM' => 'lib/WWW/YoutubeViewer.pm',
'PREREQ_PM' => {
'Data::Dump' => 0,
- 'File::Basename' => 0,
'File::Path' => 0,
'File::Spec::Functions' => 0,
'Getopt::Long' => 0,
View
12 WWW-YoutubeViewer/README
@@ -20,21 +20,19 @@ To package this application, run the following commands:
GTK-YOUTUBE-VIEWER
-To install the gtk-youtube-viewer, run Build.PL with the '--gtk-youtube-viewer' argument.
+To install GTK Youtube Viewer, run Build.PL with the '--gtk-youtube-viewer' argument.
- sudo perl Build.PL --gtk-youtube-viewer
+ perl Build.PL --gtk-youtube-viewer
or:
perl Build.PL --destdir "/my/path" --gtk-youtube-viewer
-# NOTE: If you're installing gtk-youtube-viewer, the 'Build.PL' script must be executed with root
-# permissions because it creates the directories and installs the files needed for gtk-youtube-viewer.
SUPPORT AND DOCUMENTATION
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! If you're using a version of perl < 5.16.0, youtube-viewer (CLI) will need some changes;
-!! Please, see: https://code.google.com/p/trizen/downloads/detail?name=yv_5.16_to_5.10.pl
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! Please, consider: https://code.google.com/p/trizen/downloads/detail?name=yv_5.16_to_5.10.pl
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
After installing, you can find documentation for this module with the
perldoc command.
View
86 WWW-YoutubeViewer/bin/gtk-youtube-viewer
@@ -31,6 +31,7 @@ use strict;
no if $] >= 5.018, warnings => 'experimental::smartmatch';
use Gtk2 qw(-init);
+use File::ShareDir qw(dist_dir);
use File::Spec::Functions qw(
rel2abs
catdir
@@ -70,26 +71,17 @@ foreach my $dir ($config_dir, $yv_config_dir) {
# Unchangeable variables goes here
my %constant = (win32 => ($^O =~ /^mswin\d/i || 0));
-# CLI Youtube Viewer
-my $cli_youtube_viewer = '/usr/share/gtk-youtube-viewer/youtube-viewer';
+# Share directory
+my $share_dir = dist_dir('WWW-YoutubeViewer');
-if (not -e $cli_youtube_viewer) {
- $cli_youtube_viewer = rel2abs('./youtube-viewer');
-}
-
-if (not -e $cli_youtube_viewer) {
- require File::Basename;
- my $dir = File::Basename::dirname(rel2abs($0));
- $cli_youtube_viewer = catfile($dir, 'youtube-viewer');
-}
-
-# Locating gcap
-my $gcap;
-foreach my $path (path()) {
- if (-e (my $gcap_path = catfile($path, 'gcap'))) {
- $gcap = $gcap_path;
- last;
+sub which_command {
+ my ($cmd) = @_;
+ foreach my $path (path()) {
+ if (-e (my $cmd_path = catfile($path, $cmd))) {
+ return $cmd_path;
+ }
}
+ return;
}
# Get mplayer
@@ -163,7 +155,7 @@ my %CONFIG = (
srt_languages => ['en', 'jp'],
captions_dir => tmpdir(),
get_captions => 1,
- gcap => $gcap,
+ gcap => undef,
# Others
http_proxy => undef,
@@ -178,12 +170,11 @@ my %CONFIG = (
search_channels => 0,
search_playlists => 0,
thousand_separator => q{,},
- perl_bin => $^X,
default_thumb => 'default',
downloads_folder => $ENV{'HOME'},
browser => undef,
terminal => find_terminal(),
- cli_youtube_viewer => $cli_youtube_viewer,
+ youtube_viewer => undef,
users_list => catfile($config_dir, 'youtube_users.txt'),
);
@@ -227,24 +218,12 @@ foreach my $sig (qw(HUP TERM INT KILL)) {
}
# Locating the .glade interface file and icons dir
-my ($interface_path, $icons_path);
-if (-f (my $glade_file = catfile(updir(), 'share', "$execname.glade"))) {
- require File::Basename;
- $interface_path = rel2abs($glade_file);
- $icons_path = catdir(File::Basename::dirname($interface_path), 'gtk-youtube-viewer-icons');
-}
-else {
- foreach my $usr_dir (qw(/usr /usr/local . ..)) {
- if (-e ($interface_path = catfile($usr_dir, 'share', $execname, "$execname.glade"))) {
- $icons_path = catdir($usr_dir, 'share', $execname, 'icons');
- last;
- }
- }
-}
+my $glade_file = catfile($share_dir, "$execname.glade");
+my $icons_path = catdir($share_dir, "$execname-icons");
# Defining GUI
my $gui = 'Gtk2::Builder'->new;
-$gui->add_from_file($interface_path);
+$gui->add_from_file($glade_file);
$gui->connect_signals(undef);
# ------------- Get GUI objects ------------- #
@@ -350,11 +329,11 @@ local $SIG{__DIE__} = sub {
};
#---------------------- LOAD IMAGES ----------------------#
-my $app_icon_pixbuf = 'Gtk2::Gdk::Pixbuf'->new_from_file("$icons_path/$execname.png");
-my $user_icon_pixbuf = 'Gtk2::Gdk::Pixbuf'->new_from_file_at_size("$icons_path/user.png", 16, 16);
-my $feed_icon_pixbuf = 'Gtk2::Gdk::Pixbuf'->new_from_file_at_size("$icons_path/feed_icon.png", 16, 16);
-my $default_thumb = 'Gtk2::Gdk::Pixbuf'->new_from_file_at_size("$icons_path/default_thumb.jpg", 120, 90);
-my $animation = 'Gtk2::Gdk::PixbufAnimation'->new_from_file("$icons_path/spinner.gif");
+my $app_icon_pixbuf = 'Gtk2::Gdk::Pixbuf'->new_from_file(catfile($icons_path, "$execname.png"));
+my $user_icon_pixbuf = 'Gtk2::Gdk::Pixbuf'->new_from_file_at_size(catfile($icons_path, "user.png"), 16, 16);
+my $feed_icon_pixbuf = 'Gtk2::Gdk::Pixbuf'->new_from_file_at_size(catfile($icons_path, "feed_icon.png"), 16, 16);
+my $default_thumb = 'Gtk2::Gdk::Pixbuf'->new_from_file_at_size(catfile($icons_path, "default_thumb.jpg"), 120, 90);
+my $animation = 'Gtk2::Gdk::PixbufAnimation'->new_from_file(catfile($icons_path, "spinner.gif"));
# Setting application title and icon
$mainw->set_title("$appname $version");
@@ -401,6 +380,16 @@ elsif (not \%CONFIG ~~ $CONFIG) {
dump_configuration();
}
+# Locating gcap
+if (not defined $CONFIG{gcap}) {
+ if (defined(my $gcap = which_command('gcap'))) {
+ $CONFIG{gcap} = $gcap;
+ }
+}
+
+# Locating youtube-viewer
+$CONFIG{youtube_viewer} //= which_command('youtube-viewer') // 'youtube-viewer';
+
require WWW::YoutubeViewer;
my $yv_obj = WWW::YoutubeViewer->new(
key => $key,
@@ -703,7 +692,7 @@ use_threads
1 to use threads when getting the XML content
use_threads_for_thumbs
- 1 to use threads when getting the thumbnails
+ 1 to use threads when getting the thumbnails (not recommended!)
cache & cache_min
this cache values are used for resolutions higher than 480p
@@ -721,13 +710,13 @@ clear_list
1 to clean the treeview list before each search
gcap
- path to gcap application ( see http://gcap.googlecode.com )
+ full path to the gcap application ( see http://gcap.googlecode.com )
srt_languages
- default subtitle languages (when gcap is available)
+ default subtitle languages (requires: gcap)
captions_dir
- is used to store the closed captions from YouTube (.srt files)
+ the directory where to store the closed captions from YouTube (.srt files)
* Knowledge:
http://code.google.com/intl/ro/apis/youtube/2.0/developers_guide_protocol_api_query_parameters.html
@@ -1825,7 +1814,7 @@ sub clear_text {
}
sub run_cli_youtube_viewer {
- execute_external_program($CONFIG{terminal}, '-e', q{'} . join(' ', $CONFIG{perl_bin}, $CONFIG{cli_youtube_viewer}), q{'});
+ execute_external_program($CONFIG{terminal}, '-e', q{'} . join(' ', $CONFIG{youtube_viewer}), q{'});
}
sub find_terminal {
@@ -1936,10 +1925,7 @@ sub execute_cli_youtube_viewer {
q{ },
(
map { chr ord eq q{'} ? $_ : quotemeta } $CONFIG{terminal},
- '-e',
- q{'}
- . join(q{ }, $CONFIG{perl_bin}, $CONFIG{cli_youtube_viewer}, get_options_as_arguments(), @arguments)
- . q{'}
+ '-e', q{'} . join(q{ }, $CONFIG{youtube_viewer}, get_options_as_arguments(), @arguments) . q{'}
)
)
. ' &';
View
23 WWW-YoutubeViewer/bin/youtube-viewer
@@ -149,13 +149,14 @@ if (not -d $config_dir) {
or warn "[!] Can't create dir '$config_dir': $!";
}
-# Locating gcap
-my $gcap;
-foreach my $path (path()) {
- if (-e (my $gcap_path = catfile($path, 'gcap'))) {
- $gcap = $gcap_path;
- last;
+sub which_command {
+ my ($cmd) = @_;
+ foreach my $path (path()) {
+ if (-e (my $cmd_path = catfile($path, $cmd))) {
+ return $cmd_path;
+ }
}
+ return;
}
# Regular expressions
@@ -192,7 +193,7 @@ my %CONFIG = (
srt_languages => ['en', 'jp'],
captions_dir => tmpdir(),
get_captions => 1,
- gcap => $gcap,
+ gcap => undef,
# Others
http_proxy => undef,
@@ -381,6 +382,14 @@ elsif (not \%CONFIG ~~ $CONFIG) {
dump_configuration();
}
+# Locating gcap
+if (not defined $CONFIG{gcap}) {
+ if (defined(my $gcap = which_command('gcap'))) {
+ $CONFIG{gcap} = $gcap;
+ dump_configuration();
+ }
+}
+
@opt{keys %CONFIG} = values(%CONFIG);
require WWW::YoutubeViewer;

0 comments on commit 37f1c20

Please sign in to comment.
Something went wrong with that request. Please try again.