-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new search-helper function. Corrected test data.
- Loading branch information
Showing
5 changed files
with
230 additions
and
1,293 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package plex | ||
|
||
const testMetadata = ` | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<MediaContainer size="1" allowSync="1" identifier="com.plexapp.plugins.library" librarySectionID="1" librarySectionTitle="TV Shows" librarySectionUUID="abc123" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1466733873"> | ||
<Directory ratingKey="1" key="/library/metadata/1/children" guid="com.plexapp.agents.thetvdb://153021?lang=en" librarySectionID="1" studio="AMC" type="show" title="The Walking Dead" titleSort="Walking Dead" contentRating="TV-MA" summary="The world we knew is gone. An epidemic of apocalyptic proportions has swept the globe causing the dead to rise and feed on the living. In a matter of months society has crumbled. In a world ruled by the dead, we are forced to finally start living. Based on a comic book series of the same name by Robert Kirkman, this AMC project focuses on the world after a zombie apocalypse. The series follows a police officer, Rick Grimes, who wakes up from a coma to find the world ravaged with zombies. Looking for his family, he and a group of survivors attempt to battle against the zombies in order to stay alive.
" index="1" rating="9.0" viewCount="22" lastViewedAt="1466507083" year="2010" thumb="/library/metadata/1/thumb/1459739349" art="/library/metadata/1/art/1459739349" banner="/library/metadata/1/banner/1459739349" theme="/library/metadata/1/theme/1459739349" duration="2400000" originallyAvailableAt="2010-10-31" leafCount="12" viewedLeafCount="11" childCount="1" addedAt="1448444228" updatedAt="1459739349"> | ||
<Genre id="47" tag="Action" /> | ||
<Genre id="6" tag="Drama" /> | ||
<Genre id="7" tag="Horror" /> | ||
<Genre id="48" tag="Suspense" /> | ||
<Role id="49" tag="Andrew Lincoln" role="Rick Grimes" /> | ||
<Role id="50" tag="Melissa McBride" role="Carol Peletier" /> | ||
<Role id="51" tag="Norman Reedus" role="Daryl Dixon" /> | ||
<Role id="52" tag="Steven Yeun" role="Glenn" /> | ||
<Role id="53" tag="Lennie James" role="Morgan Jones" /> | ||
<Role id="54" tag="Chandler Riggs" role="Carl Grimes" /> | ||
<Role id="55" tag="Lauren Cohan" role="Maggie Greene" thumb="http://image.tmdb.org/t/p/original/5W4AV3ZXn38NlEMqPy9QPjwRRz8.jpg" /> | ||
<Role id="56" tag="Danai Gurira" role="Michonne" /> | ||
<Role id="1709" tag="Tom Payne" role="Paul 'Jesus' Rovia" /> | ||
<Role id="58" tag="Austin Nichols" role="Spencer Monroe" /> | ||
<Role id="62" tag="Tyler James Williams" role="Noah" /> | ||
<Role id="63" tag="Seth Gilliam" role="Father Gabriel" /> | ||
<Role id="64" tag="Josh McDermitt" role="Eugene Porter" /> | ||
<Role id="65" tag="Christian Serratos" role="Rosita Espinosa" /> | ||
<Role id="66" tag="Michael Cudlitz" role="Abraham Ford" /> | ||
<Role id="67" tag="Alanna Masterson" role="Tara Chambler" /> | ||
<Role id="68" tag="Lawrence Gilliard Jr." role="Bob Stookey" /> | ||
<Role id="69" tag="Dallas Roberts" role="Milton Mamet" /> | ||
<Role id="70" tag="Chad L. Coleman" role="Tyreese" /> | ||
<Role id="71" tag="Sonequa Martin-Green" role="Sasha" /> | ||
<Role id="72" tag="David Morrissey" role="The Governor" thumb="http://image.tmdb.org/t/p/original/4w0XlXlk4IKO8g8HejnBHn7xOPG.jpg" /> | ||
<Role id="73" tag="Michael Rooker" role="Merle Dixon" /> | ||
<Role id="74" tag="Emily Kinney" role="Beth Greene" /> | ||
<Role id="75" tag="Scott Wilson" role="Hershel Greene" /> | ||
<Role id="76" tag="Irone Singleton" role="T-Dog" /> | ||
<Role id="77" tag="Emma Bell" role="Amy" /> | ||
<Role id="78" tag="Laurie Holden" role="Andrea" /> | ||
<Role id="79" tag="Jeffrey DeMunn" role="Dale" /> | ||
<Role id="80" tag="Jon Bernthal" role="Shane Walsh" /> | ||
<Role id="81" tag="Sarah Wayne Callies" role="Lori Grimes" /> | ||
<Role id="1993" tag="Jeffrey Dean Morgan" role="Negan" thumb="http://image.tmdb.org/t/p/original/6ors2HGy8UdXm8kBx6on0HwRHB5.jpg" /> | ||
<Label id="2455" tag="Siirclutch-guest" /> | ||
<Field name="label" locked="1" /> | ||
<Location path="/media/tv/The Walking Dead" /> | ||
</Directory> | ||
</MediaContainer> | ||
` |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package plex | ||
|
||
import "regexp" | ||
|
||
// SearchPlex searches just like Search, but omits the last 4 results which are not relevant | ||
func (p *Plex) SearchPlex(title string) (SearchResults, error) { | ||
results, err := p.Search(title) | ||
|
||
if err != nil { | ||
return SearchResults{}, err | ||
} | ||
|
||
results.Children = results.Children[:4] | ||
|
||
return results, nil | ||
} | ||
|
||
// ExtractKeyAndThumbFromURL extracts the rating key and thumbnail id from the url | ||
func (p *Plex) ExtractKeyAndThumbFromURL(_url string) (string, string) { | ||
count := len(_url) | ||
|
||
var key string | ||
var thumbID string | ||
|
||
if count > 18 { | ||
k := _url[18:] | ||
keyCount := len(k) | ||
|
||
if keyCount > 7 { | ||
// Get key | ||
for ii := 0; ii < keyCount; ii++ { | ||
if k[ii:ii+1] == "/" { | ||
key = k[:ii] | ||
thumbID = k[ii+7:] | ||
break | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
return key, thumbID | ||
} | ||
|
||
// ExtractKeyFromRatingKey extracts the key from the rating key url | ||
func (*Plex) ExtractKeyFromRatingKey(key string) string { | ||
keyCount := len(key) | ||
|
||
if keyCount > 18 { | ||
key = key[18:] | ||
keyCount = len(key) | ||
|
||
if keyCount > 9 { | ||
for ii := 0; ii < keyCount; ii++ { | ||
if key[ii:ii+1] == "/" { | ||
key = key[:ii] | ||
break | ||
} | ||
} | ||
} | ||
|
||
return key | ||
} | ||
|
||
return key | ||
} | ||
|
||
// ExtractKeyFromRatingKeyRegex extracts the key from a rating key url via regex | ||
func (p *Plex) ExtractKeyFromRatingKeyRegex(key string) string { | ||
r := regexp.MustCompile(`\d+`) | ||
result := r.FindStringSubmatch(key) | ||
|
||
if len(key) == 0 { | ||
return "" | ||
} | ||
|
||
return result[0] | ||
} |
Oops, something went wrong.