Coder Social home page Coder Social logo

cheshire137 / rsteamshot Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 5.5 MB

A Ruby gem to get screenshots users have uploaded to Steam.

Home Page: https://rubygems.org/gems/rsteamshot

License: MIT License

Ruby 99.73% Shell 0.27%
ruby-gem steam mechanize screenshot video-game

rsteamshot's Introduction

Rsteamshot

Build Status

Rsteamshot is a Ruby gem for getting screenshots a user has uploaded to their Steam profile, as well as screenshots uploaded for a particular game. You can find the newest screenshots as well as the most popular screenshots. Screenshots can be paginated.

There's no Steam API that I know of that provides this screenshot data, so this gem works by using Mechanize to do web scraping on steamcommunity.com.

View source on GitHub | View docs on RubyDoc | View gem on RubyGems

Installation

Add this line to your application's Gemfile:

gem 'rsteamshot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rsteamshot

Usage

# Specify where the latest list of apps from Steam should be downloaded as a JSON file, and
# referenced when looking up app IDs:
Rsteamshot.configure do |config|
  config.apps_list_path = 'apps-list.json'
end

# Get screenshots uploaded by a Steam user:
steam_user_name = 'cheshire137'
user = Rsteamshot::User.new(steam_user_name)
user.per_page = 10
order = 'newestfirst' # also: score, oldestfirst
screenshots = user.screenshots(order: order)
screenshots += user.screenshots(order: order, page: 2)

# Search Steam apps by name:
apps = Rsteamshot::App.search('witcher 3')
# => [#<Rsteamshot::App:0x007feb28b135f8 @id=292030, @name="The Witcher 3: Wild Hunt"...
apps.size
# => 18

# Find the best match for a Steam app by name:
app = Rsteamshot::App.find_by_name('oblivion')
# => #<Rsteamshot::App:0x007feb25dbd518 @id=22330, @name="The Elder Scrolls IV: Oblivion "...

# Filter a user's screenshots to those for a particular app:
alice_screenshots = user.screenshots(app_id: '19680')

# Find a Steam app by its ID:
app = Rsteamshot::App.find_by_id(377160)
# => #<Rsteamshot::App:0x007ff800438758 @id=377160, @name="Fallout 4"...

# Utility methods for an app:
app.to_h
# => {:id=>377160, :name=>"Fallout 4"}
app.to_json
# => "{\n  \"id\": 377160,\n  \"name\": \"Fallout 4\"\n}"

# Get screenshots uploaded for a Steam game:
app.per_page = 10
order = 'mostrecent' # also: toprated, trendday, trendweek, trendthreemonths, trendsixmonths,
                     # trendyear
screenshots = app.screenshots(order: order)
screenshots += app.screenshots(order: order, page: 2)

# Search an app's screenshots:
dog_screenshots = app.screenshots(query: 'dog', order: 'trendweek')

# Data available for each screenshot:
screenshots.each do |screenshot|
  screenshot.title
  # => "Lovely sunset in Toussaint"

  screenshot.details_url
  # => "http://steamcommunity.com/sharedfiles/filedetails/?id=737284878"

  screenshot.full_size_url
  # => "https://steamuserimages-a.akamaihd.net/ugc/1621679306978373648/FACBF0285AFB413467E0E76371E8796D8E8C263D/"

  screenshot.medium_url
  # => "https://steamuserimages-a.akamaihd.net/ugc/1621679306978373648/FACBF0285AFB413467E0E76371E8796D8E8C263D/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to%3D%2A%2C%2A%7C1024%3A576&background-color=black"

  screenshot.user_name
  # => "cheshire137"

  screenshot.user_url
  # => "http://steamcommunity.com/id/cheshire137"

  screenshot.date
  # => #<DateTime: 2016-08-03T20:54:00+00:00 ((2457604j,75240s,0n),+0s,2299161j)>

  screenshot.file_size
  # => "0.367 MB"

  screenshot.file_size_in_bytes
  # => 367000

  screenshot.width
  # => 1920

  screenshot.height
  # => 1080

  screenshot.like_count
  # => 0

  screenshot.comment_count
  # => 0

  # Utility methods:
  screenshot.to_h
  # => {:details_url=>"http://steamcommunity.com/sharedfiles/filedetails/?id=737284878", :title=>...

  screenshot.to_json
  # => "{\n  \"details_url\": \"http://steamcommunity.com/sharedfiles/filedetails/?id=737284878\",
end

# Force the Steam apps list to be re-downloaded:
Rsteamshot::App.reset_list
Rsteamshot::App.download_apps_list

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

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.

Contributing

Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

rsteamshot's People

Contributors

cheshire137 avatar marcqualie avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

jessrudder

rsteamshot's Issues

Add integer file size in bytes

To complement Rsteamshot::Screenshot#file_size, a new method #file_size_in_bytes would be nice. It should return an integer based on the #file_size string, parsed and converted to bytes.

Add #app_name, #app_id to screenshot

The app ID will already be known for screenshots looked up for an app, and possibly the app name will be known if the user initialized the Rsteamshot::App from the #search method. Otherwise, the app name can be found on the details page, e.g., http://steamcommunity.com/sharedfiles/filedetails/?id=749227857 has "The Elder Scrolls IV: Oblivion " up top. The app ID can be gotten from the link to the "Store Page" in the top right, e.g., http://store.steampowered.com/app/22330.

Maybe an #app method that returns an Rsteamshot::App instance would make more sense instead? Could do a similar thing with a #user method instead of having user_name and user_url. Could then add #url to User.

Add app method to search by name and take the first result

Add a class method to Rsteamshot::App such that I can pass in a string like "witcher 3" and a path to the apps list JSON file, and it will return an App instance for the first search result matching that string from the app list. Kind of an "I'm feeling lucky" for Steam apps, assuming that the first result will be the best fit.

I'm picturing an interface like this:

app = Rsteamshot::App.find_by_name("witcher 3")
# => #<Rsteamshot::App:0x007f85c2f38f00 @id=292030, @name="The Witcher 3: Wild Hunt", ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.