• Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login
RetroPie forum home
  • Recent
  • Tags
  • Popular
  • Home
  • Docs
  • Register
  • Login

Take and Scrape Your Own Screenshots

Scheduled Pinned Locked Moved Ideas and Development
retroarchscreenshotscrapesselphruncommand
122 Posts 8 Posters 66.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    meleu @herb_fargus
    last edited by meleu 20 Aug 2016, 04:42

    @herb_fargus
    Man! What a shame!

    facepalm

    Actually the auto_screenshot_filename flag does his job very well!!

    The trailing timestamp is what the "auto" means! If you want a screenshot with the "ROM Name.png" only, you just have to set auto_screenshot_filename to false (the default is true).

    Our script here can take advantage of this feature!

    • Useful topics
    • joystick-selection tool
    • rpie-art tool
    • achievements I made
    H 1 Reply Last reply 20 Aug 2016, 04:48 Reply Quote 0
    • H
      herb_fargus administrators @meleu
      last edited by 20 Aug 2016, 04:48

      @meleu so you mean it worked this whole time? :P ha ha that's funny. Ok well I'll give it a test once I get some time to compile retroarch

      If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

      Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

      M 1 Reply Last reply 20 Aug 2016, 04:55 Reply Quote 0
      • M
        meleu @herb_fargus
        last edited by meleu 20 Aug 2016, 04:55

        @herb_fargus said in Take and Scrape Your Own Screenshots:

        @meleu so you mean it worked this whole time? :P ha ha that's funny. Ok well I'll give it a test once I get some time to compile retroarch

        yeah man! it works even before my PR was merged. There is no need to compile retroarch to get those changes I made, because the auto_screenshot_filename = "false" is what we want! My changes only takes effect when auto_screenshot_filename = "true", and the default (if this option aren't in retroarch.cfg) is true.

        We can adapt the "take and scrape your own screenshots" trick to work only when the auto_screenshot_filename = "false". I'm at work now, but I check it as soon as get in home...

        • Useful topics
        • joystick-selection tool
        • rpie-art tool
        • achievements I made
        H 1 Reply Last reply 20 Aug 2016, 05:06 Reply Quote 0
        • H
          herb_fargus administrators @meleu
          last edited by 20 Aug 2016, 05:06

          @meleu heh talk about an over engineered solution well regardless a bug was still fixed as a result so good job :) I'll see if I can update it. Maybe there's a way I can have it automatically generate folders and/or configs this time around- perhaps maybe come up with a module for it or something

          If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

          Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

          H 1 Reply Last reply 20 Aug 2016, 06:46 Reply Quote 1
          • H
            herb_fargus administrators @herb_fargus
            last edited by herb_fargus 20 Aug 2016, 06:46

            @meleu

            Alright here's a prelimnary more or less untested psuedo code for runcommand-onend.sh:

            # Variables
            system="$1"
            imgdir="$HOME/RetroPie/roms/$system/images"
            # check if images folder exists for each system, if not create it
            if [[ ! -d "$imgdir" ]]; then
            mkdir $imgdir
            fi
            ####### Possible configs to automate potentially with inifuncts?
            #### overall retroarch.cfg in /opt/retropie/configs/all:
            # Hotkey config to take screenshot with controller
            input_screenshot_btn = "12"
            # This makes sure the screenshot filename is named ROM NAME.ext
            auto_screenshot_filename = "false"
            #### system based retroarch.cfg in /opt/retropie/configs/$system/
            # Add screenshot per system directory
            screenshot_directory = "$HOME/RetroPie/roms/$system/images/"

            Really if you take out the automation, the runcommand-onend.sh is really no longer necessary, the user just has to manually edit 3 things:

            • create an images folder for each system they are scraping with

            • specify the screenshot directory in each system based retroarch.cfg e.g. screenshot_directory = "$HOME/RetroPie/roms/$system/images/"

            • add the auto_screenshot_filename = "false" to the main retroarch.cfg

            Just thinking out loud but it should be simple enough to use inifuncts with this recent change:

            https://github.com/RetroPie/RetroPie-Setup/commit/7d806d52e9fc55fd557cd4a7f931df6e07509bf3

            (a little more discussion on it here: https://retropie.org.uk/forum/topic/3285/i-think-we-finally-have-a-solution-for-rgui-fans/11)

            I'm just unsure if we have to initialise the inifuncts script on its own in the runcommand-onend since its technically already initialised here:

            https://github.com/RetroPie/RetroPie-Setup/blob/406728c368d038270651159430ded40a92df2649/scriptmodules/supplementary/runcommand/runcommand.sh#L57

            but then again variables like the $romdir $rootdir etc are initialised in the retropie_packages.sh which are obviously used in the main runcommand.sh but aren't initialised in the runcommand-onend.sh

            anyways what I'm saying is the variables are all already in the code, we may just have to call inifuncs.sh and retropie_packages.sh, or duplicate code to initialise the variables manually. idk. just ideas.

            If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

            Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

            H 1 Reply Last reply 20 Aug 2016, 08:58 Reply Quote 0
            • H
              herb_fargus administrators @herb_fargus
              last edited by herb_fargus 20 Aug 2016, 08:58

              @meleu

              Ok I think I've got it. I've tried to simplify it as best as I could. Could probably be refactored a bit anyhow. so this one is a little different in that everything is automated so many of the steps on the first post are unnecessary and it uses runcommand-onstart rather than runcommand-onend (primarily because I want it to create the image folder first before screenshots are taken so they have somewhere to go)

              so create a file with the following contents called rucommand-onstart.sh and place it in /opt/retropie/configs/all

              #!/usr/bin/env bash
              system="$1"
              imgdir="$HOME/RetroPie/roms/$system/images"
              configdir="/opt/retropie/configs"
              mainretroarch="$configdir/all/retroarch.cfg"
              systemretroarch="$configdir/$system/retroarch.cfg"
              source "/opt/retropie/lib/inifuncs.sh"
              # If there is no auto screenshot setting in the main retroarch.cfg add it
              function add_overall_screenshot() {
              if ! grep -q "auto_screenshot_filename" $mainretroarch; then
              iniConfig " = " '"' "$mainretroarch"
              iniSet "auto_screenshot_filename" "false"
              fi
              }
              # check if an images folder exists in the systems rom folder, if not create it
              function make_screenshot_dir() {
              if [[ ! -d "$imgdir" ]]; then
              mkdir $imgdir
              fi
              }
              # If there is no system based screenshot directory defined then define it in the system based retroarch.cfg
              function add_system_screenshot() {
              if ! grep -q "screenshot_directory" $systemretroarch; then
              iniConfig " = " '"' "$systemretroarch"
              iniSet "screenshot_directory" "$imgdir"
              retroarchIncludeToEnd
              fi
              }
              add_overall_screenshot
              make_screenshot_dir
              add_system_screenshot

              It may also be possible to automate sselphs scraper, but I dont think its a good fit with the onstart or onend command. perhaps its something better left as a manual step.

              If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

              Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

              M 1 Reply Last reply 20 Aug 2016, 14:27 Reply Quote 0
              • M
                meleu @herb_fargus
                last edited by meleu 20 Aug 2016, 14:27

                @herb_fargus
                I'll come back to this topic soon (I'm very sleepy after a 12 hours turn). But first I would like to share some tips/thoughts with you:

                • the scraper command you use in the first post can be faster if you use the options -skip_check=true and -use_gdb=false.

                • I don't like to use a subdir for images in the roms directory. You can use the -image_path="path/to/screenshots" to make the scraper get the images from another place.

                • I really would like to keep my previous gamelist.xml and only change the entry for the game that we recently took the screenshot. I think the way to achieve it is the -append=true option. But we need some XML parsing trick to exclude the game entry from gamelist.xml before call the scraper in order to make it consider the game as a new entry.

                I think we are on the right way...

                • Useful topics
                • joystick-selection tool
                • rpie-art tool
                • achievements I made
                H 1 Reply Last reply 20 Aug 2016, 16:15 Reply Quote 0
                • H
                  herb_fargus administrators @meleu
                  last edited by herb_fargus 20 Aug 2016, 16:15

                  @meleu those are good tips to keep in mind. I suppose that we could set the screenshot directory to just one screenshot directory (perhaps even just leave the default) and then use sselphs scraper to point to that, eliminates another config step but I like the idea of having all the images and gamelists in each rom folder because you only have to scrape once and then you can just backup/copy the roms folder complete with images etc with no need to scrape again.

                  also if you use the -skip_check=true and -use_gdb=false would that not eliminate the metadata for the detailed view so you only end up having an image?

                  I guess we'd have to get feedback to see what people prefer

                  If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                  Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                  1 Reply Last reply Reply Quote 0
                  • H
                    herb_fargus administrators @hiulit
                    last edited by 20 Aug 2016, 17:13

                    @hiulit I've created a wiki page for it with the latest working code. See first post for link

                    If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                    Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                    H M 2 Replies Last reply 20 Aug 2016, 17:19 Reply Quote 1
                    • H
                      hiulit @herb_fargus
                      last edited by 20 Aug 2016, 17:19

                      @herb_fargus nice! Thanks!

                      My little contributions to the RetroPie project:

                      • Shell-Script-Boilerplate
                      • Fun-Facts-Splashscreens
                      • Limit-Last-Played-Games
                      1 Reply Last reply Reply Quote 0
                      • M
                        meleu @herb_fargus
                        last edited by meleu 20 Aug 2016, 19:37

                        @herb_fargus
                        [EDIT: I've edited the wiki including those two options for a faster scraper execution. I intentionally didn't edit the runcommand-onstart.sh to let it as you prefer.]

                        Some points on the wiki runcommand-onstart.sh:

                        1. You can set the iniConfig just once and then pass the file to the iniSet in the 3rd argument.

                        2. the function make_screenshot_dir can be replaced by mkdir -p "$imgdir" (the -p option means "no error if existing, make parent directories as needed").

                        3. There is no need to explicitly call retroarchIncludeToEnd, since it is automatically executed when editing any file with a name that ends with "retroarch.cfg" (inifuncs feature).

                        The runcommand-onstart.sh can be simplified to this:

                        #!/usr/bin/env bash
                        system="$1"
                        imgdir="$HOME/RetroPie/roms/$system/images"
                        configdir="/opt/retropie/configs"
                        mainretroarch="$configdir/all/retroarch.cfg"
                        systemretroarch="$configdir/$system/retroarch.cfg"
                        source "/opt/retropie/lib/inifuncs.sh"
                        iniConfig " = " '"'
                        # If there is no auto screenshot setting in the main retroarch.cfg add it
                        if ! grep -q "auto_screenshot_filename" "$mainretroarch"; then
                        iniSet "auto_screenshot_filename" "false" "$mainretroarch"
                        fi
                        mkdir -p "$imgdir"
                        # If there is no system based screenshot directory defined then define it in the system based retroarch.cfg
                        if ! grep -q "screenshot_directory" $systemretroarch; then
                        iniSet "screenshot_directory" "$imgdir" "$systemretroarch"
                        fi
                        • Useful topics
                        • joystick-selection tool
                        • rpie-art tool
                        • achievements I made
                        H 1 Reply Last reply 20 Aug 2016, 21:08 Reply Quote 1
                        • H
                          herb_fargus administrators @meleu
                          last edited by 20 Aug 2016, 21:08

                          @meleu you still didn't address:

                          also if you use the -skip_check=true and -use_gdb=false would that not eliminate the metadata for the detailed view so you only end up having an image?

                          If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                          Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                          M 1 Reply Last reply 20 Aug 2016, 21:28 Reply Quote 0
                          • M
                            meleu @herb_fargus
                            last edited by 20 Aug 2016, 21:28

                            @herb_fargus I was so focused on the images thing and didn't give a proper attention to this important detail. Sorry.

                            Re-edited the wiki excluding these options.

                            • Useful topics
                            • joystick-selection tool
                            • rpie-art tool
                            • achievements I made
                            H 2 Replies Last reply 20 Aug 2016, 21:37 Reply Quote 0
                            • H
                              herb_fargus administrators @meleu
                              last edited by herb_fargus 20 Aug 2016, 21:37

                              @meleu I personally don't care about metadata but I know lots of others do.

                              Once gridview is incorporated I think those extra flags will be more useful (though I presume that it may be possible to theme metadata in with that at some point) might be a cool design to have a box on the side that changes with each game. I'll have to play with that in the future.

                              Also have you tested your code changes ;)

                              If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                              Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                              M 1 Reply Last reply 21 Aug 2016, 00:16 Reply Quote 0
                              • H
                                herb_fargus administrators @meleu
                                last edited by 21 Aug 2016, 00:05

                                @meleu I tested your code changes and they work :) thanks for the refactor. I've updated the wiki page accordingly.

                                If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                                Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                                M 2 Replies Last reply 21 Aug 2016, 11:30 Reply Quote 1
                                • M
                                  meleu @herb_fargus
                                  last edited by 21 Aug 2016, 00:16

                                  @herb_fargus said in Take and Scrape Your Own Screenshots:

                                  Also have you tested your code changes ;)

                                  hahaha... after one acquires a bad reputation it's hard to miss it...

                                  yes! I tested my code! :D
                                  I'm glad it works for you too.

                                  • Useful topics
                                  • joystick-selection tool
                                  • rpie-art tool
                                  • achievements I made
                                  1 Reply Last reply Reply Quote 0
                                  • M
                                    meleu
                                    last edited by meleu 21 Aug 2016, 00:30

                                    @herb_fargus I'm currently working on a simpler way to achieve what we want here (take and scrape your own screenshots). No need for those runcommand-on{start,end}.sh sselph scraper options complexity, just take your screenshots as you like and then execute a script to put the most recent screenshot as the scrape image. Hope to show something useful soon...

                                    • Useful topics
                                    • joystick-selection tool
                                    • rpie-art tool
                                    • achievements I made
                                    1 Reply Last reply Reply Quote 0
                                    • M
                                      meleu @herb_fargus
                                      last edited by meleu 9 Feb 2016, 04:58 21 Aug 2016, 11:30

                                      @herb_fargus
                                      Well...
                                      After reading this series of brainstorming posts, reading the gamelist.xml doc, and taking a look at some gamelist.xml files, I found a simpler solution for what we want.

                                      Let me talk about another method...

                                      user point of view

                                      Take screenshots of a game and set the most recent screenshot as the emulationstation image for this game.

                                      prerequisites

                                      • auto_screenshot_filename = false in global retroarch.cfg. It will be the flag to turn on/off the "scrape your own screenshots" functionality (it can be confusing, because "false" means "on", we can think about another flag later.).
                                      • screenshot_directory must be set to some directory in retroarch.cfg (system specific or global, system specific takes precedence).
                                      • it was made to work after a scraping (the $HOME/.emulationstation/gamelists/$system/gamelist.xml or /etc/emulationstation/gamelists/$system/gamelist.xml files must exist).

                                      how it works

                                      Summing up: put the game screenshot full path file name in the respective <image> entry, replacing the old content. If the game isn't present in gamelist.xml, create an entry for it.

                                      Let's take a look at the runcommand-onend.sh:
                                      [EDIT: the script below is just a "proof of concept". A robust and updated version is in https://raw.githubusercontent.com/meleu/share/master/screeper.sh]

                                      #!/bin/bash
                                      echo "--- start of $(basename $0) ---" >&2
                                      readonly system="$1"
                                      readonly full_path_rom="$3"
                                      readonly retroarch_cfg="/opt/retropie/configs/all/retroarch.cfg"
                                      readonly system_ra_cfg="/opt/retropie/configs/$system/retroarch.cfg"
                                      readonly gamelist="$HOME/RetroPie/roms/$system/gamelist.xml"
                                      readonly gamelist1="$HOME/.emulationstation/gamelists/$system/gamelist.xml"
                                      readonly gamelist2="/etc/emulationstation/gamelists/$system/gamelist.xml"
                                      rom="${full_path_rom##*/}"
                                      rom="${rom%.*}"
                                      scrap_img="$rom.png"
                                      source "/opt/retropie/lib/inifuncs.sh"
                                      iniConfig ' = ' '"'
                                      # only go on if the auto_screenshot_filename is false
                                      iniGet "auto_screenshot_filename" "$retroarch_cfg"
                                      if ! [[ "$ini_value" =~ ^(false|0)$ ]]; then
                                      exit 0
                                      fi
                                      # getting the screenshots directory
                                      # try system specific retroarch.cfg, if not found try the global one
                                      iniGet "screenshot_directory" "$system_ra_cfg"
                                      screenshot_dir="$ini_value"
                                      if [[ -z "$screenshot_dir" ]]; then
                                      iniGet "screenshot_directory" "$retroarch_cfg"
                                      screenshot_dir="$ini_value"
                                      if [[ -z "$screenshot_dir" ]]; then
                                      echo "You must set a path for 'screenshot_directory' in \"retroarch.cfg\"." >&2
                                      echo "Aborting..." >&2
                                      exit 1
                                      fi
                                      fi
                                      # if there is no screenshot named "ROM Name.png", we have nothing to do here
                                      if ! [[ -f "$screenshot_dir/$scrap_img" ]]; then
                                      echo "There is no screenshot for \"$rom\". Exiting..." >&2
                                      exit 0
                                      fi
                                      # if there is no "customized gamelist.xml", try the user specific,
                                      # if it fails, get the global one
                                      if ! [[ -f "$gamelist" ]]; then
                                      echo "Copying \"$gamelist1\" to \"$gamelist\"." >&2
                                      if ! cp "$gamelist1" "$gamelist" 2>/dev/null; then
                                      echo "Failed to copy \"$gamelist1\"." >&2
                                      echo "Copying \"$gamelist2\" to \"$gamelist\"." >&2
                                      if ! cp "$gamelist2" "$gamelist" 2>/dev/null; then
                                      echo "Failed to copy \"$gamelist2\"." >&2
                                      echo "Aborting..." >&2
                                      exit 1
                                      fi
                                      fi
                                      fi
                                      # the <image> entry MUST be on a single line and match the pattern:
                                      # anything followed by rom name followed or not by "-image" followed by dot followed by 3 chars
                                      old_img_regex="<image>.*$rom\(-image\)\?\....</image>"
                                      new_img_regex="<image>$screenshot_dir/$scrap_img</image>"
                                      if grep -q "$old_img_regex" "$gamelist"; then
                                      sed -i "s|$old_img_regex|$new_img_regex|" "$gamelist"
                                      else # oh! there is no entry for this game yet!
                                      gamelist_entry="\\
                                      <game id=\"\" source=\"\">\\
                                      <path>$full_path_rom</path> \\
                                      <name>$rom</name> \\
                                      <desc></desc> \\
                                      $new_img_regex \\
                                      <releasedate></releasedate> \\
                                      <developer></developer> \\
                                      <publisher></publisher> \\
                                      <genre></genre> \\
                                      </game>"
                                      sed -i "/<\/gameList>/ s|.*|${gamelist_entry}\n&|" "$gamelist"
                                      fi
                                      echo "--- end of $(basename $0) ---" >&2

                                      limitations

                                      Currently this is a kind of "proof of concept". The limitations below can be overcome if we feel that this is the way to achieve what we want.
                                      [The updated and more robust version of the script is available here: https://raw.githubusercontent.com/meleu/share/master/screeper.sh]

                                      • This method only changes the <image> entry of a particular game. So, if this game is NOT present in the gamelist.xml, nothing happens. [EDIT: if the game is not present in gamelist.xml, the script creates an entry for it]
                                      • The <image></image> entry in the gamelist.xml must be in a single line (it seems to be the default, so probably we don't have to worry about it).
                                      • The original image filename in the <image> entry must be named as ROM Name.ext or ROM Name-image.ext (ext can be any 3 characters, eg: png, bmp, jpg, etc), otherwise the sed command won't replace it. [EDIT: it wasn't a problem in my first tests here]
                                      • After a succeeded image changing, the respective <image> entry will have a full path to the image. It can be an inconvenience if the user wants to copy the gamelist.xml between computers (IMHO it's not so important. Besides that it probably won't be a problem to those who use the pi user).

                                      "I didn't like how it looks! I want my old scrapes back!"

                                      Change the auto_screenshot_filename to true in /opt/retropie/configs/all/retroarch.cfg and then delete the system specific gamelist.xml that is at the system roms directory (example for SNES: ~/RetroPie/roms/snes/gamelist.xml). Now emulationstation will get the gamelist from $HOME/.emulationstation/gamelists/$system/gamelist.xml.

                                      Restart emulationstation and you'll get back your old scrapes.

                                      where to go from here?

                                      After learn how to use the scraper with -append=true option (no success on my first tests) and if it proves to be good enough, we can evolve it to what I think would be a cool feature: scrape with screenshots only the games that aren't scraped. In other words: if the user is playing a non-scraped game and takes screenshots, then scrape this game with the most recent taken screenshot.

                                      I think its done! :D
                                      Maybe some minor bug fixes (if we found some) and minor improvements.

                                      • Useful topics
                                      • joystick-selection tool
                                      • rpie-art tool
                                      • achievements I made
                                      1 Reply Last reply Reply Quote 0
                                      • M
                                        meleu
                                        last edited by meleu 9 Feb 2016, 04:54 21 Aug 2016, 11:34

                                        Yes, I tested the code. ;-)

                                        If you want to avoid the copy'n'paste process you can get it with this command:

                                        wget "https://raw.githubusercontent.com/meleu/share/master/screeper.sh"
                                        

                                        And then rename it to runcommand-onend.sh.

                                        • Useful topics
                                        • joystick-selection tool
                                        • rpie-art tool
                                        • achievements I made
                                        1 Reply Last reply Reply Quote 0
                                        • M
                                          meleu @herb_fargus
                                          last edited by meleu 21 Aug 2016, 14:45

                                          @herb_fargus
                                          Man! I've updated the script to create an entry for the games that aren't present in gamelist.xml. I updated my big post above including the changes (yes! I tested my code!).

                                          You can get the updated code at github:

                                          wget "https://raw.githubusercontent.com/meleu/src/master/screeper.sh"
                                          

                                          Dude, it was really fun to accomplish this task. Thanks for this challenge!

                                          When you have time to test it (and agree with my method) maybe we can edit the wiki to use this method. It's up to you. (If you agree I can edit it next night).

                                          Cheers!

                                          • Useful topics
                                          • joystick-selection tool
                                          • rpie-art tool
                                          • achievements I made
                                          H 1 Reply Last reply 21 Aug 2016, 15:25 Reply Quote 0
                                          49 out of 122
                                          • First post
                                            49/122
                                            Last post

                                          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.

                                            This community forum collects and processes your personal information.
                                            consent.not_received