forum

Videos only songs folder creation powershell script (copy files or symlink)

posted
Total Posts
1
Topic Starter
dung eater
I learned powershell today, don't use it without looking through. Improvements welcome.

osu db might not like when u update songs with the video-osu installation, idk how it deals with symlinks

Purpose: If you just wanna play with videos, create an osu install that uses that folder.

old
#README
#Use at your own risk, idk what i'm doing. I learned powershell today.
#Powershell 7.3
#
#Copies all songs with videos to another directory.
#Or makes symlinks to only the video folders at destination folder.
#
#Usage:
#Change $SongsFolder and $VideosOnlyDestination
#Create the destination folder before proceeding
#Comment out either symlink creation or folder copying

Clear-Host
$SongsFolder = "D:\osu\songs\"
$VideosOnlyDestination = "D:\osuvideosymlinks or files\"
$FileType = ".mp4", ".avi", ".flv"

Get-ChildItem -Path "$SongsFolder"  -Force | Where-Object { $_.PSIsContainer } |
Foreach-Object {
	param(
	$Subfolder = $_.FullName,
	$Foldername = $_.BaseName,
	$FiletypePresent = $false )

	#Check if there's a video file
	Foreach ($type in $FileType) {
		$files = Get-ChildItem -Path $Subfolder -Filter *$type -Force | Where-Object { !$_.PSIsContainer }
		Foreach ($file in $files) {
			$FiletypePresent = $true
			Break
		}
		if($FiletypePresent) { Break }
	}

	#Console output for no video skipped directories
	#if(!$FiletypePresent) {
	#	Write-Output "No match" $Foldername
	#}
	
	$Failsafe = $false #this stops you from copying AND creating symlinks
	#Copy files
	#if($FiletypePresent) {
	#	New-Item -Path "$VideosOnlyDestination\$Foldername" -ItemType Directory -Force
	#	Copy-Item -Path "$Subfolder" -Destination "$VideosOnlyDestination" -Force -Recurse
	#	$Failsafe = $true
	#}

	#Symlink folders inside destination path
	if($FiletypePresent -and !$Failsafe) {
		New-Item -Path $VideosOnlyDestination\$Foldername -ItemType SymbolicLink -Value $Subfolder
	}
}

Read-Host -Prompt "Press Enter to exit"


Update
# README
# Use at your own risk, idk what i'm doing. I learned powershell just for this.
# Powershell 7.3
# Creates symlinks to folders that contain video files in another directory.
# Usage:
# Change $SongsFolder and $VideosOnlyDestination
# Create the destination folder before proceeding

Clear-Host

$SongsFolder = "Z:\osu\songs\"
$VideosOnlyDestination = "Z:\osuvideosymlinks\"
$FileType = ".mp4", ".avi", ".flv", ".wmv", ".m4v"

$Processed = 0
$Added = 0
$Skipped = 0
$Folderamount = (get-childitem -Path "$SongsFolder" | where-object { $_.PSIsContainer }).Count

Get-ChildItem -Path "$SongsFolder"  -Force | Where-Object { $_.PSIsContainer } |
Foreach-Object {
    param(
        $Subfolder = $_.FullName,
        $Foldername = $_.BaseName,
        $FiletypePresent = $false )
    #Check if symlink already exists, necessary to not get error spam and useless checking files on a second run
    if (Test-Path -Path $VideosOnlyDestination\$Foldername) { $script:Skipped++ }
    else {
        # Check if there's a video file in a beatmap folder
        Foreach ($type in $FileType) {
            $files = Get-ChildItem -Path $Subfolder -Filter *$type -Force | Where-Object { !$_.PSIsContainer }
            Foreach ($file in $files) {
                $FiletypePresent = $true
                Break }
            if($FiletypePresent) {
                Break
            }
        }
        # Console output for no video skipped directories
        # if(!$FiletypePresent) {
        #     Write-Output "No match" $Foldername
        # }

        # Symlink folders inside destination path
        if($FiletypePresent) {
            New-Item -Path $VideosOnlyDestination\$Foldername -ItemType SymbolicLink -Value $Subfolder
            $script:Added++
        }
    }
    $script:Processed++
    Write-Host "$Processed of $Folderamount folders processed. $Added video mapsets added. $Skipped video mapsets were added previously and were skipped." 
}
Read-Host -Prompt "Press Enter to exit"

Update 3

Now supports filenames with [ ]

Now runs faster if you run it again

Now fills another cursed folder with symlinks to maps with no video (used for skipping on subsequent runs)

Documentation a bit bad, try to understand what it does before running.

# README
# Use at your own risk, idk what i'm doing. I learned powershell just for this.
# Powershell 7.3
#
# Creates symlinks to folders that contain video files in another directory.
#
# Usage:
# Change $SongsFolder and $VideosOnlyDestination
# Create the destination folder before proceeding
# Copy your osu folder and remove the .db files, songs folder. set songs folder to the symlink folder

Clear-Host

# CONFIG START #
$SongsFolder = "Z:\osu\songs\"
$VideosOnlyDestination = "Z:\osuvideosymlinks\"
$NoVideosOnlyDestination = "Z:\osuNOvideosymlinks\"
$FileType = ".mp4", ".avi", ".flv", ".wmv", ".m4v"
# CONFIG END #

$Processed = 0
$Added = 0
$AddedNo = 0
$Skipped = 0
$Folderamount = (get-childitem -Path "$SongsFolder" | where-object { $_.PSIsContainer }).Count

Get-ChildItem -Path "$SongsFolder"  -Force | Where-Object { $_.PSIsContainer } |
Foreach-Object {
    param(
        $Subfolder = $_.FullName,
        $Foldername = $_.BaseName,
        $FiletypePresent = $false )
    
    #Check if symlink already exists, necessary to not get error spam and useless checking files on a second run
    if ((Test-Path -literalPath $VideosOnlyDestination\$Foldername) -Or (Test-Path -literalPath $NoVideosOnlyDestination\$Foldername)) { $script:Skipped++ }
    else {
        # Check if there's a video file in a beatmap folder
        Foreach ($type in $FileType) {
            $files = Get-ChildItem -literalPath $Subfolder -Filter *$type -Force | Where-Object { !$_.PSIsContainer }
            Foreach ($file in $files) {
                $FiletypePresent = $true
                Break }
            if($FiletypePresent) {
                Break
            }
        }

        # No video skipped directories
        if(!$FiletypePresent) {
            New-Item -Path $NoVideosOnlyDestination\$Foldername -ItemType SymbolicLink -Value $Subfolder.replace('[', '``[').replace(']', '``]')
            $script:AddedNo++
        }

        # Symlink folders inside destination path
        if($FiletypePresent) {
            New-Item -Path $VideosOnlyDestination\$Foldername -ItemType SymbolicLink -Value $Subfolder.replace('[', '``[').replace(']', '``]')
            $script:Added++
        }
    }
    $script:Processed++
    #"Write-Host "$Processed of $Folderamount done. $Added videos found. $AddedNo folders without video found. $Skipped previously processed and skipped." 
    #[Console]::WriteLine("$Processed of $Folderamount done. $Added videos found. $AddedNo folders without video found. $Skipped previously processed and skipped.")
}

Read-Host -Prompt "Press Enter to exit"
Please sign in to reply.

New reply