Skip to content

Commit

Permalink
Implement go-xREL-API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
hashworks committed Apr 28, 2016
1 parent b02f9b9 commit 4aa3aa7
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 222 deletions.
61 changes: 34 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See `--help`:
```
Global flags:
--configFile="/path/to/config.json"
--configFile /path/to/config.json
Sets the path to the config file to use.
Don't want a config file? Set it to /dev/null.
Expand All @@ -23,12 +23,12 @@ Global flags:
Basically it can be used with every function
that shows releases.
--perPage=5
--perPage 5
Set how many entries to show per page.
Basically it can be used with every function
that displays pagination in any way.
--page=1
--page 1
Set the page to show. Can be used along with --perPage.
Function flags:
Expand All @@ -37,43 +37,50 @@ Function flags:
Shows the version and a few informations.
--authenticate
Authenticates you with xREL.to using oAuth.
Authenticates you with xREL.to using oAuth2.
--rateLimit
Shows your current rate limit.
--searchRelease="Portal 2 Linux"
--searchRelease "Portal 2 Linux"
Search for a release. Optional parameters:
--limit=5
--limit 5
Limit output from 5 to 25 entries.
Uses value of --perPage by default.
--release="Portal.2.Linux-ACTiVATED"
--release Portal.2.Linux-ACTiVATED
Show information about a release.
Optional parameters, all of them require authentication:
--addComment="[...]"
--addComment "[...]"
Add a comment to a release.
--rateVideo=9
--rateVideo 9
Rate the video of a release from 1-10. Requires --rateAudio.
--rateAudio=8
--rateAudio 8
Rate the audio of a release from 1-10. Requires --rateVideo.
--comments="Portal.2.Linux-ACTiVATED"
--comments Portal.2.Linux-ACTiVATED
List comments of a release.
--searchMedia="The Big Bang Theory"
--getNFOImage Portal.2.Linux-ACTiVATED
Saves an image of the NFO of the specified release
in the current directory.
--addProof=filepathTo/Proof/image.png Game.of.Thrones.S05E10.Die.Gnade.der.Mutter.German.DL.1080p.BluRay.x264-RSG Game.of.Thrones.S05E10.Die.Gnade.der.Mutter.German.DL.720p.BluRay.x264-RSG
Adds a proof image to the specified releases. Requires authentication.
--searchMedia "The Big Bang Theory"
Search for media. Optional parameters:
--mediaType="tv"
--mediaType tv
Limit results by movie, tv, game, console, software or xxx.
--limit=5
--limit 5
See --searchRelease.
--addToFavorites
Add selected media to a favorites list you select.
Requires authentication.
--info
Show information about the selected media.
Only usefull if used with the following parameters.
--rate=8
--rate 8
Rate selected media from 1 to 10.
--releases
Show latest releases of the selected media.
Expand All @@ -84,42 +91,42 @@ Function flags:
--showUnreadFavorites
Select a user's favorite list and show unread releases.
Requires authentication.
Requires authentication. Optional parameters:
--markAsRead
Marks entries as read.
--removeFavoriteEntry
Select a user's favorite list and remove an entry.
Requires authentication.
--latest
Lists latest releases. Optional parameters:
--filter="overview"
--filter overview
Filter ID or 'overview' to use the currently
logged in user's overview filter.
--browseArchive="YYYY-MM"
--browseArchive YYYY-MM
Browse archive. Optional parameters:
--filter="overview"
--filter overview
See --latest.
--filters
Shows a list of public, predefined release filters
to use with --filter.
--browseCategory="topmovie"
--browseCategory topmovie
Browse a category. Optional parameters:
--mediaType="movie"
--mediaType movie
See --searchMedia.
--categories
Returns a list of categories to use with --browseCategory.
--upcomingTitles
Lists upcoming titles. Optional parameters:
--country us
Show upcoming titles for a specific country, currently
possible values are 'de' (default) and 'us'.
--releases
See --searchMedia.
```

## TODO

* Various in the code, prefixed with "TODO:"
* Add Tests
8 changes: 4 additions & 4 deletions distribute.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

if [ "$xREL_TERMINAL_CLIENT_CONSUMER_KEY" == "" ] || [ "$xREL_TERMINAL_CLIENT_CONSUMER_SECRET" == "" ]; then
echo You need to set the following env variables: xREL_TERMINAL_CLIENT_CONSUMER_KEY and xREL_TERMINAL_CLIENT_CONSUMER_SECRET. >&2
if [ "$xREL_TERMINAL_OAUTH2_CLIENT_KEY" == "" ] || [ "$xREL_TERMINAL_OAUTH2_CLIENT_SECRET" == "" ]; then
echo You need to set the following env variables: xREL_TERMINAL_OAUTH2_CLIENT_KEY and xREL_TERMINAL_OAUTH2_CLIENT_SECRET. >&2
echo Get those from http://www.xrel.to/api-apps.html >&2
exit 1
fi
Expand Down Expand Up @@ -57,8 +57,8 @@ for plat in "${platforms[@]}"; do
fi

GOOS="${plat%-*}" GOARCH="${plat#*-}" go build -ldflags '-X main.VERSION='"$version"'
-X main.OAUTH_CONSUMER_KEY='"$xREL_TERMINAL_CLIENT_CONSUMER_KEY"'
-X main.OAUTH_CONSUMER_SECRET='"$xREL_TERMINAL_CLIENT_CONSUMER_SECRET" \
-X main.OAUTH2_CLIENT_KEY='"$xREL_TERMINAL_OAUTH2_CLIENT_KEY"'
-X main.OAUTH2_CLIENT_SECRET='"$xREL_TERMINAL_OAUTH2_CLIENT_SECRET" \
-o "$tmpFile" "$DIR"/src/*.go

if [ "$?" != 0 ]; then
Expand Down
67 changes: 52 additions & 15 deletions src/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import (
"os"
"regexp"
"sort"
"strconv"
"strings"
)

func showCategories(isP2P bool) {
orderedCategories := map[string][]string{}
if isP2P {
p2pCategories, err := xrel.GetP2PCategories()
ok(err, "Failed to get p2p categories:\n")
for i := 0; i < len(p2pCategories); i++ {
categoryCount := len(p2pCategories)
if categoryCount == 0 {
fmt.Println("No p2p categories found.")
os.Exit(1)
}
ok(err, "Failed to get p2p categories: ")
for i := 0; i < categoryCount; i++ {
metaCat := strings.ToUpper(p2pCategories[i].MetaCat)
if p2pCategories[i].SubCat != "" {
orderedCategories[metaCat] = append(orderedCategories[metaCat], p2pCategories[i].SubCat)
Expand All @@ -27,8 +33,13 @@ func showCategories(isP2P bool) {
fmt.Println("Available p2p categories:")
} else {
categories, err := xrel.GetReleaseCategories()
ok(err, "Failed to get scene categories:\n")
for i := 0; i < len(categories); i++ {
categoryCount := len(categories)
if categoryCount == 0 {
fmt.Println("No categories found.")
os.Exit(1)
}
ok(err, "Failed to get scene categories: ")
for i := 0; i < categoryCount; i++ {
category := &categories[i]
if category.ParentCat != "" && category.Name != "" {
orderedCategories[category.ParentCat] = append(orderedCategories[category.ParentCat], category.Name)
Expand Down Expand Up @@ -57,15 +68,23 @@ func showCategories(isP2P bool) {
func browseCategory(categoryName, extInfoType string, isP2P bool, perPage, page int) {
if isP2P {
categoryID, err := findP2PCategoryID(categoryName)
ok(err, "Failed to get category id:\n")
ok(err, "Failed to get category id: ")
data, err := xrel.GetP2PReleases(perPage, page, categoryID, "", "")
ok(err, "Failed to browse p2p category:\n")
ok(err, "Failed to browse p2p category: ")
if len(data.List) == 0 {
fmt.Println("No p2p releases found.")
os.Exit(1)
}
printP2PReleases(data, true, false)
} else {
// Currently all categories are upper case. That might change?
categoryName = strings.ToUpper(categoryName)
data, err := xrel.BrowseReleaseCategory(categoryName, extInfoType, perPage, page)
ok(err, "Failed to browse scene category:\n")
ok(err, "Failed to browse scene category: ")
if len(data.List) == 0 {
fmt.Println("No releases found.")
os.Exit(1)
}
printSceneReleases(data, true, false)
}
}
Expand All @@ -76,21 +95,35 @@ func showFilters(isP2PFlag bool) {
os.Exit(1)
}
filters, err := xrel.GetReleaseFilters()
ok(err, "Failed to get filters:\n")
fmt.Println("Available scene filters:\n")
for i := 0; i < len(filters); i++ {
fmt.Println(filters[i].Id + ": " + filters[i].Name)
ok(err, "Failed to get filters: ")
filterCount := len(filters)
if filterCount == 0 {
fmt.Println("No filters found.")
os.Exit(1)
} else {
fmt.Println("Available scene filters: ")
for i := 0; i < filterCount; i++ {
fmt.Println(strconv.Itoa(filters[i].ID) + ": " + filters[i].Name)
}
}
}

func showLatest(filterFlag string, isP2PFlag bool, perPageFlag, pageFlag int) {
if isP2PFlag {
data, err := xrel.GetP2PReleases(perPageFlag, pageFlag, "", "", "")
ok(err, "Failed to get latest p2p releases:\n")
ok(err, "Failed to get latest p2p releases: ")
if len(data.List) == 0 {
fmt.Println("No p2p releases found.")
os.Exit(1)
}
printP2PReleases(data, false, false)
} else {
data, err := xrel.GetLatestReleases(perPageFlag, pageFlag, filterFlag, "")
ok(err, "Failed to get latest scene releases:\n")
ok(err, "Failed to get latest releases: ")
if len(data.List) == 0 {
fmt.Println("No releases found.")
os.Exit(1)
}
printSceneReleases(data, false, false)
}
}
Expand All @@ -100,10 +133,14 @@ func browseArchive(browseArchiveFlag, filterFlag string, isP2PFlag bool, perPage
fmt.Println("Due to API limitations it is impossible to browse the P2P archive.")
os.Exit(1)
} else {
matched, err := regexp.MatchString("^[0-9]{4}-[1-9]{2}$", browseArchiveFlag)
matched, err := regexp.MatchString("^[0-9]{4}-[0-9]{2}$", browseArchiveFlag)
if err == nil && matched {
data, err := xrel.GetLatestReleases(perPageFlag, pageFlag, filterFlag, browseArchiveFlag)
ok(err, "Failed to browse the scene archive:\n")
ok(err, "Failed to browse the scene archive: ")
if len(data.List) == 0 {
fmt.Println("No releases found.")
os.Exit(1)
}
printSceneReleases(data, false, false)
} else {
fmt.Println("Please use the following format: --browseArchive=YYYY-MM")
Expand Down
11 changes: 6 additions & 5 deletions src/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package main
import (
"fmt"
"github.com/hashworks/go-xREL-API/xrel"
"github.com/hashworks/go-xREL-API/xrel/types"
"os"
"strings"
)

func showUpcomingTitles(showReleases, showP2P bool) {
titles, err := xrel.GetUpcomingTitles()
ok(err, "Failed to get upcoming titles:\n")
func showUpcomingTitles(country string, showReleases, showP2P bool) {
titles, err := xrel.GetUpcomingTitles(country)
ok(err, "Failed to get upcoming titles: ")
titleCount := len(titles)
if titleCount == 0 {
fmt.Println("No upcoming titles found.")
Expand All @@ -23,12 +24,12 @@ func showUpcomingTitles(showReleases, showP2P bool) {
if showP2P {
for i := 0; i < len(title.P2PReleases); i++ {
release := title.P2PReleases[i]
fmt.Println("\t" + release.GetPubTime().Format(xRELReleaseTimeFormat) + " - " + release.Dirname)
fmt.Println("\t" + release.GetPubTime().Format(types.TIME_FORMAT_RELEASE) + " - " + release.Dirname)
}
} else {
for i := 0; i < len(title.Releases); i++ {
release := title.Releases[i]
fmt.Println("\t" + release.GetTime().Format(xRELReleaseTimeFormat) + " - " + release.Dirname)
fmt.Println("\t" + release.GetTime().Format(types.TIME_FORMAT_RELEASE) + " - " + release.Dirname)
}
}
}
Expand Down
Loading

0 comments on commit 4aa3aa7

Please sign in to comment.