tsrc/testing/tools/genVideoFeed.pl
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 #
       
     2 # Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 
       
    18 #------------------------------------------------------------------------------------
       
    19 # Includes
       
    20 #------------------------------------------------------------------------------------
       
    21 #use strict;
       
    22 use warnings;
       
    23 use Cwd; # for cwd
       
    24 use FindBin; # for FindBin:Bin
       
    25 use File::Path; # for mkpath
       
    26 use Date::Calc;
       
    27 
       
    28 #------------------------------------------------------------------------------------
       
    29 # GLOBAL CODE
       
    30 #------------------------------------------------------------------------------------
       
    31 
       
    32 
       
    33 my $xmlStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
       
    34 "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\">\n" .
       
    35 "\t<channel>\n";
       
    36 
       
    37 my $xmlItem =
       
    38 "\t<item>\n" .
       
    39 "\t\t<enclosure url=\"XMLURL\" length=\"39567360\" type=\"video/3gpp\"/>\n" .
       
    40 "\t\t<title>XMLTITLE</title>\n" .
       
    41 "\t\t<guid>XMLURL</guid>\n" .
       
    42 "\t</item>\n";
       
    43 
       
    44 my $xmlEnd =
       
    45 "\t</channel>\n" .
       
    46 "</rss>\n";
       
    47 
       
    48 my $argcount = scalar(@ARGV);
       
    49 my $paramFileName = "";
       
    50 my $paramOutFileName = "";
       
    51 
       
    52 if(scalar(@ARGV) < 2)
       
    53 {
       
    54     print("Usage: perl genVideoFeed.pl <infile> <outfile>\n");
       
    55     print("Infile is list of videos with url and title are separated by comma\n");
       
    56     exit();
       
    57 }
       
    58 
       
    59 while(scalar(@ARGV) >= 1)
       
    60 {
       
    61 	$paramFileName = shift(@ARGV);
       
    62 	$paramOutFileName = shift(@ARGV);
       
    63 }
       
    64 
       
    65 # Read TXT
       
    66 
       
    67 if( !open(FILE_HANDLE, $paramFileName) )
       
    68 {
       
    69 	print("ERROR! Could not open file '" . $paramFileName . "'\n");
       
    70 	return 0;
       
    71 }
       
    72 my @array = <FILE_HANDLE>;
       
    73 close(FILE_HANDLE);
       
    74 
       
    75 # Write XML
       
    76 
       
    77 if(!open(FILE_HANDLE, ">" . "$paramOutFileName") )
       
    78 {
       
    79     print("ERROR! Could not open file for writing '" . "$paramOutFileName" . "'\n");
       
    80     return 0;
       
    81 }
       
    82 
       
    83 print FILE_HANDLE ("$xmlStart");
       
    84 
       
    85 my $line;
       
    86 $line = $array[0];
       
    87 RemoveWhiteSpaces(\$line);
       
    88 print FILE_HANDLE ("<title>$line</title>\n");
       
    89 
       
    90 for(my $i=1; $i<scalar(@array); $i++)
       
    91 {
       
    92     my $pos = index($array[$i], ",");
       
    93     my $url = substr( $array[$i], 0, $pos);
       
    94     my $title = substr( $array[$i], $pos+1);
       
    95 
       
    96     RemoveWhiteSpaces(\$url);
       
    97     RemoveWhiteSpaces(\$title);
       
    98 
       
    99     my $data = $xmlItem;
       
   100     XmlReadyText(\$title);
       
   101     XmlReadyText(\$url);
       
   102     $data =~ s/XMLTITLE/$title/;
       
   103     $data =~ s/XMLURL/$url/g;
       
   104 
       
   105     if($url ne "" and $title ne "")
       
   106     {
       
   107         print FILE_HANDLE ("$data");
       
   108     }
       
   109 }
       
   110 
       
   111 print FILE_HANDLE ("$xmlEnd");
       
   112 
       
   113 close(FILE_HANDLE);
       
   114 
       
   115 exit();
       
   116 
       
   117 #------------------------------------------------------------------------------------
       
   118 # RemoveWhiteSpaces
       
   119 #
       
   120 # Parameters:
       
   121 # 	$text
       
   122 #------------------------------------------------------------------------------------
       
   123 sub RemoveWhiteSpaces
       
   124 {
       
   125 	my ($text) = @_;
       
   126 	${$text} =~ s/\s+$//; #whitespaces in the end
       
   127 	${$text} =~ s/^\s+//; #whitespaces at the start
       
   128 }
       
   129 
       
   130 #------------------------------------------------------------------------------------
       
   131 # XmlReadyText
       
   132 #
       
   133 # Parameters:
       
   134 # 	$text
       
   135 #------------------------------------------------------------------------------------
       
   136 sub XmlReadyText
       
   137 {
       
   138 	my ($text) = @_;
       
   139 
       
   140 	$txtlt = "&lt;";
       
   141 	$txtgt = "&gt;";
       
   142 	${$text} =~ s/</$txtlt/g;
       
   143 	${$text} =~ s/>/$txtgt/g;
       
   144 
       
   145 	${$text} =~ s/Ä/&Auml/g;
       
   146 	${$text} =~ s/ä/&auml/g;
       
   147 	${$text} =~ s/Ö/&Ouml/g;
       
   148 	${$text} =~ s/ö/&ouml/g;
       
   149 
       
   150 	#ä &auml;
       
   151 
       
   152 #	Ö &Ouml;
       
   153 
       
   154 #	ö &ouml;
       
   155 
       
   156 }