Wednesday, September 10, 2014

"My Youtube Channels" Android Application Changed to "My Channels" in Google Play Store

2 years back I have uploaded my android application "My Youtube Channels" to Google Play Store. You can quickly search for a particular Youtube channel based on a keyword and add it to your favorites list. You can later quickly access the content of the channel as it is already in your favorites list on the launch screen of the app. It has the following features.
  • Search for a keyword and add selected channel to your list.
  • Follow the selected video channels regularly.
  • Enjoy periodic updates from the channels you like by changing settings( Periodic new video check time interval etc.).
  •  Select multiple videos and play them at once.
  • Share the videos you like on Facebook.
It started small with fewer downloads and gradually increased after one year. Once the app started getting good downloads the app was somehow deleted from play store. Hence, I have modified it a bit and re-uploaded to play store with "My Channels" Name. Please download the "My Channels" application and rate it after you use it for some time.

Friday, April 30, 2010

Desktop Scorecard for Cricket

Most of the cricket lovers will be using their favorite site cricinfo.com for the match updates. As a huge fan of cricket I do the same. But sometimes when you are doing some important work, you may not be interested in switching the current working window to watch the score. As an example When I am watching a movie, I am not interested in pausing the movie and see the score card. This led me to think of how can I know the score without switching my window. Desktop scorecard is the solution that I came up with.

I have kubuntu running on machine. Kubuntu shows a pop-up notification message at the bottom right corner when I plug in a pendrive. I thought of using the similar kind of notification message for the cricket score card. When I searched on net, I found a cool solution with kdialog tool. It has various GUI elements like input textbox, alert windows etc. For the score card notification message it has an option called passivepopup. It takes 2 parameters. One is the text to be shown in the notification message and the other one is the time duration for which the notification message should be active. If the user does not close that message with in that time, It automatically gets closed. For example the following command produces the below passivepopup

kdialog --title "This is a passive popup" --passivepopup "It will disappear in about 60 seconds" 60


Having known how to show pop-up notification messages, my task of showing score card has become more easy. All I need to do now is that, I have to get the current score and then send that to the popup message. For this task, I have used the cricinfo.com as the source for my score card. My score card shows very little information, the current team's score and both the batsman's score. I think that is enough but if you want more you can add it.

For reading the webpage and getting the score, I have used the perl language. Finally a mix of both perl and shell scripting completed my task.

#!/usr/bin/perl
use LWP::Simple;
$numargs=$#ARGV + 1;
if($numargs < 1)
{
  print "Enter the URL as argument";
  exit;
}
$pageURL=$ARGV[0];
$filename="cricket.txt";
$scorecardfname="score.txt";
#$pageURL="http://www.cricinfo.com/world-twenty20-2010/engine/current/match/412678.html?view=live";#"http://www.google.com";
$simplePage=get($pageURL); 
if( $simplePage == /^\s*$/)
{
   print "page can not be fetched\n";
   open FHSC1,">$scorecardfname" or die $!;
   print FHSC1 "";
   close FHSC1;
   exit;
}
open FH,"> $filename" or die $!;
print FH $simplePage;
close FH;
open FH,$filename or die $!;
open FHSC,">$scorecardfname" or die $!;
@fc=<fh>;
$NOL=@fc;
$line=0;
$noofplayers=0;
$teamcount=0;
while($line < $NOL)
{
  $e = $fc[$line];
  if( $e =~ /<div class="teamText">
(.*)<\/p>/ )
  {
    if($teamcount == 0 )
    {
      $firstbattingteam = $1;
      print FHSC $firstbattingteam."\n";
      $teamcount++;
    } 
    elsif($teamcount==1)
    {
      $secondbattingteam = $1;
      $teamcount++;
    }
  }
  elsif( $e =~ /showHwkTooltip/ )
  {
    if( $e =~ /<a.*>(.*)<\/a>/)
    {
      #print $1."\n";
      $name = $1;
      $line = $line + 2;
      if( $fc[$line] =~ /<b>(.*)<\/b><\/td>/ )
      {
          $score = $1;
      }
      $line++;
      if( $fc[$line] =~ /(.*)<\/td>/ )
      {
          $balls = $1;
      }
      $line++;
      if( $fc[$line] =~ /(.*)<\/td>/ )
      {
          $fours = $1;
      }
      $line++;
      if( $fc[$line] =~ /(.*)<\/td>/ )
      {
          $sixes = $1;
      }
      $line++;
      if( $fc[$line] =~ /(.*)<\/td>/ )
      {
          $strikerate = $1;
      }
      print FHSC $name."      ".$score."(".$balls.")\n"; 
      $noofplayers++;
      if($noofplayers==2) 
      {
          last;
      }
    }
  }
  $line++;
}
print FHSC $secondbattingteam."\n";
#print FHSC $firstbattingteam."\n";
close FH;
close FHSC;

save the above code as readwebpage.pl. This takes the URL of the cricinfo webpage as the command line argument. This is perl script is executed in the below mentioned shell script. It reads the webpage and searches for the teams information and current batting players. It writes this information in to score.txt file. This file is read by the below shell script.

i=1;
url=`kdialog --title "Cricinfo Url" --inputbox "Enter the Cricinfo URL"`;
echo "Entered URL: $url";
while [ $i -ne 0 ]
do
  ./readwebpage.pl $url;
  sha=`cat score.txt`;
  if [[ $sha == "" ]]
  then
    exit;
  fi
  kdialog --title "scorecard" --passivepopup "$sha" 10;
  sleep 11;
done

Save the above snippet as showscore.sh. When you run this shell script, it opens a window containing a input text box asking for the URL. Go to cricinfo.com in your browser and go the score card page for which you want updates, copy and then paste it in that text box.



One important thing to note here is that always add "?view=live" at the end of the URL. For example if the page URL is http://www.cricinfo.com/world-twenty20-2010/engine/current/match/412678.html then the URL you should enter is http://www.cricinfo.com/world-twenty20-2010/engine/current/match/412678.html?view=live. After taking this URL as input it calls the above perl script with the URL as the command line argument. The perl script writes data into score.txt file. Now the shell script reads the data from score.txt file and calls kdialog's passivepop message. I have kept the 10sec time for the popup to stay alive. You can configure this as you wish. This is all fine but we want to update the score card on regular time intervals. For this purpose make the above functionality in an infinite loop but there should be some sleep time between each update. That regular interval time can be put as the parameter for the sleep command in the script. Suppose if you want to update the score for every 30 sec. then make that as sleep 30 instead of sleep 11.

This works only in Linux machines and you should have Kdialog and perl installed. Ubuntu users can get kdialog using sudo apt-get install kdebase-bin or get it through synaptic manager. Most of the Linux distributions already have perl installed. If you quickly want to try this, download the file DesktopScoreCard. Untar the downloaded file. Open a terminal and go to the untarred DesktopScoreCard folder. Then run the showscore.sh file. If all goes well you can see the popup message with the score card from the URL you have entered.
You can see the screen shot showing the score card