/usr/bin/tv_grab_fi is in xmltv-util 0.5.67-0.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 | #!/usr/bin/perl -w
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
# -*- mode: perl; coding: utf-8 -*- ###########################################
#
# Setup
#
###############################################################################
use 5.008; # we process Unicode texts
use strict;
use warnings;
###############################################################################
#
# This is the merged version of the script.
#
# !!! DO NOT EDIT - YOUR CHANGES WILL BE LOST !!!
#
# Any changes should be done to the original modules instead.
#
###############################################################################
package fi::common;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT = qw(message debug fetchRaw fetchTree
timeToEpoch fullTimeToEpoch);
our @EXPORT_OK = qw(setQuiet setDebug setTimeZone);
our %EXPORT_TAGS = (
main => [qw(message debug setQuiet setDebug setTimeZone)],
);
# Perl core modules
use Carp;
use Encode qw(decode);
use POSIX qw(tzset);
use Time::Local qw(timelocal);
# Other modules
use HTML::TreeBuilder;
use XMLTV::Get_nice;
# Normal message, disabled with --quiet
{
my $quiet = 0;
sub message(@) { print STDERR "@_\n" unless $quiet }
sub setQuiet($) { ($quiet) = @_ }
}
# Debug message, enabled with --debug
{
my $debug = 0;
sub debug($@) {
my $level = shift;
print STDERR "@_\n" unless $debug < $level;
}
sub setDebug($) {
if (($debug) = @_) {
# Debug messages may contain Unicode
binmode(STDERR, ":encoding(utf-8)");
debug(1, "Debug level set to $debug.");
}
}
}
# Fetch URL as UTF-8 encoded string
sub fetchRaw($;$$) {
my($url, $encoding, $nofail) = @_;
debug(2, "Fetching URL '$url'");
my $content;
my $retries = 5; # this seems to be enough?
RETRY:
while (1) {
eval {
local $SIG{ALRM} = sub { die "Timeout" };
# Default TCP timeouts are too long. If we don't get a response
# within 20 seconds, then that's usually an indication that
# something is really wrong on the server side.
alarm(20);
$content = get_nice($url);
alarm(0);
};
unless ($@) {
# Everything is OK
# NOTE: utf-8 means "strict UTF-8 standard encoding"
$content = decode($encoding || "utf-8", $content);
last RETRY;
} elsif (($@ =~ /error: 500 Timeout/) && $retries--) {
# Let's try this one more time
carp "fetchRaw(): timeout. Retrying...";
} elsif ($nofail) {
# Caller requested not to fail
$content = "";
last RETRY;
} else {
# Fail on everything else
croak "fetchRaw(): $@";
}
}
debug(5, $content);
return($content);
}
# Fetch URL as parsed HTML::TreeBuilder
sub fetchTree($;$$$) {
my($url, $encoding, $nofail, $unknown) = @_;
my $content = fetchRaw($url, $encoding, $nofail);
my $tree = HTML::TreeBuilder->new();
$tree->ignore_unknown(!$unknown);
local $SIG{__WARN__} = sub { carp("fetchTree(): $_[0]") };
$tree->parse($content) or croak("fetchTree() parse failure for '$url'");
$tree->eof;
return($tree);
}
#
# Time zone handling
#
# After setting up the day list we switch to a fixed time zone in order to
# interpret the program start times from finnish sources. In this case we of
# course use
#
# Europe/Helsinki
#
# which can mean
#
# EET = GMT+02:00 (East European Time)
# EEST = GMT+03:00 (East European Summer Time)
#
# depending on the day of the year. By using a fixed time zone this grabber
# will always be able to correctly calculate the program start time in UTC,
# no matter what the time zone of the local system is.
#
# Test program:
# ---------------------- CUT HERE ---------------------------------------------
# use Time::Local;
# use POSIX qw(strftime tzset);
#
# # DST test days for Europe 2010
# my @testdays = (
# # hour, minute, mday, month
# [ 2, 00, 1, 1],
# [ 2, 59, 28, 3],
# [ 3, 00, 28, 3],
# [ 3, 01, 28, 3],
# [ 3, 00, 1, 7],
# [ 3, 59, 31, 10],
# [ 4, 00, 31, 10],
# [ 4, 01, 31, 10],
# [ 2, 00, 1, 12],
# );
#
# print strftime("System time zone is: %Z\n", localtime(time()));
# if (@ARGV) {
# $ENV{TZ} = "Europe/Helsinki";
# tzset();
# }
# print strftime("Script time zone is: %Z\n", localtime(time()));
#
# foreach my $date (@testdays) {
# my $time = timelocal(0, @{$date}[1, 0, 2], $date->[3] - 1, 2010);
# print
# "$time: ", strftime("%d-%b-%Y %T %z", localtime($time)),
# " -> ", strftime("%d-%b-%Y %T +0000", gmtime($time)), "\n";
# }
# ---------------------- CUT HERE ---------------------------------------------
#
# Test runs:
#
# 1) system on Europe/Helsinki time zone [REFERENCE]
#
# $ perl test.pl
# System time zone is: EET
# Script time zone is: EET
# 1262304000: 01-Jan-2010 02:00:00 +0200 -> 01-Jan-2010 00:00:00 +0000
# 1269737940: 28-Mar-2010 02:59:00 +0200 -> 28-Mar-2010 00:59:00 +0000
# 1269738000: 28-Mar-2010 04:00:00 +0300 -> 28-Mar-2010 01:00:00 +0000
# 1269738060: 28-Mar-2010 04:01:00 +0300 -> 28-Mar-2010 01:01:00 +0000
# 1277942400: 01-Jul-2010 03:00:00 +0300 -> 01-Jul-2010 00:00:00 +0000
# 1288486740: 31-Oct-2010 03:59:00 +0300 -> 31-Oct-2010 00:59:00 +0000
# 1288490400: 31-Oct-2010 04:00:00 +0200 -> 31-Oct-2010 02:00:00 +0000
# 1288490460: 31-Oct-2010 04:01:00 +0200 -> 31-Oct-2010 02:01:00 +0000
# 1291161600: 01-Dec-2010 02:00:00 +0200 -> 01-Dec-2010 00:00:00 +0000
#
# 2) system on America/New_York time zone
#
# $ TZ="America/New_York" perl test.pl
# System time zone is: EST
# Script time zone is: EST
# 1262329200: 01-Jan-2010 02:00:00 -0500 -> 01-Jan-2010 07:00:00 +0000
# 1269759540: 28-Mar-2010 02:59:00 -0400 -> 28-Mar-2010 06:59:00 +0000
# 1269759600: 28-Mar-2010 03:00:00 -0400 -> 28-Mar-2010 07:00:00 +0000
# 1269759660: 28-Mar-2010 03:01:00 -0400 -> 28-Mar-2010 07:01:00 +0000
# 1277967600: 01-Jul-2010 03:00:00 -0400 -> 01-Jul-2010 07:00:00 +0000
# 1288511940: 31-Oct-2010 03:59:00 -0400 -> 31-Oct-2010 07:59:00 +0000
# 1288512000: 31-Oct-2010 04:00:00 -0400 -> 31-Oct-2010 08:00:00 +0000
# 1288512060: 31-Oct-2010 04:01:00 -0400 -> 31-Oct-2010 08:01:00 +0000
# 1291186800: 01-Dec-2010 02:00:00 -0500 -> 01-Dec-2010 07:00:00 +0000
#
# 3) system on America/New_York time zone, script on Europe/Helsinki time zone
# [compare to output from (1)]
#
# $ TZ="America/New_York" perl test.pl switch
# System time zone is: EST
# Script time zone is: EET
# 1262304000: 01-Jan-2010 02:00:00 +0200 -> 01-Jan-2010 00:00:00 +0000
# 1269737940: 28-Mar-2010 02:59:00 +0200 -> 28-Mar-2010 00:59:00 +0000
# 1269738000: 28-Mar-2010 04:00:00 +0300 -> 28-Mar-2010 01:00:00 +0000
# 1269738060: 28-Mar-2010 04:01:00 +0300 -> 28-Mar-2010 01:01:00 +0000
# 1277942400: 01-Jul-2010 03:00:00 +0300 -> 01-Jul-2010 00:00:00 +0000
# 1288486740: 31-Oct-2010 03:59:00 +0300 -> 31-Oct-2010 00:59:00 +0000
# 1288490400: 31-Oct-2010 04:00:00 +0200 -> 31-Oct-2010 02:00:00 +0000
# 1288490460: 31-Oct-2010 04:01:00 +0200 -> 31-Oct-2010 02:01:00 +0000
# 1291161600: 01-Dec-2010 02:00:00 +0200 -> 01-Dec-2010 00:00:00 +0000
#
# Setup fixed time zone for program start time interpretation
sub setTimeZone() {
$ENV{TZ} = "Europe/Helsinki";
tzset();
}
# Take a fi::day (day/month/year) and the program start time (hour/minute)
# and convert it to seconds since Epoch in the current time zone
sub timeToEpoch($$$) {
my($date, $hour, $minute) = @_;
return(timelocal(0, $minute, $hour,
$date->day(), $date->month() - 1, $date->year()));
}
# Same thing but without fi::day object
sub fullTimeToEpoch($$$$$) {
my($year, $month, $day, $hour, $minute) = @_;
return(timelocal(0, $minute, $hour, $day, $month - 1, $year));
}
# That's all folks
1;
###############################################################################
package fi::day;
use strict;
use warnings;
use Carp;
use Date::Manip qw(DateCalc ParseDate UnixDate);
# Overload stringify operation
use overload '""' => "ymd";
# Constructor (private)
sub _new {
my($class, $day, $month, $year) = @_;
my $self = {
day => $day,
month => $month,
year => $year,
ymd => sprintf("%04d%02d%02d", $year, $month, $day),
ymdd => sprintf("%04d-%02d-%02d", $year, $month, $day),
dmy => sprintf("%02d.%02d.%04d", $day, $month, $year),
};
return(bless($self, $class));
}
# instance methods
sub day { $_[0]->{day} };
sub dmy { $_[0]->{dmy} };
sub month { $_[0]->{month} };
sub year { $_[0]->{year} };
sub ymd { $_[0]->{ymd} };
sub ymdd { $_[0]->{ymdd} };
# class methods
sub generate {
my($class, $offset, $days) = @_;
# Start one day before offset
my $date = DateCalc(ParseDate("today"), ($offset - 1) . " days")
or croak("can't calculate start day");
# End one day after offset + days
my @dates;
for (0..$days + 1) {
my($year, $month, $day) = split(':', UnixDate($date, "%Y:%m:%d"));
push(@dates, $class->_new(int($day), int($month), int($year)));
$date = DateCalc($date, "+1 day")
or croak("can't calculate next day");
}
return(\@dates);
}
# That's all folks
1;
###############################################################################
package fi::programme;
use strict;
use warnings;
use Carp;
use POSIX qw(strftime);
# Import from internal modules
fi::common->import();
sub _trim {
return unless defined($_[0]);
$_[0] =~ s/^\s+//;
$_[0] =~ s/\s+$//;
}
# Constructor
sub new {
my($class, $channel, $language, $title, $start, $stop) = @_;
_trim($title);
croak "${class}::new called without valid title or start"
unless defined($channel) && defined($title) && (length($title) > 0) &&
defined($start);
my $self = {
channel => $channel,
language => $language,
title => $title,
start => $start,
stop => $stop,
};
return(bless($self, $class));
}
# instance methods
sub category {
my($self, $category) = @_;
_trim($category);
$self->{category} = $category
if defined($category) && length($category);
}
sub description {
my($self, $description) = @_;
_trim($description);
$self->{description} = $description
if defined($description) && length($description);
}
sub episode {
my($self, $episode, $language) = @_;
_trim($episode);
if (defined($episode) && length($episode)) {
$episode =~ s/\.$//;
push(@{ $self->{episode} }, [$episode, $language]);
}
}
sub season_episode {
my($self, $season, $episode) = @_;
# only accept a pair of valid, positive integers
if (defined($season) && defined($episode)) {
$season = int($season);
$episode = int($episode);
if (($season > 0) && ($episode > 0)) {
$self->{season} = $season;
$self->{episode_number} = $episode;
}
}
}
sub start {
my($self, $start) = @_;
$self->{start} = $start
if defined($start) && length($start);
$start = $self->{start};
croak "${self}::start: object without valid start time"
unless defined($start);
return($start);
}
sub stop {
my($self, $stop) = @_;
$self->{stop} = $stop
if defined($stop) && length($stop);
$stop = $self->{stop};
croak "${self}::stop: object without valid stop time"
unless defined($stop);
return($stop);
}
# read-only
sub language { $_[0]->{language} }
sub title { $_[0]->{title} }
# Convert seconds since Epoch to XMLTV time stamp
#
# NOTE: We have to generate the time stamp using local time plus time zone as
# some XMLTV users, e.g. mythtv in the default configuration, ignore the
# XMLTV time zone value.
#
sub _epoch_to_xmltv_time($) {
my($time) = @_;
# Unfortunately strftime()'s %z is not portable...
#
# return(strftime("%Y%m%d%H%M%S %z", localtime($time));
#
# ...so we have to roll our own:
#
my @time = localtime($time); # is_dst
return(strftime("%Y%m%d%H%M%S +0", @time) . ($time[8] ? "3": "2") . "00");
}
# Configuration data
my %series_description;
my %series_title;
my @title_map;
my $title_strip_parental;
# Common regular expressions
# ($left, $special, $right) = ($description =~ $match_description)
my $match_description = qr/^\s*([^.!?]+[.!?])([.!?]+\s+)?\s*(.*)/;
sub dump {
my($self, $writer) = @_;
my $language = $self->{language};
my $title = $self->{title};
my $category = $self->{category};
my $description = $self->{description};
my $episode = $self->{episode_number};
my $season = $self->{season};
my $subtitle = $self->{episode};
#
# Programme post-processing
#
# Parental level removal (catch also the duplicates)
$title =~ s/(?:\s+\((?:S|T|7|9|12|16|18)\))+\s*$//
if $title_strip_parental;
#
# Title mapping
#
foreach my $map (@title_map) {
if ($map->($title)) {
debug(3, "XMLTV title '$self->{title}' mapped to '$title'");
last;
}
}
#
# Check 1: object already contains episode
#
my($left, $special, $right);
if (defined($subtitle)) {
# nothing to be done
}
#
# Check 2: title contains episode name
#
# If title contains a colon (:), check to see if the string on the left-hand
# side of the colon has been defined as a series in the configuration file.
# If it has, assume that the string on the left-hand side of the colon is
# the name of the series and the string on the right-hand side is the name
# of the episode.
#
# Example:
#
# config: series title Prisma
# title: Prisma: Totuus tappajadinosauruksista
#
# This will generate a program with
#
# title: Prisma
# sub-title: Totuus tappajadinosauruksista
#
elsif ((($left, $right) = ($title =~ /([^:]+):\s*(.*)/)) &&
(exists $series_title{$left})) {
debug(3, "XMLTV series title '$left' episode '$right'");
($title, $subtitle) = ($left, $right);
}
#
# Check 3: description contains episode name
#
# Check if the program has a description. If so, also check if the title
# of the program has been defined as a series in the configuration. If it
# has, assume that the first sentence (i.e. the text before the first
# period, question mark or exclamation mark) marks the name of the episode.
#
# Example:
#
# config: series description Batman
# description: Pingviinin paluu. Amerikkalainen animaatiosarja....
#
# This will generate a program with
#
# title: Batman
# sub-title: Pingviinin paluu
# description: Amerikkalainen animaatiosarja....
#
# Special cases
#
# text: Pingviinin paluu?. Amerikkalainen animaatiosarja....
# sub-title: Pingviinin paluu?
# description: Amerikkalainen animaatiosarja....
#
# text: Pingviinin paluu... Amerikkalainen animaatiosarja....
# sub-title: Pingviinin paluu...
# description: Amerikkalainen animaatiosarja....
#
# text: Pingviinin paluu?!? Amerikkalainen animaatiosarja....
# sub-title: Pingviinin paluu?!?
# description: Amerikkalainen animaatiosarja....
#
elsif ((defined $description) &&
(exists $series_description{$title}) &&
(($left, $special, $right) = ($description =~ $match_description))) {
my $desc_subtitle;
# Check for "Kausi <season>. Jakso <episode>/<# of episodes>. <sub-title>...."
if (my($desc_season, $desc_episode, $remainder) =
($description =~ m,^Kausi\s+(\d+)\.\s+Jakso\s+(\d+)(?:/\d+)?\.\s*(.*)$,)) {
$season = $desc_season;
$episode = $desc_episode;
# Repeat the above match on remaining description
($left, $special, $right) = ($remainder =~ $match_description);
# Check for "Kausi <season>, <episode>/<# of episodes>. <sub-title>...."
} elsif (($desc_season, $desc_episode, $remainder) =
($description =~ m!^Kausi\s+(\d+),\s+(\d+)(?:/\d+)?\.\s*(.*)$!)) {
$season = $desc_season;
$episode = $desc_episode;
# Repeat the above match on remaining description
($left, $special, $right) = ($remainder =~ $match_description);
# Check for "<sub-title>. Kausi <season>, <episode>/<# of episodes>...."
} elsif (($desc_subtitle, $desc_season, $desc_episode, $remainder) =
($description =~ m!^(.+)\s+Kausi\s+(\d+),\s+(\d+)(?:/\d+)?\.\s*(.*)$!)) {
$left = $desc_subtitle;
$season = $desc_season;
$episode = $desc_episode;
# Remainder is already the final episode description
$right = $remainder;
undef $special;
}
unless (defined $special) {
# We only remove period from episode title, preserve others
$left =~ s/\.$//;
} elsif (($left !~ /\.$/) &&
($special =~ /^\.\s/)) {
# Ignore extraneous period after sentence
} else {
# Preserve others, e.g. ellipsis
$special =~ s/\s+$//;
$left .= $special;
}
debug(3, "XMLTV series title '$title' episode '$left'");
($subtitle, $description) = ($left, $right);
}
# XMLTV programme desciptor (mandatory parts)
my %xmltv = (
channel => $self->{channel},
start => _epoch_to_xmltv_time($self->{start}),
stop => _epoch_to_xmltv_time($self->{stop}),
title => [[$title, $language]],
);
debug(3, "XMLTV programme '$xmltv{channel}' '$xmltv{start} -> $xmltv{stop}' '$title'");
# XMLTV programme descriptor (optional parts)
if (defined($subtitle)) {
$subtitle = [[$subtitle, $language]]
unless ref($subtitle);
$xmltv{'sub-title'} = $subtitle;
debug(3, "XMLTV programme episode ($_->[1]): $_->[0]")
foreach (@{ $xmltv{'sub-title'} });
}
if (defined($category) && length($category)) {
$xmltv{category} = [[$category, $language]];
debug(4, "XMLTV programme category: $category");
}
if (defined($description) && length($description)) {
$xmltv{desc} = [[$description, $language]];
debug(4, "XMLTV programme description: $description");
}
if (defined($season) && defined($episode)) {
$xmltv{'episode-num'} = [[ ($season - 1) . '.' . ($episode - 1) . '.', 'xmltv_ns' ]];
debug(4, "XMLTV programme season/episode: $season/$episode");
}
$writer->write_programme(\%xmltv);
}
# class methods
# Parse config line
sub parseConfigLine {
my($class, $line) = @_;
# Extract words
my($command, $keyword, $param) = split(' ', $line, 3);
if ($command eq "series") {
if ($keyword eq "description") {
$series_description{$param}++;
} elsif ($keyword eq "title") {
$series_title{$param}++;
} else {
# Unknown series configuration
return;
}
} elsif ($command eq "title") {
if (($keyword eq "map") &&
# Accept "title" and 'title' for each parameter
(my(undef, $from, undef, $to) =
($param =~ /^([\'\"])([^\1]+)\1\s+([\'\"])([^\3]+)\3/))) {
debug(3, "title mapping from '$from' to '$to'");
$from = qr/^\Q$from\E/;
push(@title_map, sub { $_[0] =~ s/$from/$to/ });
} elsif (($keyword eq "strip") &&
($param =~ /parental\s+level/)) {
debug(3, "stripping parental level from titles");
$title_strip_parental++;
} else {
# Unknown title configuration
return;
}
} else {
# Unknown command
return;
}
return(1);
}
# Fix overlapping programmes
sub fixOverlaps {
my($class, $list) = @_;
# No need to cleanup empty/one-entry lists
return unless defined($list) && (@{ $list } >= 2);
my $current = $list->[0];
foreach my $next (@{ $list }[1..$#{ $list }]) {
# Does next programme start before current one ends?
if ($current->{stop} > $next->{start}) {
debug(3, "Fixing overlapping programme '$current->{title}' $current->{stop} -> $next->{start}.");
$current->{stop} = $next->{start};
}
# Next programme
$current = $next;
}
}
# That's all folks
1;
###############################################################################
package fi::programmeStartOnly;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT = qw(startProgrammeList appendProgramme convertProgrammeList);
# Import from internal modules
fi::common->import();
sub startProgrammeList($$) {
my($id, $language) = @_;
return({
id => $id,
language => $language,
programmes => []
});
}
sub appendProgramme($$$$) {
my($self, $hour, $minute, $title) = @_;
# NOTE: start time in minutes from midnight -> must be converted to epoch
my $object = fi::programme->new($self->{id}, $self->{language},
$title, $hour * 60 + $minute);
push(@{ $self->{programmes} }, $object);
return($object);
}
sub convertProgrammeList($$$$) {
my($self, $yesterday, $today, $tomorrow) = @_;
my $programmes = $self->{programmes};
my $id = $self->{id};
# No data found -> return empty list
return unless @{ $programmes };
# Check for day crossing between first and second entry
my @dates = ($today, $tomorrow);
if ((@{ $programmes } > 1) &&
($programmes->[0]->start() > $programmes->[1]->start())) {
# Did caller specify yesterday?
if (defined $yesterday) {
unshift(@dates, $yesterday);
} else {
# No, assume the second entry is broken -> drop it
splice(@{ $programmes }, 1, 1);
}
}
my @objects;
my $date = shift(@dates);
my $current = shift(@{ $programmes });
my $current_start = $current->start();
my $current_epoch = timeToEpoch($date,
int($current_start / 60),
$current_start % 60);
foreach my $next (@{ $programmes }) {
# Start of next program might be on the next day
my $next_start = $next->start();
if ($current_start > $next_start) {
#
# Sanity check: try to detect fake day changes caused by broken data
#
# Incorrect date change example:
#
# 07:00 Voittovisa
# 07:50 Ostoskanava
# 07:20 F1 Ennakkolähetys <-- INCORRECT DAY CHANGE
# 07:50 Dino, pikku dinosaurus
# 08:15 Superpahisten liiga
#
# -> 07:50 (= 470) - 07:20 (= 440) = 30 minutes < 2 hours
#
# Correct date change example
#
# 22:35 Irene Huss: Tulitanssi
# 00:30 Formula 1: Extra
#
# -> 22:35 (= 1355) - 00:30 (= 30) = 1325 minutes > 2 hours
#
# I grabbed the 2 hour limit out of thin air...
#
if ($current_start - $next_start > 2 * 60) {
$date = shift(@dates);
# Sanity check
unless ($date) {
message("WARNING: corrupted data for $id on $today: two date changes detected. Ignoring data!");
return([]);
}
} else {
message("WARNING: corrupted data for $id on $today: fake date change detected. Ignoring.");
}
}
my $next_epoch = timeToEpoch($date,
int($next_start / 60),
$next_start % 60);
my $title = $current->title();
debug(3, "Programme $id ($current_epoch -> $next_epoch) $title");
# overwrite start & stop times with epoch: see appendProgramme()
$current->start($current_epoch);
$current->stop($next_epoch);
push(@objects, $current);
# Move to next program
$current = $next;
$current_start = $next_start;
$current_epoch = $next_epoch;
}
return(\@objects);
}
# That's all folks
1;
###############################################################################
package fi::source::foxtv;
use strict;
use warnings;
BEGIN {
our $ENABLED = 1;
}
# Import from internal modules
fi::common->import();
fi::programmeStartOnly->import();
# Cleanup filter regexes
my $cleanup_match = qr/\s*(?:\d+\.\s+Kausi\.\s+)?(?:Kausi\s+\d+\.\s+)?(?:Osa|Jakso)\s+\d+\.\s*/i;
# Description
sub description { 'foxtv.fi' }
# Grab channel list - only one channel available, no need to fetch anything...
sub channels { { 'foxtv.fi' => 'fi FOX' } }
# Extract programmes for one day
sub _programmes($$) {
my($table_entries, $wday) = @_;
return if ($wday > 6);
my $entry = $table_entries->[$wday + 1];
return unless $entry;
return($entry->look_down("class" => qr/^itemListings/));
}
# Extract start time and return (hour, minute) or undef
sub _start($) {
my($programme) = @_;
my $start = $programme->look_down("rel" => "colorbox");
return unless $start;
$start = $start->find("span");
return unless $start;
return($start->as_text() =~ /^(\d{2}):(\d{2})/);
}
# Grab one day
sub grab {
my($self, $id, $yesterday, $today, $tomorrow, $offset) = @_;
# Get channel number from XMLTV id
return unless ($id eq "foxtv.fi");
#
# Only the weekly page contains all the information we need. Each of the 7
# days in a week will return the same weekly information, although the URL
# will be different. This will break XMLTV caching.
#
# The weekly page starts on Monday. We simply calculate what the Monday of
# the week is that contains the day we want to grab.
#
my $wday;
my $url;
{
# Epoch of today at 12:00
my $epoch = timeToEpoch($today, 12, 0);
# localtime weekday: 0: Sunday, 1: Monday, ..., 6: Saturday
# foxtv.fi weekday: 0: Monday, 1: Tuesday, ..., 6: Sunday
$wday = ((localtime($epoch))[6] + 6) % 7;
# Epoch of today (if it is Monday) or the previous Monday, at
# 11:00 if Monday (standard time) -> today (daylight saving time)
# 12:00 if no daylight saving change during the week
# 13:00 if Monday (daylight saving time) -> today (standard time)
my($mday, $mon, $year) = (localtime($epoch - $wday * 86400))[3..5];
$mon += 1;
$year += 1900;
# URL for weekly page
$url = "http://www.foxtv.fi/ohjelmat/weekly/$mday.$mon.$year";
}
# Fetch & parse HTML
my $root = fetchTree($url);
if ($root) {
my $opaque = startProgrammeList($id, "fi");
#
# All program info is contained in a table column *without* class
#
# <table class="bloque-slider">
# <tr>
# <td class="calendarHours"> [Index 0]
# ... one list item per hour ...
# </td>
# <td> [Index 1: Monday -> $wday + 1]
# <div class="itemListings halfHour ">
# <a href=... rel="colorbox">
# ...
# <span>00:55</span>
# ...
# </a>
# <div id="ShowDetailsOverlay" class="ShowDetails ">
# ...
# <div class="Content">
# <h4>Low Winter Sun</h4>
# ...
# <div class="Details colLeft">
# <h5 class="ShowTitle colLeft">Tuotantokausi 1</h5>
# <h5 class="ShowTitle colLeft">
# Jakso 10
# </h5>
# <p>sunnuntain myöhäisilloissa </p>
# ...
# </div>
# <div class="ShowDescription colLeft">Murhien, petosten, koston ja korruption värittämän modernin draamasarjan päähenkilönä on etsivä Frank Agnew.</div>
# ...
# </div>
# </div>
# </div>
# </td>
# <td> [Index 2: Tuesday]
# ...
# </tr>
# </table>
#
if (my $container = $root->look_down("class" => "bloque-slider")) {
if (my @table_entries = $container->find("td")) {
my @programmes_today = _programmes(\@table_entries, $wday);
my $first_tomorrow = _programmes(\@table_entries, $wday + 1);
if (@programmes_today) {
foreach my $programme (@programmes_today) {
my($hour, $minute) = _start($programme);
my $details = $programme->look_down("class" => "Content");
if ($hour && $minute && $details) {
my $desc = $details->look_down("class" => "ShowDescription colLeft");
my $title = $details->find("h4");
if ($desc && $title) {
my($season, $episode_number) = $programme->look_down("class" => "ShowTitle colLeft");
my $episode_name = $programme->find("p");
$title = $title->as_text();
$desc = $desc->as_text();
# Season, episode number & episode name (optional)
($season) = ($season->as_text() =~ /(\d+)/)
if $season;
($episode_number) = ($episode_number->as_text() =~ /(\d+)/)
if $episode_number;
($episode_name) = ($episode_name->as_text() =~ /^\s*(.+)$/)
if $episode_name;
# Cleanup some of the most common inconsistencies....
$desc =~ s/^$cleanup_match//o
if defined($desc);
if (defined($episode_name)) {
$episode_name =~ s/$cleanup_match//o;
$episode_name =~ s/\s+$//;
if (defined($desc)) {
# Strip optional parental guidance to improve following match
my $tmp;
($tmp = $episode_name) =~ s/\s+\((?:\d+|S)\)$//;
$desc =~ s/^$tmp\.\s+//;
}
}
# Description can be empty or "-"
undef $desc if ($desc eq '') || ($desc eq '-');
# Episode name can be the same as the title
undef $episode_name
if defined($episode_name) &&
(($episode_name eq '') || ($episode_name eq $title));
debug(3, "List entry fox ($hour:$minute) $title");
debug(4, $episode_name) if defined $episode_name;
debug(4, $desc) if defined $desc;
debug(4, sprintf("s%02de%02d", $season, $episode_number))
if (defined($season) && defined($episode_number));
my $object = appendProgramme($opaque, $hour, $minute, $title);
$object->description($desc);
$object->episode($episode_name, "fi");
$object->season_episode($season, $episode_number);
}
}
}
# Get stop time for last entry in the table: first start
if ($first_tomorrow) {
my($hour, $minute) = _start($first_tomorrow);
appendProgramme($opaque, $hour, $minute, "DUMMY")
if ($hour && $minute);
}
}
}
}
# Done with the HTML tree
$root->delete();
# Convert list to program objects
#
# First entry always starts on $today -> don't use $yesterday
# Last entry always ends on $tomorrow.
#
# Unfortunately we don't have a stop time for the last entry. We fix this
# (see above) by adding the start time of the first entry from tomorrow
# as a DUMMY program. This works for Monday to Saturday, but not for
# Sunday :-(
return(convertProgrammeList($opaque, undef, $today, $tomorrow));
}
return;
}
# That's all folks
1;
###############################################################################
package fi::source::iltapulu;
use strict;
use warnings;
#
# NOTE: this data source was earlier known as http://tv.hs.fi
# NOTE: this data source was earlier known as http://tv.tvnyt.fi
#
BEGIN {
our $ENABLED = 1;
}
use Carp;
# Import from internal modules
fi::common->import();
# Description
sub description { 'iltapulu.fi' }
# Grab channel list
sub channels {
my %channels;
# Fetch & parse HTML
my $root = fetchTree("http://www.iltapulu.fi/?&all=1");
if ($root) {
#
# Channel list can be found in table rows
#
# <table class="channel-row">
# <tbody>
# <tr>
# <td class="channel-name">...</td>
# <td class="channel-name">...</td>
# ...
# </tr>
# </tbody>
# ...
# </table>
# ...
#
if (my @tables = $root->look_down("class" => "channel-row")) {
foreach my $table (@tables) {
if (my @cells = $table->look_down("class" => "channel-name")) {
foreach my $cell (@cells) {
if (my $image = $cell->find("img")) {
my $name = $image->attr("alt");
$name =~ s/\s+tv-ohjelmat$//;
if (defined($name) && length($name)) {
my $channel_id = (scalar(keys %channels) + 1) . ".iltapulu.fi";
debug(3, "channel '$name' ($channel_id)");
$channels{$channel_id} = "fi $name";
}
}
}
}
}
}
# Done with the HTML tree
$root->delete();
}
debug(2, "Source iltapulu.fi parsed " . scalar(keys %channels) . " channels");
return(\%channels);
}
# Grab one day
sub grab {
my($self, $id, $yesterday, $today, $tomorrow, $offset) = @_;
# Get channel number from XMLTV id
return unless my($channel) = ($id =~ /^([-\w]+)\.iltapulu\.fi$/);
# Fetch & parse HTML
my $root = fetchTree("http://www.iltapulu.fi/?all=1&date=" . $today->ymdd());
if ($root) {
my $count = 0;
my @objects;
#
# Programme data is contained inside a div class="<full-row>"
#
# <table class="channel-row">
# <tbody>
# <tr>
# <td class="channel-name">...</td>
# <td class="channel-name">...</td>
# ...
# </tr>
# <tr class="full-row...">
# <td>
# <div class="schedule">
# <div class="full-row" data-starttime="1424643300" data-endtime="1424656800">
# <table>
# <tr>
# <td class="time">00.15</td>
# <td class="title[ movie]">
# <a class="program-open..." ... title="... description ...">
# Uutisikkuna
# </a>
# </td>
# </tr>
# </table>
# </div>
# </div>
# ...
# </td>
# ...
# </tr>
# ...
# </tbody>
# </table>
# ...
#
if (my @tables = $root->look_down("class" => "channel-row")) {
TABLES:
foreach my $table (@tables) {
if (my @cells = $table->look_down("class" => "channel-name")) {
# Channel in this table?
my $index = $channel - $count - 1;
$count += @cells;
if ($channel <= $count) {
# Extract from each row the div's from the same index
my @divs;
if (my @rows = $table->look_down("_tag" => "tr",
"class" => qr/full-row/)) {
foreach my $row (@rows) {
my $children = $row->content_array_ref;
if ($children) {
my $td = $children->[$index];
push(@divs, $td->look_down("class" => "full-row"))
if defined($td);
}
}
}
for my $div (@divs) {
my $start = $div->attr("data-starttime");
my $end = $div->attr("data-endtime");
my $link = $div->look_down("class" => qr/program-open/);
if ($start && $end && $link) {
my $title = $link->as_text();
if (length($title)) {
my $desc = $link->attr("title");
my $category = ($link->parent()->attr("class") =~ /movie/) ? "elokuvat" : undef;
debug(3, "List entry ${id} ($start -> $end) $title");
debug(4, $desc) if $desc;
debug(4, $category) if defined $category;
# Create program object
my $object = fi::programme->new($id, "fi", $title, $start, $end);
$object->category($category);
$object->description($desc);
push(@objects, $object);
}
}
}
# skip the rest of the data
last TABLES;
}
}
}
}
# Done with the HTML tree
$root->delete();
# Fix overlapping programmes
fi::programme->fixOverlaps(\@objects);
return(\@objects);
}
return;
}
# That's all folks
1;
###############################################################################
package fi::source::telkku;
use strict;
use warnings;
BEGIN {
our $ENABLED = 1;
}
# Import from internal modules
fi::common->import();
fi::programmeStartOnly->import();
# Description
sub description { 'telkku.com' }
# Grab channel list
sub channels {
# Fetch & parse HTML
my $root = fetchTree("http://www.telkku.com/channel");
if ($root) {
my %channels;
#
# Channel list can be found from the left sidebar
#
# <div class="l-wrap l-grid--16" id="channelContainer">
# ...
# <ul>
# <li><a href="http://www.telkku.com/channel/list/8/20101218">4 Sport</a></li>
# <li><a href="http://www.telkku.com/channel/list/24/20101218">4 Sport Pro</a></li>
# ...
# <li><a href="http://www.telkku.com/channel/list/87/20101218">Viron ETV</a></li>
# <li><a href="http://www.telkku.com/channel/list/10/20101218">YLE Teema</a></li>
# </ul>
# </div>
#
if (my $container = $root->look_down("id" => "channelContainer")) {
if (my @list = $container->find("li")) {
debug(2, "Source telkku.com found " . scalar(@list) . " channels");
foreach my $list_entry (@list) {
if (my $link = $list_entry->find("a")) {
my $href = $link->attr("href");
my $name = $link->as_text();
if (defined($href) && length($name) &&
(my($channel_no) = ($href =~ m,channel/list/(\d+)/,))) {
debug(3, "channel '$name' ($channel_no)");
$channels{"${channel_no}.telkku.com"} = "fi $name";
}
}
}
}
}
# Done with the HTML tree
$root->delete();
debug(2, "Source telkku.com parsed " . scalar(keys %channels) . " channels");
return(\%channels);
}
return;
}
#
# http://www.telkku.com/movie contains information about (all?) movies for
# today and the next 7 days, i.e. offsets 0 to 7. We extract the URL to the
# detailed programme information (http://www.telkku.com/program/show/......)
# that can then be used to identify movies when processing programme entries.
#
{
my %ids;
sub _getMovieIDsForOffset($) {
my($offset) = @_;
# There is only data for the next 7 days
return({}) if $offset > 7;
# Reuse cached data
return(\%ids) if %ids;
# In order to reduce website traffic, we only try this once
$ids{__DUMMY_ID_THAT_NEVER_MATCHES__}++;
# Fetch & parse HTML (do not ignore HTML5 <section>)
# This is entirely optional, so please don't abort on failure...
my $root = fetchTree("http://www.telkku.com/movie", undef, 1, 1);
if ($root) {
my $test;
#
# Document structure for movie entries:
#
# <li class="l-embed theme-hr program">
# ...
# <section class="l-embed__bd program__content">
# <a href="http://www.telkku.com/program/show/2014061910151">
# ...
# </a>
# </section>
# </li>
#
debug(2, "Source telkku.com provided movie data");
if (my @list = $root->look_down("class" => qr/program__content/)) {
debug(2, "Source telkku.com found " . scalar(@list) . " movies");
foreach my $list_entry (@list) {
if (my $link = $list_entry->find("a")) {
my $href = $link->attr("href");
if (defined($href) && length($href)) {
debug(3, "movie ID: " . $href);
$ids{$href}++;
}
}
}
}
# Done with the HTML tree
$root->delete();
}
debug(2, "Source telkku.com parsed " . (scalar(keys %ids) - 1) . " movies");
return(\%ids);
}
}
# Grab one day
sub grab {
my($self, $id, $yesterday, $today, $tomorrow, $offset) = @_;
# Get channel number from XMLTV id
return unless my($channel) = ($id =~ /^(\d+)\.telkku\.com$/);
# Fetch & parse HTML
my $root = fetchTree("http://www.telkku.com/channel/list/$channel/$today");
if ($root) {
my $movie_ids = _getMovieIDsForOffset($offset);
#
# All program info is contained within a unsorted list with class "programList"
#
# <ul class="l-stack programList">
# <li>
# <a class="program" href="http://www.telkku.com/program/show/2012100920451">
# <div class="theme-hr program__content">
# <div class="program__desc">
# <div class="h4 program__title">23:45 Uutisikkuna</div>
# <div class="progrram__desc">...</div>
# </div>
# </div>
# </a>
# </li>
# ...
# </ul>
#
my $opaque = startProgrammeList($id, "fi");
if (my $container = $root->look_down("class" => "l-stack programList")) {
if (my @list = $container->find("li")) {
foreach my $list_entry (@list) {
my $link = $list_entry->look_down("class", "program");
my $title = $list_entry->look_down("class", "h4 program__title");
my $desc = $list_entry->look_down("class", "progrram__desc");
if ($link && $title && $desc) {
my $date;
# Extract texts from HTML elements. Entities are already decoded.
$date = $title->as_text();
$desc = $desc->as_text();
# Use "." to match character (it's not included in \s?)
if (my($hour, $minute, $title) =
$date =~ /^(\d{2}):(\d{2}).(.+)/) {
my $href = $link->attr("href");
my $category = (defined($href) && exists($movie_ids->{$href})) ?
"elokuvat" : undef;
debug(3, "List entry $channel ($hour:$minute) $title");
debug(4, $desc);
debug(4, $category) if defined $category;
# Only record entry if title isn't empty
if (length($title) > 0) {
my $object = appendProgramme($opaque, $hour, $minute, $title);
$object->category($category);
$object->description($desc);
}
}
}
}
}
}
# Done with the HTML tree
$root->delete();
# Each page on telkku.com contains the program information
# for one channel for one whole day.
#
# Example (compiled from several pages for illustration):
#
# /- start time (day)
# | /- program title
# | |
# [23:45 Uutisikkuna (yesterday)]
# 00:10 Uutisikkuna (today )
# ...
# 23:31 Uusi päivä (today )
# 00:00 Kova laki (tomorrow )
# [00:40 Piilosana (tomorrow )]
# [01:00 Tellus-tietovisa (tomorrow )]
#
# The lines in [] don't appear on every page.
#
# Convert list to program objects
return(convertProgrammeList($opaque, $yesterday, $today, $tomorrow));
}
return;
}
# That's all folks
1;
###############################################################################
package fi::source::telvis;
use strict;
use warnings;
BEGIN {
our $ENABLED = 1;
}
# Import from internal modules
fi::common->import();
fi::programmeStartOnly->import();
# Description
sub description { 'telvis.fi' }
# Grab channel list
sub channels {
my %channels;
# Fetch & parse HTML
my $root = fetchTree("http://www.telvis.fi/tvohjelmat/?vw=channel",
"iso-8859-1");
if ($root) {
#
# Channel list can be found in multiple <div> nodes
#
# <div class="progs" style="text-align:left;">
# <a href="/tvohjelmat/?vw=channel&ch=tv1&sh=new&dy=03.02.2011">YLE TV1</a>
# <a href="/tvohjelmat/?vw=channel&ch=tv2&sh=new&dy=03.02.2011">YLE TV2</a>
# ...
# </div>
#
if (my @containers = $root->look_down("class" => "progs")) {
foreach my $container (@containers) {
if (my @refs = $container->find("a")) {
debug(2, "Source telvis.fi found " . scalar(@refs) . " channels");
foreach my $ref (@refs) {
my $href = $ref->attr("href");
my $name = $ref->as_text();
if (defined($href) && length($name) &&
(my($id) = ($href =~ m,vw=channel&ch=([^&]+)&,))) {
debug(3, "channel '$name' ($id)");
$channels{"${id}.telvis.fi"} = "fi $name";
}
}
}
}
}
# Done with the HTML tree
$root->delete();
} else {
return;
}
debug(2, "Source telvis.fi parsed " . scalar(keys %channels) . " channels");
return(\%channels);
}
# Grab one day
sub grab {
my($self, $id, $yesterday, $today, $tomorrow, $offset) = @_;
# Get channel number from XMLTV id
return unless my($channel) = ($id =~ /^([^.]+)\.telvis\.fi$/);
# Fetch & parse HTML
my $root = fetchTree("http://www.telvis.fi/lite/?vw=channel&ch=${channel}&dy=" . $today->dmy(),
"iso-8859-1");
if ($root) {
#
# Each programme can be found in a separate <tr> node under a <div> node
#
# <div class="tm">
# <table>
# ...
# <tr>
# <td valign="top"><strong>13:50</strong></td>
# <td><strong>Serranon perhe</strong>
# Suuret sanat suuta halkovat. Diego kertoo perheelleen suhteestaan Celiaan. Reaktiot pistävät miehelle jauhot suuhun. Ana pyytää Fitiltä palvelusta, josta tämä on otettu. Santi hoitaa Lourditasin asioita omin päin.
# </td>
# </tr>
# <tr class="zeb">
# <td valign="top"><strong>15:15</strong></td>
# <td><strong>Gilmoren tytöt</strong>
# Välirikko. Emily yrittää tuoda Christopherin takaisin perheensä piiriin, mutta Rory on saanut aina poissaolevasta isästä tarpeekseen. Lorelaita piirittää jälleen uusi ihailija.
# </td>
# </tr>
# ...
# </table>
# </div>
#
my $opaque = startProgrammeList($id, "fi");
if (my $container = $root->look_down("class" => "tm")) {
if (my @rows = $container->find("tr")) {
foreach my $row (@rows) {
my @columns = $row->find("td");
if (@columns == 2) {
my $start = $columns[0]->find("strong");
my $title = $columns[1]->find("strong");
if ($start && $title) {
$start = $start->as_text();
$title = $title->as_text();
if (my($hour, $minute) = ($start =~ /^(\d{2}):(\d{2})/)) {
my $desc = $columns[1]->as_text(); # includes $title
$desc =~ s/^\Q$title\E\s+//;
debug(3, "List entry $channel ($hour:$minute) $title");
debug(4, $desc);
# Only record entry if title isn't empty
if (length($title) > 0) {
my $object = appendProgramme($opaque, $hour, $minute, $title);
$object->description($desc);
}
}
}
}
}
}
}
# Done with the HTML tree
$root->delete();
# Convert list to program objects
#
# First entry always starts on $today -> don't use $yesterday
# Last entries always end on $tomorrow
#
# Unfortunately the last entry of $today is not the first entry of
# $tomorrow. That means that the last entry will always be missing as we
# don't have a stop time for it :-(
return(convertProgrammeList($opaque, undef, $today, $tomorrow));
}
return;
}
# That's all folks
1;
###############################################################################
package fi::source::yle;
use strict;
use warnings;
use Date::Manip;
BEGIN {
our $ENABLED = 1;
}
# Import from internal modules
fi::common->import();
fi::programmeStartOnly->import();
# Description
sub description { 'yle.fi' }
my %languages = (
"fi" => "ohjelmaopas",
"sv" => "programguide",
);
# Grab channel list
sub channels {
my %channels;
# yle.fi offers program guides in multiple languages
foreach my $code (sort keys %languages) {
# Fetch & parse HTML
my $root = fetchTree("http://$languages{$code}.yle.fi/tv/opas");
if ($root) {
#
# Channel list can be found from this list:
#
# <ul class="channel-lists ...">
# <li><h1 id="yle-tv1">Yle TV1...</h1>...</li>
# <li><h1 id="yle-tv2">Yle TV2...</h1>...</li>
# ...
# </ul>
#
if (my $container = $root->look_down("class" => qr/^channel-lists\s+/)) {
if (my @headers = $container->find("h1")) {
debug(2, "Source ${code}.yle.fi found " . scalar(@headers) . " channels");
foreach my $header (@headers) {
my $id = $header->attr("id");
my $name = $header->as_text();
if (defined($id) && length($id) && length($name)) {
debug(3, "channel '$name' ($id)");
$channels{"${id}.${code}.yle.fi"} = "$code $name";
}
}
}
}
# Done with the HTML tree
$root->delete();
} else {
return;
}
}
debug(2, "Source yle.fi parsed " . scalar(keys %channels) . " channels");
return(\%channels);
}
# Grab one day
sub grab {
my($self, $id, $yesterday, $today, $tomorrow, $offset) = @_;
# Get channel number from XMLTV id
return unless my($channel, $code) = ($id =~ /^([^.]+)\.([^.]+)\.yle\.fi$/);
# Fetch & parse HTML (do not ignore HTML5 <time>)
my $root = fetchTree("http://$languages{$code}.yle.fi/tv/opas?t=" . $today->ymdd(),
undef, undef, 1);
if ($root) {
my @objects;
#
# Each programme can be found in a separate <li> node
#
# <ul class="channel-lists ...">
# <li>
# <h1 id="yle-tv1">Yle TV1...</h1>
# <ul>
# <li class="program-entry ...">
# <div class="program-label">
# <time class="dtstart" datetime="2014-06-15T01:30:00.000+03:00">01:30</time>
# <time class="dtend" datetime="2014-06-15T04:30:00.000+03:00"></time>
# <div class="program-title">
# ...
# <a class="link-grey" href="...">Suunnistuksen Jukolan viesti</a>
# <span class="label movie">Elokuva</span>
# ...
# </div>
# </div>
# ...
# <div class="program-desc">
# <p>66. Jukolan viesti. Kolmas, neljäs ja viides osuus...
# ...
# </p>
# </div>
# </li>
# ...
# </ul>
# ...
# </li>
# </ul>
#
if (my $container = $root->look_down("class" => qr/^channel-lists\s+/)) {
if (my $header = $container->look_down("_tag" => "h1",
"id" => $channel)) {
if (my $parent = $header->parent()) {
if (my @programmes = $parent->look_down("class" => qr/^program-entry\s+/)) {
foreach my $programme (@programmes) {
my $start = $programme->look_down("class", "dtstart");
my $end = $programme->look_down("class", "dtend");
my $title = $programme->look_down("class", "program-title");
my $desc = $programme->look_down("class", "program-desc");
if ($start && $end && $title && $desc) {
$start = UnixDate($start->attr("datetime"), "%s");
$end = UnixDate($end->attr("datetime"), "%s");
my $link = $title->find("a");
my $category = $title->look_down("class" => "label movie") ? "elokuvat" : undef;
# NOTE: entries with same start and end time are invalid
if ($start && $end && $link && ($start != $end)) {
$title = $link->as_text();
$title =~ s/^\s+//;
$title =~ s/\s+$//;
if (length($title)) {
$desc = $desc->find("p");
$desc = $desc ? $desc->as_text() : "";
$desc =~ s/^\s+//;
$desc =~ s/\s+$//;
debug(3, "List entry $channel ($start -> $end) $title");
debug(4, $desc);
debug(4, $category) if defined $category;
# Create program object
my $object = fi::programme->new($id, $code, $title, $start, $end);
$object->category($category);
$object->description($desc);
push(@objects, $object);
}
}
}
}
}
}
}
}
# Done with the HTML tree
$root->delete();
# Fix overlapping programmes
fi::programme->fixOverlaps(\@objects);
return(\@objects);
}
return;
}
# That's all folks
1;
###############################################################################
###############################################################################
package main;
# Perl core modules
use Getopt::Long;
use List::Util qw(shuffle);
use Pod::Usage;
# Generate source module list
my @sources;
BEGIN {
@sources = map { s/::$//; $_ }
map { "fi::source::" . $_ }
sort
grep { ${ $::{'fi::'}->{'source::'}->{$_}->{ENABLED} } }
keys %{ $::{'fi::'}->{'source::'} };
die "$0: couldn't find any source modules?" unless @sources;
}
# Import from internal modules
fi::common->import(':main');
# Basic XMLTV modules
use XMLTV::Version "generated from\n\ttv_grab_fi.pl 2.05 2014/06/21 16:36:15\n\tcommon.pm 2.06 2015/02/24 18:41:32\n\tday.pm 2.01 2014/06/14 18:18:36\n\tprogramme.pm 2.07 2015/06/08 17:14:01\n\tprogrammeStartOnly.pm 2.02 2013/11/04 11:40:17\n\tfoxtv.pm 2.02 2013/11/20 07:58:21\n\tiltapulu.pm 2.08 2015/02/23 18:09:21\n\ttelkku.pm 2.05 2014/06/21 16:36:15\n\ttelvis.pm 2.04 2015/02/24 18:41:32\n\tyle.pm 2.10 2015/02/24 18:41:32";
use XMLTV::Capabilities qw(baseline manualconfig cache);
use XMLTV::Description 'Finland (' .
join(', ', map { $_->description() } @sources ) .
')';
# NOTE: We will only reach the rest of the code only when the script is called
# without --version, --capabilities or --description
# Reminder of XMLTV modules
use XMLTV::Get_nice;
use XMLTV::Memoize;
###############################################################################
#
# Main program
#
###############################################################################
# Forward declarations
sub doConfigure();
sub doListChannels();
sub doGrab();
# Command line option default values
my %Option = (
days => 14,
quiet => 0,
debug => 0,
offset => 0,
);
# Enable caching. This will remove "--cache [file]" from @ARGV
XMLTV::Memoize::check_argv('XMLTV::Get_nice::get_nice_aux');
# Process command line options
if (GetOptions(\%Option,
"configure",
"config-file=s",
"days=i",
"debug|d+",
"gui:s",
"help|h|?",
"list-channels",
"no-randomize",
"offset=i",
"output=s",
"quiet",
"test-mode")) {
pod2usage(-exitstatus => 0,
-verbose => 2)
if $Option{help};
setDebug($Option{debug});
setQuiet($Option{quiet});
if ($Option{configure}) {
# Configure mode
doConfigure();
} elsif ($Option{'list-channels'}) {
# List channels mode
doListChannels();
} else {
# Grab mode (default)
doGrab();
}
} else {
pod2usage(2);
}
# That's all folks
exit 0;
###############################################################################
#
# Utility functions for the different modes
#
###############################################################################
sub _getConfigFile() {
require XMLTV::Config_file;
return(XMLTV::Config_file::filename($Option{'config-file'},
"tv_grab_fi",
$Option{quiet}));
}
{
my $ofh;
sub _createXMLTVWriter() {
# Output file handling
$ofh = \*STDOUT;
if (defined $Option{output}) {
open($ofh, ">", $Option{output})
or die "$0: cannot open file '$Option{output}' for writing: $!";
}
# Create XMLTV writer for UTF-8 encoded text
binmode($ofh, ":utf8");
my $writer = XMLTV::Writer->new(
encoding => 'UTF-8',
OUTPUT => \*STDOUT,
);
#### HACK CODE ####
$writer->start({
"generator-info-name" => "XMLTV",
"generator-info-url" => "http://xmltv.org/",
"source-info-url" => "multiple", # TBA
"source-data-url" => "multiple", # TBA
});
#### HACK CODE ####
return($writer);
}
sub _closeXMLTVWriter($) {
my($writer) = @_;
$writer->end();
# close output file
if ($Option{output}) {
close($ofh) or die "$0: write error on file '$Option{output}': $!";
}
message("DONE");
}
}
sub _addChannel($$$$) {
my($writer, $id, $name, $language) = @_;
$writer->write_channel({
id => $id,
'display-name' => [[$name, $language]],
});
}
{
my $bar;
sub _createProgressBar($$) {
my($label, $count) = @_;
return if $Option{quiet};
require XMLTV::Ask;
require XMLTV::ProgressBar;
XMLTV::Ask::init($Option{gui});
$bar = XMLTV::ProgressBar->new({
name => $label,
count => $count,
});
}
sub _updateProgressBar() { $bar->update() if defined $bar }
sub _destroyProgressBar() { $bar->finish() if defined $bar }
}
sub _getChannels($$) {
my($callback, $opaque) = @_;
# Get channels from all sources
_createProgressBar("getting list of channels", @sources);
foreach my $source (@sources) {
debug(1, "requesting channel list from source '" . $source->description ."'");
if (my $list = $source->channels()) {
die "test failure: source '" . $source->description . "' didn't find any channels!\n"
if ($Option{'test-mode'} && (keys %{$list} == 0));
while (my($id, $value) = each %{ $list }) {
my($language, $name) = split(" ", $value, 2);
$callback->($opaque, $id, $name, $language);
}
}
_updateProgressBar();
}
_destroyProgressBar();
}
###############################################################################
#
# Configure Mode
#
###############################################################################
sub doConfigure() {
# Get configuration file name
my $file = _getConfigFile();
XMLTV::Config_file::check_no_overwrite($file);
# Open configuration file. Assume UTF-8 encoding
open(my $fh, ">:utf8", $file)
or die "$0: can't open configuration file '$file': $!";
print $fh "# -*- coding: utf-8 -*-\n";
# Get channels
my %channels;
_getChannels(sub {
# We only need name and ID
my(undef, $id, $name) = @_;
$channels{$id} = $name;
},
undef);
# Query user
my @sorted = sort keys %channels;
my @answers = XMLTV::Ask::ask_many_boolean(1, map { "add channel $channels{$_} ($_)?" } @sorted);
# Generate configuration file contents from answers
foreach my $id (@sorted) {
warn("\nunexpected end of input reached\n"), last
unless @answers;
# Write selection to configuration file
my $answer = shift(@answers);
print $fh ($answer ? "" : "#"), "channel $id $channels{$id}\n";
}
# Check for write errors
close($fh)
or die "$0: can't write to configuration file '$file': $!";
message("DONE");
}
###############################################################################
#
# List Channels Mode
#
###############################################################################
sub doListChannels() {
# Create XMLTV writer
my $writer = _createXMLTVWriter();
# Get channels
_getChannels(sub {
my($writer, $id, $name, $language) = @_;
_addChannel($writer, $id, $name, $language);
},
$writer);
# Done writing
_closeXMLTVWriter($writer);
}
###############################################################################
#
# Grab Mode
#
###############################################################################
sub doGrab() {
# Sanity check
die "$0: --offset must be a non-negative integer"
unless $Option{offset} >= 0;
die "$0: --days must be an integer larger than 0"
unless $Option{days} > 0;
# Get configuation
my %channels;
{
# Get configuration file name
my $file = _getConfigFile();
# Open configuration file. Assume UTF-8 encoding
open(my $fh, "<:utf8", $file)
or die "$0: can't open configuration file '$file': $!";
# Process configuration information
while (<$fh>) {
# Comment removal, white space trimming and compressing
s/\#.*//;
s/^\s+//;
s/\s+$//;
next unless length; # skip empty lines
s/\s+/ /;
# Channel definition
if (my($id, $name) = /^channel (\S+) (.+)/) {
debug(1, "duplicate channel definion in line $.:$id ($name)")
if exists $channels{$id};
$channels{$id} = $name;
# Programme definition
} elsif (fi::programme->parseConfigLine($_)) {
# Nothing to be done here
} else {
warn("bad configuration line in file '$file', line $.: $_\n");
}
}
close($fh);
}
# Generate list of days
my $dates = fi::day->generate($Option{offset}, $Option{days});
# Set up time zone
setTimeZone();
# Create XMLTV writer
my $writer = _createXMLTVWriter();
# Generate task list with one task per channel and day
my @tasklist;
foreach my $id (sort keys %channels) {
for (my $i = 1; $i < $#{ $dates }; $i++) {
push(@tasklist, [$id,
@{ $dates }[$i - 1..$i + 1],
$Option{offset} + $i - 1]);
}
}
# Randomize the task list in order to create a random access pattern
# NOTE: if you use only one source, then this is basically a no-op
if (not $Option{'no-randomize'}) {
debug(1, "Randomizing task list");
@tasklist = shuffle(@tasklist);
}
# For each entry in the task list
my %seen;
my @programmes;
_createProgressBar("getting listings", @tasklist);
foreach my $task (@tasklist) {
my($id, $yesterday, $today, $tomorrow, $offset) = @{$task};
debug(1, "XMLTV channel ID '$id' fetching day $today");
foreach my $source (@sources) {
if (my $programmes = $source->grab($id,
$yesterday, $today, $tomorrow,
$offset)) {
if (@{ $programmes }) {
# Add channel ID & name (once)
_addChannel($writer, $id, $channels{$id},
$programmes->[0]->language())
unless $seen{$id}++;
# Add programmes to list
push(@programmes, @{ $programmes });
} elsif ($Option{'test-mode'}) {
die "test failure: source '" . $source->description . "' didn't retrieve any programmes for '$id'!\n";
}
}
}
_updateProgressBar();
}
_destroyProgressBar();
# Dump programs
message("writing XMLTV programme data");
$_->dump($writer) foreach (@programmes);
# Done writing
_closeXMLTVWriter($writer);
}
###############################################################################
#
# Man page
#
###############################################################################
__END__
=pod
=head1 NAME
tv_grab_fi - Grab TV listings for Finland
=head1 SYNOPSIS
tv_grab_fi [--cache E<lt>FILEE<gt>]
[--config-file E<lt>FILEE<gt>]
[--days E<lt>NE<gt>]
[--gui [E<lt>OPTIONE<gt>]]
[--no-randomize]
[--offset E<lt>NE<gt>]
[--output E<lt>FILEE<gt>]
[--quiet]
tv_grab_fi --capabilities
tv_grab_fi --configure
[--cache E<lt>FILEE<gt>]
[--config-file E<lt>FILEE<gt>]
[--gui [E<lt>OPTIONE<gt>]]
[--quiet]
tv_grab_fi --description
tv_grab_fi --help|-h|-?
tv_grab_fi --list-channels
[--cache E<lt>FILEE<gt>]
[--gui [E<lt>OPTIONE<gt>]]
[--quiet]
tv_grab_fi --version
=head1 DESCRIPTION
Grab TV listings for several channels available in Finland. The data comes
from various sources, e.g. www.telkku.com. The grabber relies on parsing HTML,
so it might stop working when the web page layout is changed.
You need to run C<tv_grab_fi --configure> first to create the channel
configuration for your setup. Subsequently runs of C<tv_grab_fi> will grab
the latest data, process them and produce XML data on the standard output.
=head1 COMMANDS
=over 8
=item B<NONE>
Grab mode.
=item B<--capabilities>
Show the capabilities this grabber supports. See also
L<http://wiki.xmltv.org/index.php/XmltvCapabilities>.
=item B<--configure>
Generate the configuration file by asking the users which channels to grab.
=item B<--description>
Print the description for this grabber.
=item B<--help|-h|-?>
Show this help page.
=item B<--list-channels>
Fetch all available channels from the various sources and write them to the
standard output.
=item B<--version>
Show the version of this grabber.
=back
=head1 GENERIC OPTIONS
=over 8
=item B<--cache F<FILE>>
File name to cache the fetched HTML data in. This speeds up subsequent runs
using the same data.
=item B<--gui [OPTION]>
Enable the graphical user interface. If you don't specify B<OPTION> then
XMLTV will automatically choose the best available GUI. Allowed values are:
=over 4
=item B<Term>
Terminal output with a progress bar
=item B<TermNoProgressBar>
Terminal output without progress bar
=item B<Tk>
Tk-based GUI
=back
=item B<--quiet>
Suppress any progress messages to the standard output.
=back
=head1 CONFIGURE MODE OPTIONS
=over 8
=item B<--config-file F<FILE>>
File name to write the configuration to.
Default is F<$HOME/.xmltv/tv_grab_fi.conf>.
=back
=head1 GRAB MODE OPTIONS
=over 8
=item B<--config-file F<FILE>>
File name to read the configuration from.
Default is F<$HOME/.xmltv/tv_grab_fi.conf>.
=item B<--days C<N>>
Grab C<N> days of TV data.
Default is 14 days.
=item B<--no-randomize>
Grab TV data in deterministic order, i.e. first fetch channel 1, days 1 to N,
then channel 2, and so on.
Default is to use a random access pattern. If you only grab TV data from one
source then the randomizing is a no-op.
=item B<--offset C<N>>
Grab TV data starting at C<N> days in the future.
Default is 0, i.e. today.
=item B<--output F<FILE>>
Write the XML data to F<FILE> instead of the standard output.
=back
=head1 CONFIGURATION FILE SYNTAX
The configuration file is line oriented, each line can contain one command.
Empty lines and everything after the C<#> comment character is ignored.
Supported commands are:
=over 8
=item B<channel ID NAME>
Grab information for this channel. C<ID> depends on the source, C<NAME> is
ignored and forwarded as is to the XMLTV output file. This information can be
automatically generated using the grabber in the configuration mode.
=item B<series description NAME>
If a programme title matches C<NAME> then the first sentence of the
description, i.e. everything up to the first period (C<.>), question mark
(C<?>) or exclamation mark (C<!>), is removed from the description and is used
as the name of the episode.
=item B<series title NAME>
If a programme title contains a colon (C<:>) then the grabber checks if the
left-hand side of the colon matches C<NAME>. If it does then the left-hand
side is used as programme title and the right-hand side as the name of the
episode.
=item B<title map "FROM" 'TO'>
If the programme title starts with the string C<FROM> then replace this part
with the string C<TO>. The strings must be enclosed in single quotes (C<'>) or
double quotes (C<">). The title mapping occurs before the C<series> command
processing.
=item B<title strip parental level>
At the beginning of 2012 some programme descriptions started to include
parental levels at the end of the title, e.g. C<(S)>. With this command all
parental levels will be removed from the titles automatically. This removal
occurs before the title mapping.
=back
=head1 SEE ALSO
L<xmltv>.
=head1 AUTHORS
=head2 Current
=over
=item Stefan Becker C<chemobejk at gmail dot com>
=item Ville Ahonen C<ville dot ahonen at iki dot fi>
=back
=head2 Retired
=over
=item Matti Airas
=back
=head1 BUGS
The channels are identified by channel number rather than the RFC2838 form
recommended by the XMLTV DTD.
=cut
|