Permalink
Browse files

FeedLookupAPI + help

  • Loading branch information...
1 parent 81c111f commit 7b5e229ec1fa12085a30dfe30067c9d4d5462c04 @astro committed Apr 1, 2013
View
@@ -39,6 +39,7 @@ import Handler.TorrentStats
import Handler.MapFeed
import Handler.DownloadFeeds
import Handler.ByEnclosureAPI
+import Handler.FeedLookupAPI
import Handler.Tracker
import Handler.Help
import Handler.Widget
View
@@ -0,0 +1,29 @@
+module Handler.FeedLookupAPI where
+
+import Prelude
+import Control.Applicative
+import Control.Monad
+import qualified Data.Text as T
+import Yesod
+
+import Import
+
+getFeedLookupJson :: Handler RepJson
+getFeedLookupJson = do
+ urls <- map snd <$>
+ filter (("url" `T.isPrefixOf`) . fst) <$>
+ reqGetParams <$>
+ getRequest
+ urlRender <- getUrlRender
+ RepJson <$> toContent <$> object <$>
+ withDB
+ (\db ->
+ forM urls $ \url ->
+ (url .=) <$>
+ map (\feed ->
+ ("http://bitlove.org" `T.append`) <$>
+ urlRender $
+ MapFeedR (feedUser feed) (feedSlug feed)
+ ) <$>
+ feedByUrl url db
+ )
View
@@ -31,8 +31,12 @@ getHelpApiR =
defaultLayout $ do
setTitleI MsgTitleHelp
renderHelpPodcasterNavigation
- let example = T.pack $
- BC.unpack $(embedFile "templates/help-api-example.text")
+ let by_enclosure_example =
+ T.pack $
+ BC.unpack $(embedFile "templates/help-api-by-enclosure-example.text")
+ feed_lookup_example =
+ T.pack $
+ BC.unpack $(embedFile "templates/help-api-feed-lookup-example.text")
$(whamletFile "templates/help-api.hamlet")
getHelpWidgetR :: GHandler sub UIApp RepHtml
View
@@ -53,6 +53,7 @@ module Model (
userFeedInfo,
addUserFeed,
deleteUserFeed,
+ feedByUrl,
FeedDetails (..),
userFeedDetails,
setUserFeedDetails,
View
@@ -98,6 +98,10 @@ deleteUserFeed user slug db =
(== 1) `fmap`
run db "DELETE FROM user_feeds WHERE \"user\"=? AND \"slug\"=?"
[toSql user, toSql slug]
+
+feedByUrl :: Text -> Query FeedInfo
+feedByUrl url =
+ query "SELECT feeds.\"url\", user_feeds.\"user\", user_feeds.\"slug\", COALESCE(user_feeds.\"title\", feeds.\"title\", 'Untitled'), COALESCE(feeds.\"homepage\", ''), COALESCE(feeds.\"image\", ''), COALESCE(user_feeds.\"public\", FALSE), feeds.\"torrentify\", feeds.\"error\" FROM feeds INNER JOIN user_feeds ON feeds.url=user_feeds.feed WHERE feeds.url=? AND user_feeds.\"public\"=true" [toSql url]
data FeedDetails = FeedDetails {
fdPublic :: Bool,
View
@@ -41,7 +41,6 @@ Now point your browser to `http://localhost:8081/`.
* event=complete heuristics
* global statistics numbers
-* feed by feed lookup api
* change feed URL
* Feed Links größer
* <itunes:new-feed-url/>
View
@@ -51,6 +51,7 @@ library
Handler.MapFeed
Handler.DownloadFeeds
Handler.ByEnclosureAPI
+ Handler.FeedLookupAPI
Handler.Tracker
Handler.Help
Handler.Widget
View
@@ -10,6 +10,7 @@
/logout LogoutR GET
/by-enclosure.json ByEnclosureJson GET
+/feed-lookup.json FeedLookupJson GET
/ FrontR GET
/new NewR GET
@@ -0,0 +1,8 @@
+$ curl "http://localhost:8081/feed-lookup.json?url=http%3A%2F%2Fc3d2.de%2Fpentaradio.xml&url=http%3A%2F%2Fc3d2.de%2Fnews-rss.xml"
+{ "http://c3d2.de/news-rss.xml": [
+ "http://bitlove.org/c3d2/news/feed"
+ ],
+ "http://c3d2.de/pentaradio.xml": [
+ "http://bitlove.org/c3d2/pentaradio/feed"
+ ]
+}
View
@@ -1,24 +1,37 @@
$newline always
<section class="col">
<h2>API</h2>
+
+ <h3>Contents
+ <ul .toc>
+ <li>
+ <a href="#crawling">Crawling the site
+ <li>
+ <a href="#by-enclosure">Torrent data by enclosure URL
+ <li>
+ <a href="#feed-lookup">Feed lookup by URL
- <h3>Crawling the site</h3>
+ <h3 #crawling>Crawling the site</h3>
<p>
We try to put all publicly available data back #
into feeds and OPML resources. That way you can reuse #
standard software. You may #
<a href="https://github.com/astro/bitlove-ui/issues">create an issue</a> if you need more functionality.
- <h3>Torrent data by enclosure URL
+ <h3 #by-enclosure>Torrent data by enclosure URL
<p>
Obtain torrent (and source) information by URL #
of the original podcast files. The endpoint allows multiple URLs #
to be processed at once. They query key must start with #
<code>url
\ and you should URL-escape the values for safety.
- <pre>#{example}
+ <pre>#{by_enclosure_example}
<p>
This API is #
<a href="http://enable-cors.org/">CORS-enabled
\ and in actual use by the widgets.
-
+
+ <h3 #feed-lookup>Feed lookup by URL
+ <p>
+ Discover the URL of public feeds with their enclosures mapped to torrents:
+ <pre>#{feed_lookup_example}

0 comments on commit 7b5e229

Please sign in to comment.