Last active
March 5, 2024 16:33
Revisions
-
gruber revised this gist
Nov 14, 2018 . No changes.There are no files selected for viewing
-
gruber revised this gist
Nov 14, 2018 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,7 @@ # or # % echo 'https://apple.news/Ae78KIEmMOHCVXD4VA7ysKw' | AppleNewsURLRedirect.pl # # Author: John Gruber <https://daringfireball.net/> # # 13 Nov 2018 # Initial version. -
gruber created this gist
Nov 14, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ #!/usr/bin/perl # Given an Apple News URL, prints the original URL for the story. # # Usage: # % AppleNewsURLRedirect.pl 'https://apple.news/Ae78KIEmMOHCVXD4VA7ysKw' # or # % echo 'https://apple.news/Ae78KIEmMOHCVXD4VA7ysKw' | AppleNewsURLRedirect.pl # # Author: John Gruber # https://daringfireball.net/ # # # 13 Nov 2018 # Initial version. # # Todo: Should probably take a list of Apple News URLs, not just one. # use strict; use warnings; use LWP::Simple; # Try ARGV first my $apple_news_url = $ARGV[0]; # Try STDIN next (trying STDIN first won't work, will take input from terminal) unless (defined $apple_news_url) { $apple_news_url = <STDIN>; } unless( defined $apple_news_url && $apple_news_url =~ m{https://apple.news/\S+}) { print "Usage: AppleNewsURLRedirect.pl 'https://apple.news/article_id'"; exit; } my $content = get($apple_news_url); die "Couldn't get '$apple_news_url'" unless defined $content; # $content is an HTML page. Pretty easy to scrape the redirect URL # from the JavaScript, but this could easily break in the future. $content =~ m{redirectToUrl\("(.+)"\);}; my $redirect_url = $1; print $redirect_url;