xbox_video 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bcb5e006a94f0dcd974ca35b3b07774bb3066fa5
4
+ data.tar.gz: dd42f839e8c36833733d8c148c67532e59ed7de3
5
+ SHA512:
6
+ metadata.gz: 3f5985ab6c89c7666b07aa244c55628fa4995b9d1e795806588c6ba0c9307e8754d0d70780d46fe910b6fa9d43027a431acf523a30528c81701f35a4dcdbd5d0
7
+ data.tar.gz: 8dbb98012b04f7440aca7d990f1cb7546df37e75aba8390cbb2c87a7053390d32f309fd830fce486e8fb512e5b8b918ec8158c09ffba03909838cb3bbc781f6c
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xbox_video.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 doomy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # XboxVideo
2
+
3
+ The `xbox_video` gem is an API interface for Xbox Live video recordings. Basically, it'll find videos recently uploaded
4
+ by users to Xbox live. It's pretty entertaining.
5
+
6
+ # Attribution
7
+
8
+ This is possible because of [gabe_k](https://github.com/gabe-k) and his work on the original python script, [xbox_live_video_thing](https://github.com/gabe-k/xbox_live_video_thing/blob/master/xbox_api_client.py).
9
+ This is simply a wrapper for his work.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'xbox_video'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install xbox_video
26
+
27
+ ## Usage
28
+
29
+ To use, require the `xbox_video` gem. You will need authorization before using the gem. You can find this by signing
30
+ into your [Xbox account](https://account.xbox.com). After signing in, go to your profile page and open up developer tools.
31
+ Find XHR requests, and look for an `Authorization` header. It should look similar to this:
32
+
33
+ ```
34
+ XBL3.0 x=3234823942052384923042398423;93482093482394...
35
+ ```
36
+
37
+ The entire string is fairly long, so you may want to save it into a file, or as an environment variable. Make sure to include
38
+ everything, including the `XBL3.0 x=...`.
39
+
40
+ Once you have your code, instantiate the XboxVideo client. The following example assumes you have your authorization code
41
+ exported to the `XBOX_KEY` environment variable.
42
+
43
+ ```ruby
44
+ client = XboxVideo::Client.new(ENV['XBOX_KEY'])
45
+ ```
46
+
47
+ Once your client is instantiated, you can start to find videos. These videos are user generated, and new. The following will
48
+ return an array of `Video` objects from a random game.
49
+
50
+ ```ruby
51
+ videos = client.get_videos
52
+ ```
53
+
54
+ If you would like to search videos from a specific game, you can either specify the ID or game title. You can browse
55
+ all known games in the `lib/xbox_video/games.yml` file. Only several are documented right now, so please feel free to add
56
+ additional games.
57
+
58
+ ```ruby
59
+ # both of these return results for forza motorsport 5
60
+ videos = client.get_videos(game: 'forza motorsport 5')
61
+ videos = client.get_videos(game_id: 2067126551)
62
+ ```
63
+
64
+ Each `Video` object contains several attributes - most usefully, the `clips` attribute, which holds an array of `Clip` objects.
65
+ Each `Clip` object (usually only one per video) contains a few attributes, most usefully the `uri`, that allows us to view and download the video.
66
+
67
+ Instead of parsing everything out manually, we can simply download a video with our `Client` object.
68
+
69
+ ```ruby
70
+ client.download(video: videos.first, path: '/path/to/my/desired/folder/')
71
+ ```
72
+
73
+ If we wanted more, we could download an array of video objects. Take note, this may take a long time.
74
+
75
+ ```ruby
76
+ client.download_all(videos: videos, path: '/path/to/my/desired/folder/')
77
+ ```
78
+
79
+ If we wanted to download a random video, we could do the following. Take note that we don't have to search for a video first.
80
+ We can call this immediately after instantiating our `Client` object. All we need to specify is a path.
81
+
82
+ ```ruby
83
+ client.download_random(path: '/path/to/my/desired/folder/')
84
+ ```
85
+
86
+ ## Development
87
+
88
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
+
90
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/piedoom/xbox_video.
95
+
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
100
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xbox_video"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,69 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'open-uri'
5
+
6
+ require_relative 'video'
7
+
8
+ BASE_URL = 'https://gameclipsmetadata.xboxlive.com'
9
+ GAME_LIST = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'games.yml'))
10
+
11
+ module XboxVideo
12
+ class Client
13
+ def initialize(key)
14
+ @key = key
15
+ end
16
+
17
+ # users can search by specifying the game title or game id
18
+ def get_videos(game: nil, game_id: nil)
19
+
20
+ # check if user specified a game_id
21
+ if game_id.nil?
22
+ # get random game if none listed
23
+ game.nil? ? game_id = GAME_LIST[GAME_LIST.keys.sample] : game_id = GAME_LIST[game.downcase.gsub(":",' ')]
24
+ end
25
+
26
+ uri = "#{BASE_URL}/public/titles/#{game_id}/clips?qualifier=created&type=userGenerated"
27
+ puts uri
28
+ response = RestClient.get(uri, :'Authorization' => @key, :'contract_version' => 2)
29
+ parsed = JSON.parse(response)
30
+ videos = create_videos(parsed)
31
+ end
32
+
33
+ # download a clip. Pass in a video object and a pathname.
34
+ def download(video:,path:)
35
+ path = "#{video.game} #{video.title} #{video.clip_id}"
36
+ File.open("#{path}.mp4",'wb') do |save_file|
37
+ open(video.clips.first.uri, 'rb') do |read_file|
38
+ save_file.write(read_file.read)
39
+ end
40
+ end
41
+ end
42
+
43
+ def download_random(path: )
44
+ videos = get_videos
45
+ video = videos.sample
46
+ download(video: video, path: path)
47
+ end
48
+
49
+ # pass in an array of video objects to be downloaded
50
+ def download_all(videos:,path:)
51
+ videos.each do |video|
52
+ download(video: video, path: path)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def create_videos videos_hash
59
+ videos = []
60
+ videos_hash['gameClips'].each do |video|
61
+ videos.push(XboxVideo::Video.new(video))
62
+ end
63
+
64
+ videos
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,12 @@
1
+ module XboxVideo
2
+ class Clip
3
+ attr_accessor :uri, :file_size, :uri_type, :expiration
4
+
5
+ def initialize(block)
6
+ @uri = block['uri']
7
+ @file_size = block['fileSize']
8
+ @uri_type = block['uriType']
9
+ @expiration = block['expiration']
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ # titles for games must be added in alphabetical order
2
+ # please only include alphanumerical characters, spaces, dashes, and underscores in the name
3
+ # make all characters lowercase
4
+
5
+ 'assassins creed iv black flag': 556718860
6
+ 'call of duty ghosts': 572802557
7
+ 'child of light': 1512517621
8
+ 'contrast': 370169912
9
+ 'crimson dragon': 461173340
10
+ 'dead rising 3': 1923160643
11
+ 'ea sports ufc': 548464799
12
+ 'fifa 14': 1813362885
13
+ 'fighter within': 1569388578
14
+ 'forza motorsport 5': 2067126551
15
+ 'guacamelee super turbo championship edition': 1958071699
16
+ 'halo spartan assult': 682562723
17
+ 'just dance 2014': 1006362568
18
+ 'killer instinct': 58472989
19
+ 'kinect sports rivals': 1840996916
20
+ 'lego marvel super heroes': 470244957
21
+ 'lococycle': 1721636964
22
+ 'madden nfl 25': 142841733
23
+ 'max the curse of brotherhood': 1649675719
24
+ 'murdered soul suspect': 1839786246
25
+ 'nba 2k14': 778400368
26
+ 'need for speed rivals': 956568979
27
+ 'outlast': 196423588
28
+ 'peggle 2': 848717329
29
+ 'plants vs zombies garden warfare': 860666361
30
+ 'powerstar golf': 1302301894
31
+ 'rayman legends': 666757656
32
+ 'ryse son of rome': 1708767297
33
+ 'sniper elite 3': 269700535
34
+ 'strider': 2029929513
35
+ 'super time force': 255219908
36
+ 'the amazing spider-man 2': 1999803984
37
+ 'the lego movie videogame': 1755825192
38
+ 'thief': 1181281124
39
+ 'titanfall': 1292135256
40
+ 'tomb raider definitive edition': 826545257
41
+ 'trials fusion': 1265757851
42
+ 'valiant hearts the great war': 1211542442
43
+ 'watch_dogs': 585771792
44
+ 'wolfenstein the new order': 1981403899
45
+ 'worms battlegrounds': 1307429766
46
+ 'zoo tycoon': 711381438
@@ -0,0 +1,11 @@
1
+ module XboxVideo
2
+ class Thumbnail
3
+ attr_accessor :uri, :file_size, :size
4
+
5
+ def initialize(block)
6
+ @uri = block['uri']
7
+ @file_size = block['fileSize']
8
+ @size = block['thumbnailType']
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module XboxVideo
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,55 @@
1
+ require_relative 'thumbnail'
2
+ require_relative 'clip'
3
+
4
+ module XboxVideo
5
+ class Video
6
+ attr_accessor :clip_id, :published, :publish_date, :record_date, :modified_date, :caption, :type, :duration,
7
+ :rating, :rating_count, :views, :title, :game, :device, :likes_count, :shares_count, :comments_count,
8
+ :thumbnails, :clips
9
+
10
+ def initialize(options={})
11
+ @clip_id = options['gameClipId']
12
+ @published = (options['state'] == 'Published')
13
+ @publish_date = options['datePublished']
14
+ @record_date = options['dateRecorded']
15
+ @modified_date = options['lastModified']
16
+ @caption = options['userCaption']
17
+ @type = options['userCaption']
18
+ @duration = options['durationInSeconds']
19
+ @rating = options['rating']
20
+ @rating_count = options['ratingCount']
21
+ @views = options['views']
22
+ @title = options['clipName']
23
+ @game = options['titleName']
24
+ @device = options['deviceType']
25
+ @likes_count = options['likeCount']
26
+ @shares_count = options['shareCount']
27
+ @comments_count = options['commentCount']
28
+ @thumbnails = generate_thumbnails options['thumbnails']
29
+ @clips = generate_clips options['gameClipUris']
30
+ end
31
+
32
+ private
33
+
34
+ def generate_thumbnails thumbnails_hash
35
+ thumbnails = []
36
+ thumbnails_hash.each do |thumbnail|
37
+ thumbnails.push(Thumbnail.new(thumbnail))
38
+ end
39
+
40
+ thumbnails
41
+
42
+ end
43
+
44
+ def generate_clips clips_hash
45
+ clips = []
46
+ clips_hash.each do |clip|
47
+ clips.push(Clip.new(clip))
48
+ end
49
+
50
+ clips
51
+
52
+ end
53
+
54
+ end
55
+ end
data/lib/xbox_video.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "xbox_video/version"
2
+ require "xbox_video/client"
3
+
4
+ module XboxVideo
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xbox_video/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xbox_video"
8
+ spec.version = XboxVideo::VERSION
9
+ spec.authors = ["doomy", "gabe_k"]
10
+ spec.email = ["alexanderpaullozada@gmail.com"]
11
+
12
+ spec.summary = "A way to get random new user-uploaded game videos from Xbox live."
13
+ spec.homepage = "https://github.com/piedoom/xbox_video"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rest-client"
32
+ spec.add_development_dependency "json"
33
+ spec.add_development_dependency "minitest", "~> 5.0"
34
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xbox_video
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - doomy
8
+ - gabe_k
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.11'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rest-client
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: json
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '5.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '5.0'
84
+ description:
85
+ email:
86
+ - alexanderpaullozada@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/xbox_video.rb
100
+ - lib/xbox_video/client.rb
101
+ - lib/xbox_video/clip.rb
102
+ - lib/xbox_video/games.yml
103
+ - lib/xbox_video/thumbnail.rb
104
+ - lib/xbox_video/version.rb
105
+ - lib/xbox_video/video.rb
106
+ - xbox_video.gemspec
107
+ homepage: https://github.com/piedoom/xbox_video
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.8
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A way to get random new user-uploaded game videos from Xbox live.
132
+ test_files: []