-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.pl
106 lines (82 loc) · 2.88 KB
/
update.pl
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
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use Web::Scraper;
use URI;
use Net::FTP;
my $url="http://v.ifeng.com/q/show/kaijuanbafenzhong/pro/list_40.shtml";
my $i=33;
while ($i>0)
{
##找节目
print "$i\n";
my $href="";
if($i==1){
$href="/html/body/div[6]/div/div/div/h4/a";
}else{
$href="/html/body/div[6]/div/div/div[$i]/h4/a";};
$i--;
my $scraper = scraper {
process $href,link => '@href';
};
my $result = $scraper->scrape( URI->new($url));
last if not defined $result->{link};
my $guid=$result->{link};
$guid=~s/(http:\/\/v\.ifeng\.com\/.*\/\d{6}\/)(.*)(\.shtml$)/$2/;
##print "$guid";
my $x1=substr($guid,-2,1);
my $x2=substr($guid,-2);
##节目XML
my $sxml="http://v.ifeng.com/video_info_new/".$x1."/".$x2."/".$guid.".xml";
getstore($sxml,"$guid".".xml") or die("unknown url\n");
open( FXML, "$guid".".xml") or die "Couldn't open $guid\.xml for reading: $!";
read FXML,my $allxml, -s FXML;
##XML文件错误
die "找不到视频地址!"if $allxml!~m/VideoPlayUrl.*?\//;
close FXML;
##视频地址
my $mp4=$allxml;
my $html=$allxml;
my $pname=$allxml;
my $createdate=$allxml;
$mp4=~s/.*VideoPlayUrl=\"(.*\.(mp4|flv)).*/$1/s;
chomp $mp4;
$mp4=~s/video\.ifeng\.com/video16\.ifeng\.com/s;
$html=~s/.*PlayerUrl=\"(.*?\.shtml).*/$1/s;
chomp $html;
##名字
$pname=~s/.*progName=\"(.*)\".*progUrl=.*/$1/s;
chomp $pname;
print "$pname\n";
##日期
$createdate=~s/.*CreateDate=\"(.*)\".*Keyword=.*/$1/s;
chomp $createdate;
print "$createdate\n";
##判断是否存在这个节目
open REC,"rec.txt";
read REC,my $rec, -s REC;
die "已经存在" if $rec=~m/$guid/;
close REC;
##不存在,添加到记录
open WRR ,">rec.txt";
say WRR $guid."\,".$pname."\,".$mp4."\,".$createdate ;
open WRR ,">>rec.txt";
say WRR $rec;
close WRR;
##插入XML__Remote
print "插入XML Remote\n";
open RSS,"rss.xml";
read RSS, my $headrss ,1280;
read RSS, my $tailrss,-s RSS;
$headrss=~s/\<pubDate\>.*\<\/pubDate\>/\<pubDate\>$createdate\<\/pubDate\>/;
open RSS,">rss.xml";
say RSS $headrss;
open RSS,">>rss.xml";
say RSS "<item><title>$pname</title><link>$html</link><description></description><pubDate>$createdate</pubDate><enclosure url=\"$mp4\"/><guid isPermaLink=\"false\">$mp4</guid><media:content url=\"$mp4\"/></item>";
say RSS $tailrss;
close RSS;
#unlink("$guid.xml");
#unlink("$localaac.aac");
#unlink("$localmp4.mp4");
}
print "OK";