root/trunk/ActionStreams/plugins/ActionStreams/lib/ActionStreams/Fix.pm @ 1564

Revision 1564, 4.7 kB (checked in by mpaschal, 5 months ago)

Switch the Google Reader stream to a yaml recipe instead of a class based definition

Line 
1
2package ActionStreams::Fix;
3
4use strict;
5use warnings;
6
7use ActionStreams::Scraper;
8
9sub _twitter_add_tags_to_item {
10    my ($item) = @_;
11    if (my @tags = $item->{title} =~ m{
12        (?: \A | \s )  # BOT or whitespace
13        \#             # hash
14        (\w\S*\w)      # tag
15        (?<! 's )      # but don't end with 's
16    }xmsg) {
17        $item->{tags} = \@tags;
18    }
19}
20
21sub twitter_tweet_name {
22    my ($cb, $app, $item, $event, $author, $profile) = @_;
23    # Remove the Twitter username from the front of the tweet.
24    my $ident = $profile->{ident};
25    $item->{title} =~ s{ \A \s* \Q$ident\E : \s* }{}xmsi;
26    _twitter_add_tags_to_item($item);
27}
28
29sub twitter_favorite_author {
30    my ($cb, $app, $item, $event, $author, $profile) = @_;
31    # Remove the Twitter username from the front of the tweet.
32    if ($item->{title} =~ s{ \A \s* ([^\s:]+) : \s* }{}xms) {
33        $item->{tweet_author} = $1;
34    }
35    _twitter_add_tags_to_item($item);
36}
37
38sub flickr_photo_thumbnail {
39    my ($cb, $app, $item, $event, $author, $profile) = @_;
40    # Extract just the URL, and use the _t size thumbnail, not the _m size image.
41    my $thumb = delete $item->{thumbnail};
42    if ($thumb =~ m{ (http://farm[^\.]+\.static\.flickr\.com .*? _m.jpg) }xms) {
43        $thumb = $1;
44        $thumb =~ s{ _m.jpg \z }{_t.jpg}xms;
45        $item->{thumbnail} = $thumb;
46    }
47}
48
49sub googlereader_link_links {
50    my ($cb, $app, $item, $event, $author, $profile) = @_;
51    my $enclosure = delete $item->{enclosure};
52    $item->{url} ||= $enclosure || q{};
53    $item->{identifier} = $item->{url} if $item->{url};
54}
55
56sub iminta_link_title {
57    my ($cb, $app, $item, $event, $author, $profile) = @_;
58    # Remove the username for when we add it back in later.
59    $item->{title} =~ s{ (?: \s* :: [^:]+ ){2} \z }{}xms;
60}
61
62sub instructables_favorites_thumbnails {
63    my ($cb, $app, $item, $event, $author, $profile) = @_;
64    $item->{thumbnail} = URI->new_abs($item->{thumbnail}, 'http://www.instructables.com/')
65        if $item->{thumbnail};
66}
67
68sub iusethis_event_title {
69    my ($cb, $app, $item, $event, $author, $profile) = @_;
70    # Remove the username for when we add it back in later.
71    $item->{title} =~ s{ \A \w+ \s* }{}xms;
72}
73
74sub metafilter_favorites_titles {
75    my ($cb, $app, $item, $event, $author, $profile) = @_;
76    $item->{title} =~ s{ \A [^:]+ : \s* }{}xms;
77}
78
79sub netflix_recent_prefix_thumb {
80    my ($cb, $app, $item, $event, $author, $profile) = @_;
81    # Remove the 'Shipped:' or 'Received:' prefix.
82    $item->{title} =~ s{ \A [^:]*: \s* }{}xms;
83
84    # Extract thumbnail from description.
85    my $thumb = delete $item->{thumbnail};
86    if ($thumb =~ m/ <img src="([^"]+)"} /xms) {
87        $item->{thumbnail} = $1;
88    }
89}
90
91sub netflix_queue_prefix_thumb {
92    my ($cb, $app, $item, $event, $author, $profile) = @_;
93    # Remove the item number.
94    $item->{title} =~ s{ \A \d+ [\W\S] \s* }{}xms;
95
96    # Extract thumbnail from description.
97    my $thumb = delete $item->{thumbnail};
98    if ($thumb =~ m/ <img src="([^"]+)"} /xms) {
99        $item->{thumbnail} = $1;
100    }
101}
102
103sub nytimes_links_titles {
104    my ($cb, $app, $item, $event, $author, $profile) = @_;
105    return $item->{title} =~ s{ \A [^:]* recommended [^:]* : \s* }{}xms ? 1 : 0;
106}
107
108sub p0pulist_stuff_urls {
109    my ($cb, $app, $item, $event, $author, $profile) = @_;
110    $item->{url} =~ s{ \A / }{http://p0pulist.com/}xms;
111}
112
113sub kongregate_achievement_title_thumb {
114    my ($cb, $app, $item, $event, $author, $profile) = @_;
115    # Remove the parenthetical from the end of the title.
116    $item->{title} =~ s{ \( [^)]* \) \z }{}xms;
117
118    # Pick the actual achievement badge out of the inline CSS.
119    my $thumb = delete $item->{thumbnail} || q{};
120    if ($thumb =~ m{ background-image: \s* url\( ([^)]+) }xms) {
121        $item->{thumbnail} = $1;
122    }
123}
124
125sub wists_thumb {
126    my ($cb, $app, $item, $event, $author, $profile) = @_;
127    # Grab the wists thumbnail out.
128    my $thumb = delete $item->{thumbnail};
129    if ($thumb =~ m{ (http://cache.wists.com/thumbnails/ [^"]+ ) }xms) {
130        $item->{thumbnail} = $1;
131    }
132}
133
134sub gametap_score_stuff {
135    my ($cb, $app, $item, $event, $author, $profile) = @_;
136    $item->{score} =~ s{ \D }{}xmsg;
137    $item->{url} = q{} . $item->{url};
138    $item->{url} =~ s{ \A / }{http://www.gametap.com/}xms;
139}
140
141sub typepad_comment_titles {
142    my ($cb, $app, $item, $event, $author, $profile) = @_;
143    $item->{title} =~ s{ \A .*? ' }{}xms;
144    $item->{title} =~ s{ ' \z }{}xms;
145}
146
147sub magnolia_link_notes {
148    my ($cb, $app, $item, $event, $author, $profile) = @_;
149    my $scraper = scraper {
150        process '//p[position()=2]', note => 'TEXT';
151    };
152
153    my $result = $scraper->scrape(\$item->{note});
154
155    if ($result->{note}) {
156        $item->{note} = $result->{note};
157    }
158    else {
159        delete $item->{note};
160    }
161}
162
1631;
164
Note: See TracBrowser for help on using the browser.