cinema 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cinema.rb +34 -14
  3. data/lib/cinema/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5d225844e5eceadc94ca34949f795de82bacdb5
4
- data.tar.gz: e563cc3990759300cc0195594388636804cf540d
3
+ metadata.gz: 40198843fe3c5d3b28ff47d8f262003c8a31ff97
4
+ data.tar.gz: bd9fe004867afdb96c052cdc3c92f7ef52f33474
5
5
  SHA512:
6
- metadata.gz: ea4a757678da6db59842ed64c5cf3352deb35c6cf60bd8379903edcfb5c68992e44b1cbd17c7777cf5c7161fa2df36e423220ebfbd4a5ebed5e7273b93b38073
7
- data.tar.gz: 4767c973f7322eccd6458c36c61880a09191ff021ebb0210e412ffb8577c472cd57e0823192932be39a496516fc15cb31c4e2ac6d252ffd7e252b5c23330b076
6
+ metadata.gz: 8b00d6cbcb7b576bcad702bf33aa4822633151706117b6b949c9b4bf6b6501f0bd9c99436cae180cebe02b87c70cb814012a7fe98e4f2eeb0d304975cf401262
7
+ data.tar.gz: 3244358108007330ec72320b8398204b028e3c1126bb9cea806b0e9922362a7c961c97c360bd4dfa9ed78871fa021cf6ec352b07519adb2576ecdb1ce24c9e70
@@ -11,19 +11,23 @@ module Cinema
11
11
  APP_ID="69f18bbaff859f035d934888f846b7ae3653e223a2b0f15629bcc9b836d3996b"
12
12
  APP_SECRET="077edf5024fca4102295263e802631f52f8cebd404f612194279f059bc5d9b8d"
13
13
 
14
- def ask_and_play
15
- imdb_id = select("Select movie",
16
- watchlist.sort_by{|x| x["released"]},
17
- ->(x){ x["movie"]["title"] })["movie"]["ids"]["imdb"]
18
- unless imdb_id
19
- print "imdb id: "
20
- imdb_id = gets.chomp
14
+ def get_sorting_options(sample)
15
+ sample.reduce([]) do |result, (k,v)|
16
+ if v.is_a? Hash
17
+ child_sorting_options = get_sorting_options(v).map do |name, accessor|
18
+ ["#{k} #{name}", ->(x){ accessor.(x[k]) }]
19
+ end
20
+ result.concat child_sorting_options
21
+ else
22
+ result << [k.to_s, ->(x){ x[k] }]
23
+ end
21
24
  end
22
- torrent = select("Select quality", torrents(imdb_id), ->(x){ x["quality"] })["url"]
23
- downloader = select("Select downloader", ["peerflix", "qbittorrent", "wget", "echo"], ->(x){x})
25
+ end
26
+
27
+ def run_torrent(downloader, torrent)
24
28
  case downloader
25
29
  when 'peerflix'
26
- player = select("Select player", ["mplayer","vlc"], ->(x){x})
30
+ player = select("Select player", ["mplayer","vlc"])
27
31
  system downloader, torrent, "--#{player}"
28
32
  when 'qbittorrent'
29
33
  system "sh", "-c", "#{downloader} #{torrent} &"
@@ -32,20 +36,36 @@ module Cinema
32
36
  end
33
37
  end
34
38
 
35
- def select(title, items, title_proc)
36
- menu_items = items.each_with_index.map{|x,i| [i.to_s, title_proc.(x)]}
39
+ def ask_and_play
40
+ watchlist = get_watchlist
41
+ sorting_options = get_sorting_options(watchlist.first)
42
+ sort_getter = select("Order movie list by", sorting_options, &:first).last
43
+
44
+ imdb_id = select("Select movie", watchlist.sort_by{|x| sort_getter.(x)}){ |x|
45
+ "#{sort_getter.(x)}: #{x["movie"]["title"]}"
46
+ }["movie"]["ids"]["imdb"]
47
+
48
+ torrent = select("Select quality", torrents(imdb_id)){|x| x["quality"] }["url"]
49
+ downloader = select("Select downloader", ["peerflix", "qbittorrent", "wget", "echo"])
50
+ run_torrent(downloader, torrent)
51
+ end
52
+
53
+ def select(title, items, &title_proc)
54
+ menu_items = items.each_with_index.map do |x,i|
55
+ [i.to_s, (title_proc ? title_proc.(x) : x)]
56
+ end
37
57
  index = capture_stderr do
38
58
  success = system 'dialog', '--title', title,
39
59
  '--menu', '', '0', '0', '0',
40
60
  *menu_items.flatten
41
61
  unless success
42
- return nil
62
+ exit 0
43
63
  end
44
64
  end
45
65
  items[index.to_i] if index
46
66
  end
47
67
 
48
- def watchlist
68
+ def get_watchlist
49
69
  with_unreliable_api do
50
70
  puts "Requesting watchlist..."
51
71
  trakt_request(:get, "sync/watchlist/movies")
@@ -1,3 +1,3 @@
1
1
  module Cinema
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ales Guzik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-09 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler