$downloadDirectory = 'D:\Downloads\'
Set-Location $downloadDirectory


switch -Regex ($args[0]){
    <#'music.'{
        $YTcommand = "youtube-dl --no-playlist --newline -x --audio-format best --add-metadata --audio-quality 0 $args[0]""
    }#>
    'youtu'{$YTcommand = "youtube-dl -o ""$downloadDirectory\%(title)s.%(ext)s"" $args[0]"}
    'twitter'{$YTcommand = "youtube-dl -o ""$downloadDirectory\%(id)s.%(ext)s"" $args[0]"}
    'chaturbate'{
        for ($i=1;$i -le 40;$i++){
            $waitTimer = 30
            $chaturbate = "youtube-dl -o ""$downloadDirectory\%(title)s.%(ext)s"" $args[0]"
            Invoke-Expression $chaturbate
            $timeMultiply = $waitTimer * $i
            $ts = [timespan]::FromSeconds($timeMultiply)
            Start-Sleep -Seconds $waitTimer
            Write-Host 'Waited for' $ts
        }
    }
    'series'{
        $channels = @(
            'https://www.youtube.com/user/Worthikids'
            'https://www.youtube.com/user/CrazyBorisProduction'
            'https://www.youtube.com/c/JelloApocalypse/videos'
            'https://www.youtube.com/c/BRFootball/videos'
        )
        $regexs = @(
            '(?i)^bigtop burger'
            '(?i)^dungeon dynamite'
            '(?i)^epithet erased'
            '(?i)^the champions(?! League)'
        )
        $locations = @(
            'D:\OneDrive\Videos\Series\Bigtop Burger'
            'D:\OneDrive\Videos\Series\Dungeon Dynamite'
            'D:\OneDrive\Videos\Series\Epithet Erased'
            'D:\OneDrive\Videos\Series\The Champions'
        )

        for ($i = 0; $i -lt $channels.Count; $i++){
            $channel = $channels[$i]
            $location = $locations[$i]
            $regex = $regexs[$i]

            $channelSeries = "youtube-dl --match-title ""$regex"" -i --ignore-config --add-metadata --embed-subs --all-subs --convert-subs srt --merge-output-format mkv -o ""$location\%(title)s.%(ext)s"" ""$channel"""
            Invoke-Expression $channelSeries
        }

        $Channels = @(
            'https://www.youtube.com/channel/UC1DTYW241WD64ah5BFWn4JA/videos'
            'https://www.youtube.com/c/ContraPoints/videos'
        )
        $locations = @(
            "D:\OneDrive\Videos\Series\Sam O'Nella"
            "D:\OneDrive\Videos\Series\ContraPoints"
        )
        #Channels Hd
        for ($i = 0; $i -lt $channels.Count; $i++){
            $channel = $channels[$i]
            $location = $locations[$i]
            $regex = $regexs[$i]

            $channelSeries = "youtube-dl -i --ignore-config --add-metadata --embed-subs --all-subs --convert-subs srt --merge-output-format mkv -o ""$location\%(title)s.%(ext)s"" ""$channel"""
            Invoke-Expression $channelSeries
        }

        #Rhys
        $playlists = @(
            'https://youtu.be/BhMIUJ-OeaQ?list=PLzxc0OSXCoWxzE6IvnzCcOqlI0puY0513'
            'https://youtu.be/ilYzQJ-geCc?list=PLzxc0OSXCoWxhI9_F5ZHgsC2MZ9uyZK8V'
            'https://youtu.be/b5S7WPRbVDk?list=PLzxc0OSXCoWwItlpwhY7TOR8RWu8wyQHC'
        )
        foreach ($playlist in $playlists){
            $location = 'D:\OneDrive\Videos\Series\Rhys'
            $urlCommand = "youtube-dl -i --ignore-config --add-metadata --recode-video mp4 -o ""$location\%(playlist)s\%(title)s.%(ext)s"" ""$playlist"""
            Invoke-Expression $urlCommand
        }
        
        #CGkid
        $channel = 'https://www.youtube.com/c/CgKid/videos'
        $location = 'D:\OneDrive\Videos\Series\CGKid'
        $urlCommand = "youtube-dl -f ""best[height<480]"" -i --ignore-config --add-metadata --recode-video mp4 -o ""$location\%(title)s.%(ext)s"" ""$channel"""
        Invoke-Expression $urlCommand
    }
    Default {
        $linkCom = "youtube-dl -o ""$downloadDirectory\%(title)s.%(ext)s"" $args[0]"
        Invoke-Expression $linkCom
    }
}

if ($YTcommand){
    Invoke-Expression $YTcommand
}
