Skip to content

Commit 1998f54

Browse files
committed
Stream: Allow stream command
1 parent 4ac6c5a commit 1998f54

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
<a href="https://goreportcard.com/report/github.com/bisoncorps/gophie">
88
<img src="https://goreportcard.com/badge/github.com/bisoncorps/gophie" alt="Go Report Card">
99
</a>
10-
<a href="https://opensource.org/licenses/MIT">
11-
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT">
12-
</a>
1310
<a href="https://travis-ci.com/bisoncorps/gophie">
1411
<img src="https://travis-ci.com/bisoncorps/gophie.svg?branch=master" alt="Build Status">
1512
</a>
@@ -36,6 +33,7 @@ gophie
3633

3734
![Demo](assets/demo.gif)
3835
```bash
36+
>>> gophie
3937
Gophie
4038

4139
Usage:
@@ -48,6 +46,7 @@ Available Commands:
4846
list lists the recent movies by page number
4947
resume resume downloads for previously stopped movies
5048
search search for a movie
49+
stream Stream a video from gophie
5150
version Get Gophie Version
5251

5352
Flags:

cmd/stream.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"strings"
20+
21+
"github.com/bisoncorps/gophie/engine"
22+
"github.com/bisoncorps/mplayer"
23+
log "github.com/sirupsen/logrus"
24+
"github.com/spf13/cobra"
25+
"github.com/spf13/viper"
26+
)
27+
28+
var selectedPlayer string
29+
30+
const DEFAULT_PLAYER = "browser"
31+
32+
// streamCmd represents the stream command
33+
var streamCmd = &cobra.Command{
34+
Use: "stream",
35+
Short: "Stream a video from gophie",
36+
Long: `Sometimes you do not want to download. Gophie stream allows streaming videos using browser player.
37+
You can pass a query argument to the stream call to search for a specific query or left blank to retrieve
38+
latest uploaded movies on the specified engine. Full list of supported players can be found at https://github.com/bisoncorps/mplayer.
39+
40+
example:
41+
gophie stream Jumanji - stream Jumanji
42+
gophie stream -e fzmovies - check for latest movies on fzmovies for streaming
43+
`,
44+
Run: func(cmd *cobra.Command, args []string) {
45+
selectedEngine, err := engine.GetEngine(viper.GetString("engine"))
46+
if err != nil {
47+
log.Fatal(err)
48+
}
49+
query := strings.Join(args, " ")
50+
var movie engine.Movie
51+
if query == "" {
52+
movie = processList(1, selectedEngine)
53+
} else {
54+
movie = processSearch(query, selectedEngine)
55+
}
56+
p, err := mplayer.GetPlayer(selectedPlayer)
57+
if err != nil {
58+
log.Fatal(err)
59+
}
60+
p.SetURL(movie.DownloadLink.String())
61+
p.SetTitle(movie.Title)
62+
p.Play()
63+
},
64+
}
65+
66+
func init() {
67+
streamCmd.Flags().StringVarP(
68+
&selectedPlayer, "player", "p", DEFAULT_PLAYER, "Player to use for streaming (default: browser)")
69+
rootCmd.AddCommand(streamCmd)
70+
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/antchfx/htmlquery v1.2.2 // indirect
88
github.com/antchfx/xmlquery v1.2.3 // indirect
99
github.com/antchfx/xpath v1.1.4 // indirect
10+
github.com/bisoncorps/mplayer v0.0.0-20200330192254-e2f647162350
1011
github.com/briandowns/spinner v1.9.0
1112
github.com/cheggaaa/pb/v3 v3.0.4
1213
github.com/fatih/color v1.9.0 // indirect
@@ -16,7 +17,7 @@ require (
1617
github.com/iawia002/annie v0.0.0-20200217104547-c4b096ad402a
1718
github.com/manifoldco/promptui v0.7.0
1819
github.com/mitchellh/go-homedir v1.1.0
19-
github.com/sirupsen/logrus v1.2.0
20+
github.com/sirupsen/logrus v1.4.2
2021
github.com/spf13/cobra v0.0.5
2122
github.com/spf13/viper v1.6.2
2223
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ github.com/antchfx/xpath v1.1.4/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNY
3232
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
3333
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
3434
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
35+
github.com/bisoncorps/mplayer v0.0.0-20200322194618-a571bdb0e718 h1:xKZkESrsUz7fC+RfmH9BPNtmD8HqFEXrjDeKpO2k0SU=
36+
github.com/bisoncorps/mplayer v0.0.0-20200322201029-721d94659427 h1:EZD4S3knn2lYq/pU9teBH6eni0DjOotOF+xjOhN02Dk=
37+
github.com/bisoncorps/mplayer v0.0.0-20200322201029-721d94659427/go.mod h1:r1baNt23WYxinzhQ16y+gPe73dRe/0e4/jOyW5Y9mHk=
38+
github.com/bisoncorps/mplayer v0.0.0-20200323113337-8dd264ea57e4 h1:OgAQR2aGIBGKOp4xFQ3fC6T0J0WImJ5rHK0uPrMbpsA=
39+
github.com/bisoncorps/mplayer v0.0.0-20200323113337-8dd264ea57e4/go.mod h1:KT1eUGk8Y07NyBhjTrKe0r0eqhv7DQRlJpLLii1kH8s=
40+
github.com/bisoncorps/mplayer v0.0.0-20200330192254-e2f647162350 h1:562G6+GDTx5KZ6keI7SQnI7uMqQ6LaP5QITvjVutTUs=
41+
github.com/bisoncorps/mplayer v0.0.0-20200330192254-e2f647162350/go.mod h1:KT1eUGk8Y07NyBhjTrKe0r0eqhv7DQRlJpLLii1kH8s=
3542
github.com/briandowns/spinner v1.9.0 h1:+OMAisemaHar1hjuJ3Z2hIvNhQl9Y7GLPWUwwz2Pxo8=
3643
github.com/briandowns/spinner v1.9.0/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ=
3744
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
@@ -83,6 +90,7 @@ github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4er
8390
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY=
8491
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
8592
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
93+
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
8694
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
8795
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
8896
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -176,6 +184,8 @@ github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj
176184
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
177185
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
178186
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
187+
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
188+
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
179189
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
180190
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
181191
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
@@ -259,13 +269,15 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5h
259269
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
260270
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
261271
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
272+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
262273
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
263274
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
264275
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
265276
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
266277
golang.org/x/sys v0.0.0-20191104094858-e8c54fb511f6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
267278
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
268279
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
280+
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
269281
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
270282
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
271283
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
@@ -276,6 +288,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
276288
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
277289
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
278290
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
291+
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
279292
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
280293
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
281294
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -301,3 +314,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
301314
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
302315
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
303316
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
317+
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
318+
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

0 commit comments

Comments
 (0)