PlayniteExtensionsCollection icon indicating copy to clipboard operation
PlayniteExtensionsCollection copied to clipboard

[Extra Metadata Loader] Add menu item to download video(s) from games created by itch.io library

Open joyrider3774 opened this issue 3 years ago • 1 comments

Extension name

Extra Metadata Loader

Feature Description

should work for most store page on itch.io the approach with:

  1. get itch.io game page url from links section of the game (itch.io library normally adds these)
  2. download the html from that page
  3. get position of <div class="right_col column"> in html (+ get child <div class="video_embed">) (added by CanRanBan not sure)
  4. get youtube video ID with regex match
(?:youtu(?:\.be|be\.com)\/embed\/)((?:[a-zA-Z\d]|-|_){11})
  1. make sure found match position in html is greater than position found in point 3
  2. use the youtube id to pass it your youtube download function to download the video from youtube for game

notes from CanRanBan But I think you should add to only look inside the <div class="video_embed">. If my looking at 3 different store pages is sufficient enough you always have one

and one <div class="screenshot_list"> as child elements. sometimes the video one is empty.

I don't do the child elements stuff on my hacked together extension because it would exclude videos in the main page

example Powershell code of what i do in my hacked to together script

function Get-ItchIoYoutubeLink
{
    param(
        $scriptGameMenuItemActionArgs
    )
	Set-MandatorySettings
    $gameDatabase = $PlayniteApi.MainView.SelectedGames
    $videoSetCount = 0

    foreach ($game in $gameDatabase)
    {
		if($game.Links)
		{
			foreach ($link in $game.Links)
			{
				
				if ($link.Url -like "*itch.io*")
				{
					$matches = $null
					try
					{
						$webContent = Get-DownloadString $link.Url
					}
					catch
					{
						$webContent = ""
					}
					$webContentLower = $webContent.ToLower()
					$index = $webContentLower.LastIndexOf('class="right_col column"')					
					if ($index -gt 0)
					{
						$webContent -match 'youtu(.*?\/embed\/)(.*?)"' | Out-Null
						if ($matches)
						{
							$index2 = $webContentLower.LastIndexOf($matches[0].ToLower())
							if($index2 -gt $index)
							{
								Set-YouTubeVideoManual $matches[2] $false $game
								break
							}
						}
					}
				}
			}
		}
	}
	
	$PlayniteApi.Dialogs.ShowMessage("Finished", "Extra Metadata tools")
}

In a lot of cases if the page has a video it will usually download the trailer from youtube

Screenshots

image

joyrider3774 avatar Mar 09 '22 02:03 joyrider3774

here is another variation of the script (i'm now) using

it tries to take the 1st youtube video it finds after the text class="right_col column" using this way it had found some extra video's

function Get-ItchIoYoutubeLink
{
    param(
        $scriptGameMenuItemActionArgs
    )
	Set-MandatorySettings
    $gameDatabase = $PlayniteApi.MainView.SelectedGames
    $videoSetCount = 0

    foreach ($game in $gameDatabase)
    {
		if($game.Links)
		{
			foreach ($link in $game.Links)
			{
				
				if ($link.Url -like "*itch.io*")
				{
					$matches = $null
					try
					{
						$webContent = Get-DownloadString $link.Url
					}
					catch
					{
						$webContent = ""
					}
					$webContentLower = $webContent.ToLower()
					$index = $webContentLower.LastIndexOf('class="right_col column"')					
					if ($index -gt 0)
					{
						$m = Select-String -InputObject $webContent -Pattern '(?:youtu(?:\.be|be\.com)\/embed\/)((?:[a-zA-Z\d]|-|_){11})' -AllMatches 
						foreach ($match in $m.Matches)
						{
							if($match.Index -gt $index)
							{
								Set-YouTubeVideoManual $Match.Groups[1] $false $game
								break
							}
						}
					}
				}
			}
		}
	}
	
	$PlayniteApi.Dialogs.ShowMessage("Finished", "Extra Metadata tools")
}

joyrider3774 avatar Mar 12 '22 04:03 joyrider3774