Skip to content

Commit

Permalink
Use a hash of the cast URL and episode title if there is no GUID
Browse files Browse the repository at this point in the history
  • Loading branch information
khlieng committed Jul 1, 2015
1 parent 55edeb4 commit 8a065c5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ var testFeed = []byte(`<?xml version="1.0" encoding="UTF-8"?>
<itunes:explicit>no</itunes:explicit>
<itunes:duration>1:15:36</itunes:duration>
<media:thumbnail url="http://www.jupiterbroadcasting.com/wp-content/uploads/2015/06/bsd-0095-v.jpg" />
<author>BSD, FreeBSD, PCBSD, PC-BSD, OpenBSD, NetBSD, DragonFlyBSD, FreeNAS, pfSense, Interview, Tutorial, ZFS, UFS (Jupiter Broadcasting)</author><media:content url="http://www.podtrac.com/pts/redirect.mp4/201406.jb-dl.cdn.scaleengine.net/bsdnow/2015/bsd-0095.mp4" fileSize="510856278" type="video/mp4" /></item><item><guid>DD438D40-D5A1-4D08-974F-0B3FAF6BDF9C</guid></item><copyright>Copyright Jupiter Broadcasting</copyright><media:credit role="author">Jupiter Broadcasting</media:credit><media:rating>nonadult</media:rating><media:description type="plain">Everything you wanted to know about BSD</media:description></channel>
<author>BSD, FreeBSD, PCBSD, PC-BSD, OpenBSD, NetBSD, DragonFlyBSD, FreeNAS, pfSense, Interview, Tutorial, ZFS, UFS (Jupiter Broadcasting)</author><media:content url="http://www.podtrac.com/pts/redirect.mp4/201406.jb-dl.cdn.scaleengine.net/bsdnow/2015/bsd-0095.mp4" fileSize="510856278" type="video/mp4" /></item>
<item><guid>DD438D40-D5A1-4D08-974F-0B3FAF6BDF9C</guid></item>
<item><title>Where dat GUID at?</title></item>
<copyright>Copyright Jupiter Broadcasting</copyright><media:credit role="author">Jupiter Broadcasting</media:credit><media:rating>nonadult</media:rating><media:description type="plain">Everything you wanted to know about BSD</media:description></channel>
</rss>`)

var atomTestFeed = []byte(`<?xml version="1.0" encoding="utf-8"?>
Expand Down
11 changes: 10 additions & 1 deletion api/crawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ func (c *crawler) save(job saveJob) bool {
for i := range episodes {
ep := episodes[i].(map[string]interface{})
eps[i].CastID = cast.ID
eps[i].GUID = extractGUID(ep, format)

guid := extractGUID(ep, format)
if guid == "" {
title, ok := ep["title"].(string)
if ok {
guid = md5Hash(cast.URL + title)
}
}

eps[i].GUID = guid
eps[i].CrawlTS = ts
feed, _ := json.Marshal(ep)
eps[i].Feed = (*json.RawMessage)(&feed)
Expand Down
8 changes: 8 additions & 0 deletions api/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package api

import (
"crypto/md5"
"encoding/hex"

"github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/labstack/echo"
)

Expand All @@ -16,3 +19,8 @@ func formContains(c *echo.Context, keys ...string) bool {
}
return true
}

func md5Hash(str string) string {
hash := md5.Sum([]byte(str))
return hex.EncodeToString(hash[:])
}
5 changes: 5 additions & 0 deletions api/util_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"crypto/md5"
"net/http"
"testing"

Expand All @@ -17,3 +18,7 @@ func TestFormContains(t *testing.T) {
c.Request().PostForm.Set("b", "val")
assert.True(t, formContains(c, "a", "b"))
}

func TestMD5(t *testing.T) {
assert.Len(t, md5Hash("stuff"), md5.Size*2)
}

0 comments on commit 8a065c5

Please sign in to comment.