URI-Title-1.900000755001750001750 012444414310 12305 5ustar00bookbook000000000000README100644001750001750 204012444414310 13242 0ustar00bookbook000000000000URI-Title-1.900NAME URI::Title - get the titles of things on the web in a sensible way DESCRIPTION I keep having to find the title of things on the web. This seems like a really simple request, just get() the object, parse for a title tag, you're done. Ha, I wish. There are several problems with this approach: What if the resource is on a very slow server? Do we wait for ever or what? What if the resource is a 900 gig file? You don't want to download that. What if the page title isn't in a title tag, but is buried in the HTML somewhere? What if the resource is an MP3 file, or a word document or something? ... So, let's solve these issues once. METHODS only one, the title(url) method. Call it with an url, get the title if possible, undef if it wasn't. Very simple. AUTHORS Tom Insam , original author, 2004-2012. Philippe Bruhat (BooK) , maintainer, 2014. LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Changes100644001750001750 634112444414310 13665 0ustar00bookbook000000000000URI-Title-1.900Revision history for Perl module URI::Title 1.900 2014-58-18 Philippe Bruhat (BooK) - now packaged with Dist::Zilla - Added separate COPYRIGHT AND LICENSE section to pod (NEILB) - Specified min version of perl as 5.006 (NEILB) - Added WWW::GetPageTitle to SEE ALSO. More for completeness than any belief that anyone might want to use that over URI::Title. (NEILB) 1.89 2014-09-12 Philippe Bruhat (BooK) - Closed RT #55235 (thanks to James Green (JKG)) 1.88 2014-02-04 Philippe Bruhat (BooK) - Closed RT #41361 (thanks to Kevin Ryde (KRYDE)) 1.87 2014-02-04 Philippe Bruhat (BooK) - New maintainer: BOOK - Added github repo to metadata - Added license details to metadata - Closed RT #82054 (thanks to Jotam Jr. Trejo) - Closed RT #92091 (thanks to Zakariyya Mughal (ZMUGHAL)) - Fixed POD syntax - Added some POD tests - Fixed broken tests 1.86 2012-05-26 Tom Insam - Twitter suport fixed for non-javascript anchor links (yay) 1.85 2011-06-02 Tom Insam - Twitter suport fixed for javascript anchor links (ugh) 1.84 2009-07-27 Tom Insam - Spotify titling support from https://rt.cpan.org/Public/Bug/Display.html?id=48231 1.83 2008-10-18 Paul Mison - Work around a change in Twitter HTML 1.82 2008-09-30 Tom Insam - Latest LWP-UserAgent is pickier about what you pass it as a URI - fixed. 1.81 2008-06-19 Tom Insam - fix changes for the Register title - clearer licensing 1.80 2008-06-19 Tom Insam - Twitter support - Google calculator support - Too many irritating corner-case bugfixes to list. - Claim that we don't do gzip in some cases, to avoid evil 1.70 2008-04-21 Tom Insam - Added special case for Helsingin Sanomat URLs. - Supressed warnings if imgsize can't get an image size (from Dagfinn Ilmari Mannsaker) - Fixed some more nagging unicode issues. Bah, unicode. - Send a real user-agent, to prevent people that hard-code a block of the default Perl useragent from blocking us. 1.62 2006-05-18 Tom Insam - character set support that actually _works_ - we also try utf-8 first always, because people lie. - Fix for servers that don't respect the Range header. 1.61 2005-07-21 Tom Insam - Fix tiny test breakage - Better charset support 1.60 2004-09-23 Tom Insam - Added limited character set support. It mostly sucks, but less than it did before. 1.50 2004-08-13 Tom Insam - Added quick special case for iTMS urls. - Bumped version to 1.0, I quite like this code now. 0.50 2004-05-06 Tom Insam - 0.5 Release - Use File::Type to detech mime types and hand off to sub-modules - Use Module::Pluggable to discover sub-modules - Add Image, MP3 and PDF naming modules 0.30 2004-03-16 Tom Insam - 0.3 Release - Don't run tests without a net connection - More special cases. - Variable header size downloading for pathological cases - Much better whitespace trimming 0.10 2004-01-17 Tom Insam - 0.1 Release. It doesn't suck, much. LICENSE100644001750001750 4364212444414310 13424 0ustar00bookbook000000000000URI-Title-1.900This software is copyright (c) 2014 by Tom Insam. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014 by Tom Insam. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 by Tom Insam. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End dist.ini100644001750001750 174612444414310 14042 0ustar00bookbook000000000000URI-Title-1.900name = URI-Title author = Philippe Bruhat (BooK) license = Perl_5 copyright_holder = Tom Insam ; copyright_year = 2004-2014 [PkgVersion] [@Filter] -bundle = @Basic -remove = Readme [PruneFiles] filename = TODO filename = Insane perl code to get title [ExecDir] dir = script [AutoPrereqs] [Prereqs] Module::Pluggable = 1.2 File::Type = 0.22 HTML::Parser = 3.45 [ReportVersions::Tiny] [MetaJSON] [MetaResources] repository.web = http://github.com/book/URI-Title repository.url = http://github.com/book/URI-Title.git repository.type = git bugtracker.web = http://rt.cpan.org/NoAuth/Bugs.html?Dist=URI-Title bugtracker.mailto = bug-uri-title@rt.cpan.org [MetaTests] [PodSyntaxTests] [PodCoverageTests] [NextRelease] format = %v %{yyyy-mm-dd}d Philippe Bruhat (BooK) [@Git] changelog = Changes commit_msg = Changes for version %v tag_format = v%v tag_message = %N v%v push_to = origin push_to = github [Git::NextVersion] t000755001750001750 012444414310 12471 5ustar00bookbook000000000000URI-Title-1.900html.t100644001750001750 134412444414310 13764 0ustar00bookbook000000000000URI-Title-1.900/tuse warnings; use strict; use Test::More; use lib 'lib'; use URI::Title qw(title); require IO::Socket; my $s = IO::Socket::INET->new( PeerAddr => "www.yahoo.com:80", Timeout => 10, ); if ($s) { close($s); plan tests => 1; } else { plan skip_all => "no net connection available"; exit; } #is( # title('http://jerakeen.org/test/uri-title.html'), # "URI::Title test", # "got title for jerakeen.org"); ok( title('http://www.theregister.co.uk/2003/12/16/warning_lack_of_technology_may/') =~ /lack of technology may harm your prospects/, "got register title"); # ok( # title('http://twitter.com/al3x/status/1039647490') eq 'twitter - Arianna Huffington: not a good saleswoman for blogging.', # "got Twitter status"); META.yml100644001750001750 165212444414310 13643 0ustar00bookbook000000000000URI-Title-1.900--- abstract: 'get the titles of things on the web in a sensible way' author: - 'Philippe Bruhat (BooK) ' build_requires: IO::Socket: '0' Test::More: '0.88' lib: '0' configure_requires: ExtUtils::MakeMaker: '6.30' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.016, CPAN::Meta::Converter version 2.133380' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: URI-Title requires: Carp: '0' Encode: '0' Exporter: '0' File::Temp: '0' File::Type: '0.22' HTML::Entities: '0' HTML::Parser: '3.45' HTTP::Request: '0' HTTP::Response: '0' Image::Size: '0' LWP::UserAgent: '0' MP3::Info: '0' Module::Pluggable: '1.2' base: '0' perl: '5.006' strict: '0' utf8: '0' warnings: '0' resources: bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=URI-Title repository: http://github.com/book/URI-Title.git version: '1.900' MANIFEST100644001750001750 65712444414310 13507 0ustar00bookbook000000000000URI-Title-1.900# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.016. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini eg/title.pl lib/URI/Title.pm lib/URI/Title/HTML.pm lib/URI/Title/Image.pm lib/URI/Title/MP3.pm lib/URI/Title/PDF.pm t/000-report-versions-tiny.t t/00bootstrap.t t/failure.t t/html.t t/image.t t/other.t.broken t/release-distmeta.t t/release-pod-coverage.t t/release-pod-syntax.t image.t100644001750001750 61312444414310 14060 0ustar00bookbook000000000000URI-Title-1.900/tuse warnings; use strict; use Test::More; use lib 'lib'; use URI::Title qw(title); require IO::Socket; my $s = IO::Socket::INET->new( PeerAddr => "www.yahoo.com:80", Timeout => 10, ); if ($s) { close($s); plan tests => 1; } else { plan skip_all => "no net connection available"; exit; } is( title('http://st.pimg.net/perlweb/images/camel_head.v25e738a.png'), "png (60 x 65)" ); META.json100644001750001750 373412444414310 14016 0ustar00bookbook000000000000URI-Title-1.900{ "abstract" : "get the titles of things on the web in a sensible way", "author" : [ "Philippe Bruhat (BooK) " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.016, CPAN::Meta::Converter version 2.133380", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "URI-Title", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "version" : "0.9901" } }, "runtime" : { "requires" : { "Carp" : "0", "Encode" : "0", "Exporter" : "0", "File::Temp" : "0", "File::Type" : "0.22", "HTML::Entities" : "0", "HTML::Parser" : "3.45", "HTTP::Request" : "0", "HTTP::Response" : "0", "Image::Size" : "0", "LWP::UserAgent" : "0", "MP3::Info" : "0", "Module::Pluggable" : "1.2", "base" : "0", "perl" : "5.006", "strict" : "0", "utf8" : "0", "warnings" : "0" } }, "test" : { "requires" : { "IO::Socket" : "0", "Test::More" : "0.88", "lib" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-uri-title@rt.cpan.org", "web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=URI-Title" }, "repository" : { "type" : "git", "url" : "http://github.com/book/URI-Title.git", "web" : "http://github.com/book/URI-Title" } }, "version" : "1.900" } failure.t100644001750001750 31012444414310 14417 0ustar00bookbook000000000000URI-Title-1.900/t#!perl -w use strict; use lib qw(lib ../lib); use Test::More tests => 1; use URI::Title qw(title); # it's much easier to test for failure is(title('nonsense'), undef, "Title of nonsense is blank"); eg000755001750001750 012444414310 12621 5ustar00bookbook000000000000URI-Title-1.900title.pl100755001750001750 27312444414310 14424 0ustar00bookbook000000000000URI-Title-1.900/eg#!/usr/bin/perl use warnings; use strict; use lib 'lib'; use URI::Title qw(title); use Encode; my $title = title(shift); binmode STDOUT, ":utf8"; print $title || 'no title'; print "\n"; Makefile.PL100644001750001750 354112444414310 14343 0ustar00bookbook000000000000URI-Title-1.900 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.016. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "get the titles of things on the web in a sensible way", "AUTHOR" => "Philippe Bruhat (BooK) ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "URI-Title", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "URI::Title", "PREREQ_PM" => { "Carp" => 0, "Encode" => 0, "Exporter" => 0, "File::Temp" => 0, "File::Type" => "0.22", "HTML::Entities" => 0, "HTML::Parser" => "3.45", "HTTP::Request" => 0, "HTTP::Response" => 0, "Image::Size" => 0, "LWP::UserAgent" => 0, "MP3::Info" => 0, "Module::Pluggable" => "1.2", "base" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "IO::Socket" => 0, "Test::More" => "0.88", "lib" => 0 }, "VERSION" => "1.900", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Encode" => 0, "Exporter" => 0, "File::Temp" => 0, "File::Type" => "0.22", "HTML::Entities" => 0, "HTML::Parser" => "3.45", "HTTP::Request" => 0, "HTTP::Response" => 0, "IO::Socket" => 0, "Image::Size" => 0, "LWP::UserAgent" => 0, "MP3::Info" => 0, "Module::Pluggable" => "1.2", "Test::More" => "0.88", "base" => 0, "lib" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 00bootstrap.t100644001750001750 14012444414310 15146 0ustar00bookbook000000000000URI-Title-1.900/t#!perl -w use strict; use lib qw(lib ../lib); use Test::More tests => 1; use_ok('URI::Title'); other.t.broken100644001750001750 110012444414310 15406 0ustar00bookbook000000000000URI-Title-1.900/tuse warnings; use strict; use Test::More; use lib 'lib'; use URI::Title qw(title); require IO::Socket; my $s = IO::Socket::INET->new( PeerAddr => "www.yahoo.com:80", Timeout => 10, ); if ($s) { close($s); plan tests => 1; } else { plan skip_all => "no net connection available"; exit; } #is( # title('http://jerakeen.org/images/thoth.gif'), # "gif (144 x 99)", # "got title for jerakeen.org/images/thoth.gif"); is( title('http://jerakeen.org/test/uri-title-test.mp3'), "Ashley Pomeroy - Sand", "got title for jerakeen.org/test/uri-title-test.mp3"); URI000755001750001750 012444414310 13433 5ustar00bookbook000000000000URI-Title-1.900/libTitle.pm100644001750001750 1453212444414310 15237 0ustar00bookbook000000000000URI-Title-1.900/lib/URIpackage URI::Title; $URI::Title::VERSION = '1.900'; use 5.006; use warnings; use strict; use base qw(Exporter); our @EXPORT_OK = qw( title ); our $VERSION; use Module::Pluggable (search_path => ['URI::Title'], require => 1 ); use File::Type; use LWP::UserAgent; use HTTP::Request; use HTTP::Response; sub _ua { my $ua = LWP::UserAgent->new; $ua->agent("URI::Title/$VERSION"); $ua->timeout(20); $ua->default_header('Accept-Encoding' => 'gzip'); return $ua; } sub _get_limited { my $url = shift; my $size = shift || 32*1024; my $ua = _ua(); $ua->max_size($size); my $req = HTTP::Request->new(GET => $url); $req->header( Range => "bytes=0-$size" ); $req->header( "Accept-Encoding" => "" ); # vox sends invalid gzipped data? my $res = eval { $ua->request($req) }; return unless $res; # useragent explodes for non-valid uris # some servers don't like the Range header. If we # get an odd 4xx response that isn't 404, just try getting # the full thing. This may be a little impolite. return _get_all($url) if $res->code >= 400 and $res->code < 500 and $res->code != 404; return unless $res->is_success; if (!wantarray) { return $res->decoded_content || $res->content; } my $cset = "iso-8859-1"; # default; my $ct = $res->header("Content-type"); if ($ct =~ /charset\s*=\>?\s*\"?([\w-]+)/i) { $cset = lc($1); #warn "Got charset $cset from URI headers\n"; } return ($res->decoded_content || $res->content, $cset); } sub _get_end { my $url = shift; my $size = shift || 16*1024; my $ua = _ua(); my $request = HTTP::Request->new(HEAD => $url); my $response = $ua->request($request); return unless $response; # useragent explodes for non-valid uris my $length = $response->header('Content-Length'); return unless $length; # We can't get the length, and we're _not_ # going to get the whole thing. my $start = $length - $size; $ua->max_size($size); my $req = HTTP::Request->new(GET => $url); $req->header( Range => "bytes=$start-$length" ); my $res = $ua->request($req); return unless $res; # useragent explodes for non-valid uris return unless $res->is_success; return $res->decoded_content unless wantarray; my $cset = "iso-8859-1"; # default; my $ct = $res->header("Content-type"); if ($ct =~ /charset=\"?(.*)\"?$/) { $cset = $1; } return ($res->decoded_content, $cset); } sub _get_all { my $url = shift; my $ua = _ua(); my $req = HTTP::Request->new(GET => $url); my $res = $ua->request($req); return unless $res->is_success; return $res->decoded_content unless wantarray; my $cset = "iso-8859-1"; # default; my $ct = $res->header("Content-type"); if ($ct =~ /charset=\"?(.*)\"?$/) { $cset = $1; } return ($res->decoded_content, $cset); } # cache our $HANDLERS; sub _handlers { my @plugins = plugins(); return $HANDLERS if $HANDLERS; for my $plugin (@plugins) { for my $type ($plugin->types) { $HANDLERS->{$type} = $plugin; } } return $HANDLERS; } sub title { my $param = shift; my $data; my $url; my $type; my $cset = "iso-8859-1"; # default # we can be passed a hashref. Keys are url, or data. if (ref($param)) { if ($param->{data}) { $data = $param->{data}; $data = $$data if ref($data); # we can be passed a ref to the data } elsif ($param->{url}) { $url = $param->{url}; } else { use Carp qw(croak); croak("Expected a single parameter, or an 'url' or 'data' key"); } # otherwise, assume we're passed an url } else { $url = $param; } if (!$url and !$data) { warn "Need at least an url or data"; return; } # If we don't have data, we will have an url, so try to get data. if (!$data) { # url might be a filename if (-e $url) { local $/ = undef; unless (open DATA, $url) { warn "$url looks like a file and isn't"; return; } $data = ; close DATA; # If not, assume it's an url } else { # special case for itms if ($url =~ s/^itms:/http:/) { $type = "itms"; $data = 1; # we don't need it, fake it. } else { # special case for spotify $url =~ s{^(?:http://open.spotify.com/|spotify:)(\w+)[:/]}{http://spotify.url.fi/$1/}; $url =~ s{#!}{?_escaped_fragment_=}; ($data, $cset) = _get_limited($url); } } } if (!$data) { #warn "Can't get content for $url"; return; } return undef unless $data; $type ||= File::Type->new->checktype_contents($data); my $handlers = _handlers(); my $handler = $handlers->{$type} || $handlers->{default} or return; return $handler->title($url, $data, $type, $cset); } 1; __END__ =head1 NAME URI::Title - get the titles of things on the web in a sensible way =head1 SYNOPSIS use URI::Title qw( title ); my $title = title('http://microsoft.com'); print "Title is $title\n"; =head1 DESCRIPTION I keep having to find the title of things on the web. This seems like a really simple request, just get() the object, parse for a title tag, you're done. Ha, I wish. There are several problems with this approach: =over 4 =item What if the resource is on a very slow server? Do we wait for ever or what? =item What if the resource is a 900 gig file? You don't want to download that. =item What if the page title isn't in a title tag, but is buried in the HTML somewhere? =item What if the resource is an MP3 file, or a word document or something? =item ... =back So, let's solve these issues once. =head1 METHODS only one, the title(url) method. Call it with an url, get the title if possible, undef if it wasn't. Very simple. =head1 TODO Many, many, many things. Still unimplemented: =over 4 =item Get titles of MP3 files, Word Docs, PDFs, etc. =item Configurable.. well, anything, in fact. Timeout would be a good start. =item Better error reporting. =back =head1 AUTHORS Tom Insam Etom@jerakeen.orgE, original author, 2004-2012. Philippe Bruhat (BooK) Ebook@cpan.orgE, maintainer, 2014. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 CREDITS Invented because of a conversation with rjp, who contributed some eyeball-melting and as-yet-unused code to get titles from MP3s and PDFs, and hex, who has also solved the problem, and got bits done in a nicer way than I did. =cut Title000755001750001750 012444414310 14514 5ustar00bookbook000000000000URI-Title-1.900/lib/URIPDF.pm100644001750001750 206712444414310 15630 0ustar00bookbook000000000000URI-Title-1.900/lib/URI/Titlepackage URI::Title::PDF; $URI::Title::PDF::VERSION = '1.900'; use warnings; use strict; sub types {( 'application/pdf', )} sub title { my ($class, $url, $data, $type) = @_; my %fields = (); my $content = URI::Title::_get_end($url) or return; foreach my $i (qw(Producer Creator CreationDate Author Title Subject)) { my @parts = $content =~ m#/$i \((.*?)\)#mgs; $fields{$i} = $parts[-1]; # grab the last one, hopefully right } my $title = ""; my @parts = (); if ($fields{Title}) { push @parts, "$fields{Title}"; if ($fields{Author}) { push @parts, "by $fields{Author}"; } if ($fields{Subject}) { push @parts, "($fields{Subject})"; } } if ($fields{Creator} and $fields{Creator} ne 'Not Available') { push @parts, "creator: $fields{Creator}"; } if ($fields{Producer} and $fields{Producer} ne 'Not Available') { push @parts, "produced: $fields{Producer}"; } $title = join(' ', @parts); return $title; } 1; __END__ =for Pod::Coverage::TrustPod types title =head1 NAME URI::Title::PDF - get titles of PDF files =cut MP3.pm100644001750001750 226612444414310 15617 0ustar00bookbook000000000000URI-Title-1.900/lib/URI/Titlepackage URI::Title::MP3; $URI::Title::MP3::VERSION = '1.900'; use warnings; use strict; use MP3::Info; use File::Temp qw(tempfile); sub types {( 'audio/mp3', )} sub _get_tag { my $data = shift; my (undef, $temp) = tempfile(); open FILE, ">$temp" or die $!; print FILE $data; close FILE; my $tag = get_mp3tag($temp); if ($tag) { my $info = get_mp3info($temp); $tag->{info} = $info; } unlink($temp); return $tag; } sub title { my ($class, $url, $data, $type) = @_; my $tag; if (-f $url) { $tag = get_mp3tag($url); if ($tag) { my $info = get_mp3info($url); $tag->{info} = $info; } } else { $tag = _get_tag( $data . URI::Title::_get_end($url) ); } return unless $tag; return unless ($tag->{ARTIST} or $tag->{TITLE}); $tag->{ARTIST} ||= "Unknown Artist"; $tag->{TITLE} ||= "Unknown Title"; my $title = "$tag->{ARTIST} - $tag->{TITLE}"; if (my $total = $tag->{info}{SECS} and -f $url) { my $m = $total / 60; my $s = $total % 60; $title .= sprintf(" (%d:%02d)", $m, $s); } return $title; } 1; __END__ =for Pod::Coverage::TrustPod types title =head1 NAME URI::Title::MP3 - get titles of MP3 files =cut release-distmeta.t100644001750001750 43012444414310 16223 0ustar00bookbook000000000000URI-Title-1.900/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); HTML.pm100644001750001750 536512444414310 15767 0ustar00bookbook000000000000URI-Title-1.900/lib/URI/Titlepackage URI::Title::HTML; $URI::Title::HTML::VERSION = '1.900'; use warnings; use strict; use HTML::Entities; use utf8; our $CAN_USE_ENCODE; BEGIN { eval { require Encode; Encode->import('decode') }; $CAN_USE_ENCODE = !$@; } sub types {( 'text/html', 'default', )} sub title { my ($class, $url, $data, $type, $cset) = @_; my $title; my $special_case; my $default_match = '(.+?)title($1); } # TODO - work this out from the headers of the HTML if ($data =~ /charset=\"?([\w-]+)/i) { $cset = lc($1); } if ( $CAN_USE_ENCODE ) { $data = eval { decode('utf-8', $data, 1) } || eval { decode($cset, $data, 1) } || $data; } my $found_title; if ($url) { if ($url =~ /use\.perl\.org\/~([^\/]+).*journal\/\d/i) { $special_case = '(.+?)<'; $title = "use.perl journal of $1 - "; } elsif ($url =~ /(pants\.heddley\.com|dailychump\.org).*#(.*)$/i) { my $id = $2; $special_case = 'id="a'.$id.'.*?>(.+?)<'; $title = "pants daily chump - "; } elsif ($url =~ /paste\.husk\.org/i) { $special_case = 'Summary: (.+?)<'; $title = "paste - "; } elsif ($url =~ /twitter.com\/(.*?)\/status(es)?\/\d+/i) { $special_case = '

([^\<]+)'; $title = "twitter - "; } elsif ($url =~ /independent\.co\.uk/i) { $special_case = '

(.+?)<'; } elsif ($url =~ /www\.hs\.fi\/english\/article/i) { $special_case = '

(.+?)

'; } elsif ($url =~ /google.com/i and $data =~ /calc_img/) { # google can be used as a calculator. Try to find the result. $special_case = 'calc_img.*(.+?)(.+?)<\/sup>/^$1/g; # for the google math output $found_title =~ s/<.*?>//g; $title .= $found_title; $title =~ s/\s+$//; $title =~ s/^\s+//; $title =~ s/\n+//g; $title =~ s/\s+/ /g; #use Devel::Peek; #Dump( $title ); $title = decode_entities($title); #Dump( $title ); # decode nasty number-encoded entities. Mostly works $title =~ s/(&\#(\d+);?)/chr($2)/eg; return $title; } 1; __END__ =for Pod::Coverage::TrustPod types title =head1 NAME URI::Title::HTML - get titles of html files =cut Image.pm100644001750001750 100212444414310 16225 0ustar00bookbook000000000000URI-Title-1.900/lib/URI/Titlepackage URI::Title::Image; $URI::Title::Image::VERSION = '1.900'; use warnings; use strict; use Image::Size; sub types {( 'image/gif', 'image/jpg', 'image/jpeg', 'image/png', 'image/x-png', )} sub title { my ($class, $url, $data, $type) = @_; my ($x, $y) = imgsize(\$data); $type =~ s!^[^/]*/!!; $type =~ s!^x-!!; return $type unless $x && $y; return "$type ($x x $y)"; } 1; __END__ =for Pod::Coverage::TrustPod types title =head1 NAME URI::Title::Image - get titles of images =cut release-pod-syntax.t100644001750001750 45612444414310 16527 0ustar00bookbook000000000000URI-Title-1.900/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); release-pod-coverage.t100644001750001750 57212444414310 16773 0ustar00bookbook000000000000URI-Title-1.900/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); 000-report-versions-tiny.t100644001750001750 610212444414310 17454 0ustar00bookbook000000000000URI-Title-1.900/tuse strict; use warnings; use Test::More 0.88; # This is a relatively nice way to avoid Test::NoWarnings breaking our # expectations by adding extra tests, without using no_plan. It also helps # avoid any other test module that feels introducing random tests, or even # test plans, is a nice idea. our $success = 0; END { $success && done_testing; } # List our own version used to generate this my $v = "\nGenerated by Dist::Zilla::Plugin::ReportVersions::Tiny v1.08\n"; eval { # no excuses! # report our Perl details my $want = '5.006'; $v .= "perl: $] (wanted $want) on $^O from $^X\n\n"; }; defined($@) and diag("$@"); # Now, our module version dependencies: sub pmver { my ($module, $wanted) = @_; $wanted = " (want $wanted)"; my $pmver; eval "require $module;"; if ($@) { if ($@ =~ m/Can't locate .* in \@INC/) { $pmver = 'module not found.'; } else { diag("${module}: $@"); $pmver = 'died during require.'; } } else { my $version; eval { $version = $module->VERSION; }; if ($@) { diag("${module}: $@"); $pmver = 'died during VERSION check.'; } elsif (defined $version) { $pmver = "$version"; } else { $pmver = ''; } } # So, we should be good, right? return sprintf('%-45s => %-10s%-15s%s', $module, $pmver, $wanted, "\n"); } eval { $v .= pmver('Carp','any version') }; eval { $v .= pmver('Encode','any version') }; eval { $v .= pmver('Exporter','any version') }; eval { $v .= pmver('ExtUtils::MakeMaker','6.30') }; eval { $v .= pmver('File::Temp','any version') }; eval { $v .= pmver('File::Type','0.22') }; eval { $v .= pmver('HTML::Entities','any version') }; eval { $v .= pmver('HTML::Parser','3.45') }; eval { $v .= pmver('HTTP::Request','any version') }; eval { $v .= pmver('HTTP::Response','any version') }; eval { $v .= pmver('IO::Socket','any version') }; eval { $v .= pmver('Image::Size','any version') }; eval { $v .= pmver('LWP::UserAgent','any version') }; eval { $v .= pmver('MP3::Info','any version') }; eval { $v .= pmver('Module::Pluggable','1.2') }; eval { $v .= pmver('Pod::Coverage::TrustPod','any version') }; eval { $v .= pmver('Test::CPAN::Meta','any version') }; eval { $v .= pmver('Test::More','0.88') }; eval { $v .= pmver('Test::Pod','1.41') }; eval { $v .= pmver('Test::Pod::Coverage','1.08') }; eval { $v .= pmver('base','any version') }; eval { $v .= pmver('lib','any version') }; eval { $v .= pmver('strict','any version') }; eval { $v .= pmver('utf8','any version') }; eval { $v .= pmver('version','0.9901') }; eval { $v .= pmver('warnings','any version') }; # All done. $v .= <<'EOT'; Thanks for using my code. I hope it works for you. If not, please try and include this output in the bug report. That will help me reproduce the issue and solve your problem. EOT diag($v); ok(1, "we really didn't test anything, just reporting data"); $success = 1; # Work around another nasty module on CPAN. :/ no warnings 'once'; $Template::Test::NO_FLUSH = 1; exit 0;