Permalink
Browse files

Merged WWW/YoutubeViewer/AuthToken.pm into WWW/YoutubeViewer.pm

Now, the new access token is saved into the authentication file right after it is recieved.
Removed the support for access_token and refresh_token configuration keys.
Removed the support for the very old config file style which consisted only of a HASH ref.
GTK Youtube Viewer has a new awesome icon. (thanks to posixru - http://zenway.ru/)
  • Loading branch information...
trizen committed Nov 24, 2013
1 parent ab983c6 commit b1160a7e6847d5d3f51d35611ded218a87524c35
@@ -4,7 +4,6 @@ Build.PL
Changes
ignore.txt
lib/WWW/YoutubeViewer.pm
-lib/WWW/YoutubeViewer/AuthToken.pm
lib/WWW/YoutubeViewer/GetCaption.pm
lib/WWW/YoutubeViewer/Itags.pm
lib/WWW/YoutubeViewer/ParseXML.pm
@@ -17,7 +16,6 @@ META.yml
README
share/gtk-youtube-viewer.desktop
share/gtk-youtube-viewer.glade
-share/gtk-youtube-viewer.png
share/icons/default_thumb.jpg
share/icons/feed_icon.png
share/icons/gtk-youtube-viewer.png
@@ -4,7 +4,7 @@
"Daniel \"Trizen\" Șuteu <trizenx@gmail.com>"
],
"dynamic_config" : 1,
- "generated_by" : "Module::Build version 0.4008, CPAN::Meta::Converter version 2.132830",
+ "generated_by" : "Module::Build version 0.42",
"license" : [
"perl_5"
],
@@ -15,6 +15,10 @@
"name" : "WWW-YoutubeViewer",
"prereqs" : {
"build" : {
+ "recommends" : {
+ "Term::ReadLine::Gnu::XS" : "0",
+ "XML::Fast" : "0"
+ },
"requires" : {
"Test::More" : "0"
}
@@ -25,10 +29,6 @@
}
},
"runtime" : {
- "recommends" : {
- "Term::ReadLine::Gnu::XS" : "0",
- "XML::Fast" : "0"
- },
"requires" : {
"Data::Dump" : "0",
"File::Path" : "0",
@@ -50,10 +50,6 @@
"file" : "lib/WWW/YoutubeViewer.pm",
"version" : "0.05"
},
- "WWW::YoutubeViewer::AuthToken" : {
- "file" : "lib/WWW/YoutubeViewer/AuthToken.pm",
- "version" : "0.01"
- },
"WWW::YoutubeViewer::GetCaption" : {
"file" : "lib/WWW/YoutubeViewer/GetCaption.pm",
"version" : "0.01"
@@ -7,7 +7,7 @@ build_requires:
configure_requires:
Module::Build: 0
dynamic_config: 1
-generated_by: 'Module::Build version 0.4008, CPAN::Meta::Converter version 2.132830'
+generated_by: 'Module::Build version 0.42, CPAN::Meta::Converter version 2.132830'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -17,9 +17,6 @@ provides:
WWW::YoutubeViewer:
file: lib/WWW/YoutubeViewer.pm
version: 0.05
- WWW::YoutubeViewer::AuthToken:
- file: lib/WWW/YoutubeViewer/AuthToken.pm
- version: 0.01
WWW::YoutubeViewer::GetCaption:
file: lib/WWW/YoutubeViewer/GetCaption.pm
version: 0.01
@@ -35,9 +32,6 @@ provides:
WWW::YoutubeViewer::Utils:
file: lib/WWW/YoutubeViewer/Utils.pm
version: 0.02
-recommends:
- Term::ReadLine::Gnu::XS: 0
- XML::Fast: 0
requires:
Data::Dump: 0
File::Path: 0
@@ -1,4 +1,4 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.4008
+# Note: this file was auto-generated by Module::Build::Compat version 0.4200
require 5.016;
use ExtUtils::MakeMaker;
WriteMakefile
@@ -56,9 +56,8 @@ my $xdg_config_home = $ENV{XDG_CONFIG_HOME}
# Configuration dir/file
my $config_dir = catdir($xdg_config_home, $execname);
my $config_file = catfile($config_dir, "$execname.conf");
-
my $yv_config_dir = catdir($xdg_config_home, 'youtube-viewer');
-my $auth_tokens_file = catfile($yv_config_dir, 'reg.dat');
+my $authentication_file = catfile($yv_config_dir, 'reg.dat');
foreach my $dir ($config_dir, $yv_config_dir) {
if (not -d $dir) {
@@ -345,38 +344,14 @@ use WWW::YoutubeViewer::RegularExpressions;
our $CONFIG;
require $config_file; # Load the configuration file
-{
- my $i = length $key;
- $key =~ s/(.{$i})(.)/$2$1/g while $i--;
-}
-
if (ref $CONFIG ne 'HASH') {
- $CONFIG = do($config_file) || warn "Can't load the configuration file: $!";
-}
-
-require WWW::YoutubeViewer::AuthToken;
-my $yv_token = WWW::YoutubeViewer::AuthToken->new(key => $key);
-
-my ($access_token, $refresh_token);
-if (defined $CONFIG->{access_token} and defined $CONFIG->{refresh_token}) {
-
- $access_token = $CONFIG->{access_token};
- $refresh_token = $CONFIG->{refresh_token};
-
- $yv_token->to_file($access_token, $refresh_token, $auth_tokens_file);
-}
-elsif (-e $auth_tokens_file) {
- ($access_token, $refresh_token) = $yv_token->from_file($auth_tokens_file);
+ die "ERROR: Invalid configuration file!\n\t\$CONFIG is not an HASH ref!";
}
my @valid_keys = grep { exists $CONFIG{$_} } keys %{$CONFIG};
@CONFIG{@valid_keys} = @{$CONFIG}{@valid_keys};
-if (ref $CONFIG ne 'HASH') {
- rename($config_file, $config_file . '.bak');
- dump_configuration();
-}
-elsif (not \%CONFIG ~~ $CONFIG) {
+if (not \%CONFIG ~~ $CONFIG) {
dump_configuration();
}
@@ -387,18 +362,22 @@ if (not defined $CONFIG{gcap}) {
}
}
+{
+ my $i = length $key;
+ $key =~ s/(.{$i})(.)/$2$1/g while $i--;
+}
+
# Locating youtube-viewer
$CONFIG{youtube_viewer} //= which_command('youtube-viewer') // 'youtube-viewer';
require WWW::YoutubeViewer;
my $yv_obj = WWW::YoutubeViewer->new(
- key => $key,
- app_name => $appname,
- app_version => $version,
- access_token => $access_token,
- refresh_token => $refresh_token,
- config_dir => $yv_config_dir,
- escape_utf8 => 1,
+ escape_utf8 => 1,
+ key => $key,
+ app_name => $appname,
+ app_version => $version,
+ config_dir => $yv_config_dir,
+ authentication_file => $authentication_file,
);
if (defined $yv_obj->get_access_token()) {
@@ -798,7 +777,7 @@ sub show_user_panel {
$yv_obj->set_refresh_token($info->{refresh_token}) // return;
if ($gui->get_object('login_check_button')->get_active) {
- $yv_token->to_file($yv_obj->get_access_token, $yv_obj->get_refresh_token, $auth_tokens_file)
+ $yv_obj->save_authentication_tokens()
or warn "Can't store the authentication tokens: $!";
}
@@ -1185,8 +1164,8 @@ sub save_usernames_to_file {
sub log_out {
change_subscription_page(0);
- unlink $auth_tokens_file
- or warn "Can't unlink: `$auth_tokens_file' -> $!";
+ unlink $authentication_file
+ or warn "Can't unlink: `$authentication_file' -> $!";
$yv_obj->set_access_token();
$yv_obj->set_refresh_token();
@@ -2121,13 +2100,6 @@ sub on_mainw_destroy {
# Save hpaned position
$CONFIG{hpaned_position} = $hbox2->get_position;
- my $new_token = $yv_obj->get_access_token();
-
- if (defined($new_token) && (!defined($access_token) || (defined($access_token) && $new_token ne $access_token))) {
- say "** Updating the access token...\n";
- $yv_token->to_file($new_token, $yv_obj->get_refresh_token(), $auth_tokens_file);
- }
-
get_main_window_size();
dump_configuration();
save_usernames_to_file();
@@ -140,8 +140,8 @@ my $xdg_config_home = $ENV{XDG_CONFIG_HOME}
# Configuration dir/file
my $config_dir = catdir($xdg_config_home, $execname);
-my $config_file = catfile($config_dir, "$execname.conf");
-my $auth_tokens_file = catfile($config_dir, 'reg.dat');
+my $config_file = catfile($config_dir, "$execname.conf");
+my $authentication_file = catfile($config_dir, 'reg.dat');
if (not -d $config_dir) {
require File::Path;
@@ -340,45 +340,21 @@ EOD
}
}
-if (not -e $config_file or $opt{reconfigure}) {
+if (not -e $config_file or -z _ or $opt{reconfigure}) {
dump_configuration();
}
our $CONFIG;
require $config_file; # Load the configuration file
-{
- my $i = length $key;
- $key =~ s/(.{$i})(.)/$2$1/g while $i--;
-}
-
if (ref $CONFIG ne 'HASH') {
- $CONFIG = do($config_file) || warn "Can't load the configuration file: $!";
-}
-
-require WWW::YoutubeViewer::AuthToken;
-my $yv_token = WWW::YoutubeViewer::AuthToken->new(key => $key);
-
-my ($access_token, $refresh_token);
-if (defined $CONFIG->{access_token} and defined $CONFIG->{refresh_token}) {
-
- $access_token = $CONFIG->{access_token};
- $refresh_token = $CONFIG->{refresh_token};
-
- $yv_token->to_file($access_token, $refresh_token, $auth_tokens_file);
-}
-elsif (-e $auth_tokens_file) {
- ($access_token, $refresh_token) = $yv_token->from_file($auth_tokens_file);
+ die "ERROR: Invalid configuration file!\n\t\$CONFIG is not an HASH ref!";
}
my @valid_keys = grep { exists $CONFIG{$_} } keys %{$CONFIG};
@CONFIG{@valid_keys} = @{$CONFIG}{@valid_keys};
-if (ref $CONFIG ne 'HASH') {
- rename($config_file, $config_file . '.bak');
- dump_configuration();
-}
-elsif (not \%CONFIG ~~ $CONFIG) {
+if (not \%CONFIG ~~ $CONFIG) {
dump_configuration();
}
@@ -392,15 +368,19 @@ if (not defined $CONFIG{gcap}) {
@opt{keys %CONFIG} = values(%CONFIG);
+{
+ my $i = length $key;
+ $key =~ s/(.{$i})(.)/$2$1/g while $i--;
+}
+
require WWW::YoutubeViewer;
my $yv_obj = WWW::YoutubeViewer->new(
- key => $key,
- access_token => $access_token,
- refresh_token => $refresh_token,
- app_name => $appname,
- app_version => $version,
- config_dir => $config_dir,
- escape_utf8 => 1,
+ key => $key,
+ app_name => $appname,
+ app_version => $version,
+ config_dir => $config_dir,
+ escape_utf8 => 1,
+ authentication_file => $authentication_file,
);
{
@@ -668,10 +648,6 @@ NOTE: Categories and region IDs are case sensitive!
But, what if we'd want to play the videos from the next pages too?
In this case, ':anp' is your friend. Use it wisely!
-8. It is recommended to close the application with the ':q' keyword.
- This option will update the access token (if needed) and closes
- the application with an appropriate exit-code.
-
** Closed-Captions
To get the closed-captions (subtitles) for videos, you need to install
the 'gcap' program. See: http://gcap.googlecode.com
@@ -1399,8 +1375,8 @@ sub get_user_input {
sub logout {
- unlink $auth_tokens_file
- or warn "Can't unlink: `$auth_tokens_file' -> $!";
+ unlink $authentication_file
+ or warn "Can't unlink: `$authentication_file' -> $!";
$yv_obj->set_access_token();
$yv_obj->set_refresh_token();
@@ -1436,7 +1412,7 @@ INFO
default => 'y',);
if ($remember_me) {
- $yv_token->to_file($yv_obj->get_access_token, $yv_obj->get_refresh_token, $auth_tokens_file)
+ $yv_obj->save_authentication_tokens()
or warn "Can't store the authentication tokens: $!";
}
@@ -3058,13 +3034,6 @@ sub press_enter_to_continue {
}
sub main_quit {
- my $new_token = $yv_obj->get_access_token();
-
- if (defined($new_token) && (!defined($access_token) || (defined($access_token) && $new_token ne $access_token))) {
- say "** Updating the access token...\n";
- $yv_token->to_file($new_token, $yv_obj->get_refresh_token(), $auth_tokens_file);
- }
-
exit $_[0];
}
Oops, something went wrong.

0 comments on commit b1160a7

Please sign in to comment.