Advertisement
Guest User

test

a guest
Sep 14th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.96 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. releaseDate=14.09.2017
  3. echo "fastscraper ver. $releaseDate"
  4.  
  5. # Set ScreenScraper credentials
  6. username=""
  7. password=""
  8.  
  9. # Interface language selection (auto, es, de, fr, en)
  10. lang=auto
  11.  
  12. # Flags - Static parameters
  13. # If true, add roms that are not found as an empty gamelist entry.
  14. addNotFound=-add_not_found=false
  15.  
  16. # Comma separated order to prefer images, s=snapshot, b=boxart, f=fanart, a=banner, l=logo, 3b=3D boxart, cart=cartridge, clabel=cartridge label, mix3=Standard 3 mix, mix4=Standard 4 mix. (default "b")
  17. consoleImg=-console_img="mix3,b,s"
  18.  
  19. # Comma seperated order to prefer console sources, ss=screenscraper, ovgdb=OpenVGDB, gdb=theGamesDB (default "gdb")
  20. consoleSrc=-console_src="ss"
  21.  
  22. # If true, convert videos for the Raspberry Pi (e.g. 320x240@30fps) NOTE: This needs HandBrakeCLI installed
  23. convertVideo=-convert_videos="true"
  24.  
  25. # If false, don't download any images, instead see if the expected file is stored locally already. (default true)
  26. downloadImg=-download_images=true
  27.  
  28. # If true, download marquees.
  29. downloadMarquee=-download_marquees="false"
  30.  
  31. # If true, download videos.
  32. downloadVideo=-download_videos="false"
  33.  
  34. # Comma separated list of extensions to also include in the scraper.
  35. extraExt=-extra_ext=".scummvm,.ipf,.mx1,.mx2,.exe,.ws,.wsc,.wad,.dsk,.tap,.trd,.tzx,.z80,.p,.a0,.crt,.nib,.do,.po"
  36.  
  37. # jpg or png, the format to write the images. (default "jpg")
  38. imgFormat=-img_format="png"
  39.  
  40. # The path to use for images in gamelist.xml. (default "images")
  41. imagePath=-image_path="./downloaded_images"
  42.  
  43. # The suffix added after rom name when creating image files. (default "-image")
  44. imageSuffix=-image_suffix="-image"
  45.  
  46. # The order to choose for language if there is more than one for a value. (en, fr, es, de, pt) (default "en")
  47. langSS=-lang="en,es,pt,de,fr"
  48.  
  49. # Comma separated order to prefer images, s=snap, t=title, m=marquee, c=cabniet, b=boxart, 3b=3D-boxart, fly=flyer. (default "t,m,s,c")
  50. mameImg=-mame_img="b,s,fly,m,t"
  51.  
  52. # Comma seperated order to prefer mame sources, ss=screenscraper, adb=arcadeitalia, mamedb=mamedb-mirror, gdb=theGamesDB-neogeo (default "adb,gdb")
  53. mameSrc=-mame_src="ss"
  54.  
  55. # jpg or png, the format to write the marquees. (default "png")
  56. marqueeFormat=-marquee_format="png"
  57.  
  58. # The path to use for marquees in gamelist.xml. (default "images")
  59. marqueePath=-marquee_path="./downloaded_images"
  60.  
  61. # The suffix added after rom name when creating marquee files. (default "-marquee")
  62. marqueeSuffix=-marquee_suffix="-marquee"
  63.  
  64. # The max height of images. Larger images will be resized.
  65. maxHeight=-max_height=0
  66.  
  67. # The max width of images. Larger images will be resized. (default 400)
  68. maxWidth=-max_width=400
  69.  
  70. # Don't add thumbnails to the gamelist.
  71. noThumb=-no_thumb=true
  72.  
  73. # Download the thumbnail for both the image and thumb (faster). (default "false")
  74. thumbOnly=-thumb_only=false
  75.  
  76. # Information will be attempted to be downloaded again but won't remove roms that are not scraped.
  77. refreshXML=-refresh=false
  78.  
  79. # The order to choose for region if there is more than one for a value. xx is a special region that will choose any region. (default "us,wor,eu,jp,fr,xx")
  80. regionSS=-region="us,wor,eu,jp,fr,xx"
  81.  
  82. # The `username` for registered ScreenScraper users.
  83. username=-ss_user=$username
  84.  
  85. # The `password` for registered ScreenScraper users.
  86. password=-ss_password=$password
  87.  
  88. # If true, use the filename minus the extension as the game title in xml.
  89. useFilename=-use_filename=false
  90.  
  91. # Use the name in the No-Intro DB instead of the one in the GDB. (default true)
  92. useNoIntroName=-use_nointro_name=true
  93.  
  94. # The path to use for videos in gamelist.xml. (default "images")
  95. videoPath=-video_path="./downloaded_images"
  96.  
  97. # The suffix added after rom name when creating video files. (default "-video")
  98. videoSuffix=-video_suffix="-video"
  99.  
  100. # Use N worker threads to process roms. (default 1)
  101. workersN=-workers=4
  102.  
  103. # Create dictionary
  104. # Get OS's language
  105. if [ -f "/recalbox/share/system/recalbox.conf" ]; then
  106. language=$(grep '^system.language' /recalbox/share/system/recalbox.conf | cut -d '=' -f 2 | cut -d '_' -f 1)
  107. else
  108. language=$(locale | grep 'LANG=' | cut -d '=' -f2 | cut -d '"' -f2 | cut -d '_' -f1)
  109. fi
  110.  
  111. # Select dictionary
  112. if [[ "$lang" =~ ^(es|de|fr|en)$ ]]; then language=$lang
  113. case $language in
  114. es)
  115. dict=('ERROR: Sin conexión a internet. Saliendo...' 'no es una plataforma soportada.' 'ERROR: Imposible descargar el scraper. Saliendo...' 'ERROR: Imposible descomprimir el scraper. Saliendo...' 'ERROR: Imposible comprobar actualizaciones en GitHub.' 'Actualizando sselph scraper de' 'a' ', espere por favor...' 'Descargando sselph scraper' 'Abriendo Explorador de Carpetas...' 'Explorador de Carpetas para' ' aun no implementado, lo siento!' 'Carpeta de roms seleccionada:' 'No olvides detener EmulationStation antes de scrapear!' '¿Qué sistema(s) desea scrapear? Escriba "all" para todos los sistemas o "cd" para abrir el navegador de carpetas.' 'Entrada incorrecta!' '¿Deseas anexar los gamelists existentes? [Y/N]:' 'Scrapeando' 'en progreso. Espere por favor...' 'Inicio' 'Fin' 'Duración' 'Por favor, seleccione la carpeta de roms.' 'Scrapeado finalizado!') ;;
  116. de)
  117. dict=('FEHLER: Keine Internetverbindung verfügbar. Beenden...' 'ist kein unterstütztes Betriebssystem.' 'FEHLER: Scraper konnte nicht heruntergeladet werden. Beenden...' 'FEHLER: Scraper konnte nicht entpackt werden. Beenden...' 'FEHLER: Suche nach Updates auf GitHub fehlgeschlagen.' 'Update sselph scraper von' 'auf' ' wird durchgeführt, bitte warten...' 'Download sselph scraper' 'Öffne Ordner Browser...' 'Ordner Browser für' 'noch nicht implementiert, entschuldige!' 'Ausgewählter roms Ordner:' 'Vergiss nicht EmulationStation vor dem Scrapen zu beenden!' 'Welche(s) System(e) möchtest du scrapen? Tippe "all" für alle Systeme oder "cd", um den Ordner Browser zu öffnen.' 'Ungültige Eingabe!' 'Möchtest du die bestehende gamelists erweitern? [Y/N]:' 'Scrapen' 'in Arbeit. Bitte warten...' 'Beginn' 'Ende' 'Dauer' 'Bitte wählen Sie den Ordner roms' 'Scrapen ist beendet!') ;;
  118. fr)
  119. dict=('ERREUR : Pas de connexion internet disponible. Quitter...' "n'est pas une plateforme prise en charge." 'ERREUR : Impossible de télécharger le scraper. Quitter...' 'ERREUR : Impossible de décompresser le scraper. Quitter...' 'ERREUR : Impossible de rechercher les mises à jour sur GitHub.' 'La mise à jour de sselph scraper de' 'à' ', veuillez patienter...' 'Le téléchargement sselph scraper' 'Ouverture du Navigateur de Dossier...' 'Navigateur de Dossier pour' 'pas encore mis en oeuvre, désolé !' 'Dossier roms sélectionné :' "N'oubliez pas d'arrêter de EmulationStation avant de scrapez !" 'Quel(s) système(s) souhaitez-vous scrapez ? Tapez « all » pour tous les systèmes ou « cd » pour ouvrir le dossier du navigateur.' 'Entrée incorrecte !' 'Vous souhaitez ajouter les gamelists ? [Y/N] :' 'Scrapez' 'en course. Veuillez patienter...' 'Démarrer' 'Terminer' 'Durée' 'Veuillez choisir le dossier de roms' 'Scrapez est terminé !') ;;
  120. *)
  121. if [ ! "$language" == "en" ]; then echo "Can't get OS's language. English will be used."; fi;
  122. dict=('ERROR: No internet connection available. Exiting...' 'is not a supported platform.' 'ERROR: Unable to download the scraper. Exiting...' "ERROR: Couldn't unzip the scraper. Exiting..." 'ERROR: Unable to check for updates on GitHub.' 'Updating sselph scraper from' 'to' ', please wait...' 'Downloading sselph scraper' 'Opening Folder Browser...' 'Folder Browser for' 'not implemented yet, sorry!' 'Selected roms folder:' "Don't forget to stop EmulationStation before scraping!" "Which system(s) do you want to scrape? Type "all" for all systems or "cd" to open the folder browser." 'Incorrect input!' 'Would you like to append existing gamelists? [Y/N]:' 'Scraping' 'in progress. Please wait...' 'Start' 'Finish' 'Duration' 'Please choose the roms folder.' 'Scraping has finished!') ;;
  123. esac
  124.  
  125. # Check internet connection
  126. uname -m | grep 'arm' >/dev/null && ping -q -c 1 -W 1 8.8.8.8 >/dev/null 2>&1 || nc -z 8.8.8.8 53 >/dev/null 2>&1
  127. if [ ! $? -eq 0 ]; then echo "${dict[0]}"; exit 1; fi
  128.  
  129. # Set default roms directory to launch directory
  130. romsDir=$(pwd)
  131. scriptPath=$(pwd)
  132.  
  133. # Function to download the latest scraper version
  134. download_scraper()
  135. {
  136. # Detect OS architecture
  137. if [ $(uname -m) == "armv7l" ]; then arch=rpi2;
  138. elif [ $(uname -m) == "armv6l" ]; then
  139. arch=rpi
  140. thumbOnly=-thumb_only=true
  141. workersN=-workers=1
  142. elif [ $(uname -m) == "x86_64" ]; then arch=amd64;
  143. else arch=386; fi
  144.  
  145. # Detect OS platform
  146. if [[ $(uname) == 'Linux' ]]; then
  147. platform='linux'
  148. elif [[ $(uname) == 'Darwin' ]]; then
  149. platform='mac'
  150. elif [[ $(uname) == 'FreeBSD' ]]; then
  151. platform='freebsd'
  152. else
  153. echo "$(uname) ${dict[1]}"
  154. exit 1
  155. fi
  156.  
  157. # Build the file name, download url and download the file to the current location
  158. if [[ $arch = "rpi2" || $arch = "rpi" ]]; then
  159. scraperZip=scraper_${arch}.zip
  160. else
  161. scraperZip=scraper_${platform}_${arch}.zip
  162. fi
  163. scraperURL=https://github.com/sselph/scraper/releases/download/${scraperVersion}/${scraperZip}
  164. curl -s -LOk $scraperURL || { echo "${dict[2]}"; exit 1; }
  165.  
  166. # Unzip the scraper, remove unnecessary files and set appropriate permissions
  167. unzip -o -q $scraperZip scraper || { echo "${dict[3]}"; exit 1; }
  168. rm $scraperZip
  169. chmod u+x ./scraper
  170. echo ""
  171. }
  172.  
  173. # scraperBIN
  174. # Query the API to get the latest release tag
  175. scraperVersion=$(curl -s https://api.github.com/repos/sselph/scraper/releases/latest | grep tag_name | cut -d '"' -f 4)
  176.  
  177. # Download or update scraper if needed
  178. if [ -f "./scraper" ]; then
  179. chmod u+x ./scraper
  180. if [ "$scraperVersion" = "$(./scraper -version)" ]; then :;
  181. else
  182. if [ "$scraperVersion" = "" ]; then
  183. echo "${dict[4]}"
  184. echo ""
  185. else
  186. echo "${dict[5]} $(./scraper -version) ${dict[6]} $scraperVersion${dict[7]}"
  187. download_scraper
  188. fi
  189. fi
  190. else
  191. echo "${dict[8]} $scraperVersion${dict[7]}"
  192. download_scraper
  193. fi
  194.  
  195. # Function to open a folder browser depending on the OS
  196. folder_browser()
  197. {
  198. echo ""
  199. echo "${dict[9]}"
  200. case "$OSTYPE" in
  201. darwin*) echo "${dict[10]} macOS ${dict[11]}" ;;
  202. freebsd*) echo "${dict[10]} FreeBSD ${dict[11]}!" ;;
  203. linux*) romsDir=`zenity --file-selection --directory --title="${dict[22]}"` ;;
  204. esac
  205.  
  206. # Check if scraping from network drive and show warning about stopping ES
  207. cd "$romsDir" && echo "${dict[12]} $romsDir"
  208. if [[ $(df "$romsDir" | grep '^//') == "//"* ]]; then echo "${dict[13]}"; fi
  209. echo ""
  210. }
  211.  
  212. # systemSelection
  213. # Select the system to scrape (type "all" to scrape all folders)
  214. while true; do
  215. echo "${dict[14]}"
  216. read system
  217. if [ "$system" = "" ]; then echo "${dict[15]}";
  218. elif [ "$system" = "cd" ]; then folder_browser;
  219. elif [ ! "$system" = "all" ]; then break;
  220. else
  221. system=$(find * -prune -type d | while read d; do echo "$d"; done) && break
  222. fi
  223. done
  224.  
  225. # modeSelection
  226. # Choose to append an existing (y) or create a new gamelist (n)
  227. while true; do
  228. if [ "$refreshXML" = "-refresh=true" ]; then appendMode="" && break; fi
  229. read -p "${dict[16]} " appendXML
  230. if [[ "$appendXML" = "y" || "$appendXML" = "Y" ]]; then appendMode=-append && break; fi
  231. if [[ "$appendXML" = "n" || "$appendXML" = "N" ]]; then appendMode="" && break; fi
  232. echo "${dict[15]}"
  233. done
  234.  
  235. # startTime
  236. # Save start time
  237. startTime=$(date +"%T")
  238. SECONDS=0
  239.  
  240. # ******************** MAIN CODE SECTION
  241.  
  242. for i in $system; do
  243.  
  244. # Check if mame device is selected and set corresponding flags
  245. arcade=""
  246. if [[ "$i" == *"arcade"* ]]; then arcade="-mame $mameImg $mameSrc"; fi
  247. if [[ "$i" == *"fba"* ]]; then arcade="-mame $mameImg $mameSrc"; fi
  248. if [[ "$i" == *"mame"* ]]; then arcade="-mame $mameImg $mameSrc"; fi
  249. if [[ "$i" == *"neogeo"* ]]; then arcade="-mame $mameImg $mameSrc"; fi
  250.  
  251. # If mame device, consoleImg not used
  252. if [ ! "$arcade" = "" ]; then consoleImg=""; fi
  253.  
  254. echo ""
  255.  
  256. # Scraping roms
  257. echo "${dict[17]} $i ${dict[18]}"
  258. echo ""
  259. "$scriptPath/scraper" $appendMode $arcade -rom_dir="$i" $imagePath -image_dir="$i/${imagePath:14}" $imageSuffix -marquee_dir="$i/${marqueePath:16}" $marqueeSuffix -video_dir="$i/${videoPath:14}" $videoSuffix $convertVideo -output_file="$i/gamelist.xml" -missing="$i/_${i}_missing.txt" $addNotFound $consoleImg $consoleSrc $downloadImg $downloadMarquee $downloadVideo $extraExt $imgFormat $marqueeFormat $langSS $maxHeight $maxWidth $noThumb $thumbOnly $refreshXML $regionSS $username $password $useFilename $useNoIntroName $workersN
  260. echo ""
  261. done
  262.  
  263. # ******************** END MAIN CODE SECTION
  264.  
  265. # Save finish time
  266. endTime=$(date +"%T")
  267. DURATION=$SECONDS
  268.  
  269. # Format the results for output
  270. hh=$(($DURATION / 3600)); mm=$((($DURATION / 60) % 60)); ss=$(($DURATION % 60))
  271. if [ $hh -lt 10 ]; then hh=0$hh; fi
  272. if [ $mm -lt 10 ]; then mm=0$mm; fi
  273. if [ $ss -lt 10 ]; then ss=0$ss; fi
  274.  
  275. DURATION=$hh:$mm:$ss
  276.  
  277. echo "${dict[19]} : $startTime"
  278. echo "${dict[20]} : $endTime"
  279. echo " ------------"
  280. echo "${dict[21]} : $DURATION"
  281.  
  282. echo ""
  283. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement