Search the Community
Showing results for tags 'powershell'.
-
First crack at this... using powershell for now since it's my native language. Attempting to create a composite movie rating leveraging the standard set of ratings sources, while adding weighting measures to various community ratings. Definitely some more conditions and logic will be needed for scenarios where subsets of ratings sources are available, but the weighting math should hopefully mitigate a chunk of that. Feedback welcome! $moviename = "Monty Python and the Holy Grail" $rtaudiencerating = 95 $rtaudiencecount = 645107 $rtcriticrating = 98 $rtcriticcount = 82 $tmdbrating = 7.8 $tmdbcount = 5028 $traktrating = 8.3 $traktcount = 11089 $metacriticrating = 91 $imdbrating = 8.2 $imdbcount = 547137 $ratings = @{} $null = $ratings.Add('tomatometerallaudience',@{'MaxValue'=100;'rating'=$rtaudiencerating;'weight'=10;'votecount'=$rtaudiencecount } ) $null = $ratings.Add('tomatometerallcritics',@{'MaxValue'=100;'rating'=$rtcriticrating;'weight'=10;'votecount'=$rtcriticcount} ) $null = $ratings.Add('themoviedb',@{'MaxValue'=10;'rating'=$tmdbrating;'weight'=20;'votecount'=$tmdbcount} ) $null = $ratings.Add('trakt',@{'MaxValue'=10;'rating'=$traktrating;'weight'=20;'votecount'=$traktcount} ) $null = $ratings.Add('metacritic',@{'MaxValue'=100;'rating'=$metacriticrating;'weight'=20;'votecount'=0} ) $null = $ratings.Add('imdb',@{'MaxValue'=10;'rating'=$imdbrating;'weight'=20;'votecount'=$imdbcount} ) $community = @{} $totalcommunityvotes = $ratings['imdb'].votecount + $ratings['trakt'].votecount + $ratings['themoviedb'].votecount + $ratings['tomatometerallaudience'].votecount $imdbpercentvotes = [math]::Round( $ratings['imdb'].votecount / $totalcommunityvotes,3) $traktpercentvotes = [math]::Round( $ratings['trakt'].votecount / $totalcommunityvotes,3) $tmdbpercentvotes = [math]::Round( $ratings['themoviedb'].votecount / $totalcommunityvotes,3) $rtpercentvotes = [math]::Round( $ratings['tomatometerallaudience'].votecount / $totalcommunityvotes,3) $communitysum = $imdbpercentvotes + $traktpercentvotes + $tmdbpercentvotes + $rtpercentvotes if ( $communitysum -gt 1 ) { $rtpercentvotes = $rtpercentvotes - ($communitysum - 1) } elseif ( $communitysum -lt 1 ) { $imdbpercentvotes = $imdbpercentvotes + (1 - $communitysum) } $adjtraktcount = 1; if ( $traktpercentvotes -eq 0 -and $ratings['trakt'].votecount -ne 0 ) { $adjtraktcount = 100 } elseif ( $traktpercentvotes -lt 0.002 ) { $adjtraktcount = 100 } elseif ( $traktpercentvotes -lt 0.004 ) { $adjtraktcount = 80 } elseif ( $traktpercentvotes -lt 0.006 ) { $adjtraktcount = 60 } elseif ( $traktpercentvotes -lt 0.008 ) { $adjtraktcount = 50 } elseif ( $traktpercentvotes -lt 0.010 ) { $adjtraktcount = 30 } elseif ( $traktpercentvotes -lt 0.100 ) { $adjtraktcount = 10 } $adjtmdbcount = 1; if ( $tmdbpercentvotes -eq 0 -and $ratings['themoviedb'].votecount -ne 0 ) { $adjtmdbcount = 100 } elseif ( $tmdbpercentvotes -lt 0.002 ) { $adjtmdbcount = 100 } elseif ( $tmdbpercentvotes -lt 0.004 ) { $adjtmdbcount = 80 } elseif ( $tmdbpercentvotes -lt 0.006 ) { $adjtmdbcount = 60 } elseif ( $tmdbpercentvotes -lt 0.008 ) { $adjtmdbcount = 50 } elseif ( $tmdbpercentvotes -lt 0.010 ) { $adjtmdbcount = 30 } elseif ( $tmdbpercentvotes -lt 0.100 ) { $adjtmdbcount = 10 } $adjtotalcommunityvotes = $ratings['imdb'].votecount + ($ratings['trakt'].votecount*$adjtraktcount) + ($ratings['themoviedb'].votecount*$adjtmdbcount) + $ratings['tomatometerallaudience'].votecount $adjimdbpercentvotes = [math]::Round( $ratings['imdb'].votecount / $adjtotalcommunityvotes,3) $adjtraktpercentvotes = [math]::Round( ($ratings['trakt'].votecount * $adjtraktcount) / $adjtotalcommunityvotes,3) $adjtmdbpercentvotes = [math]::Round( ($ratings['themoviedb'].votecount * $adjtmdbcount) / $adjtotalcommunityvotes,3) $adjrtpercentvotes = [math]::Round( $ratings['tomatometerallaudience'].votecount / $adjtotalcommunityvotes,3) $adjcommunitysum = $adjimdbpercentvotes + $adjtraktpercentvotes + $adjtmdbpercentvotes + $adjrtpercentvotes if ( $adjcommunitysum -gt 1 ) { $adjrtpercentvotes = $adjrtpercentvotes - ($adjcommunitysum - 1) } elseif ( $adjcommunitysum -lt 1 ) { $adjimdbpercentvotes = $adjimdbpercentvotes + (1 - $adjcommunitysum) } $null = $community.Add('imdb',@{'votecount'=$ratings['imdb'].votecount;'percentage'=$imdbpercentvotes;'adjpercent'=$adjimdbpercentvotes } ) $null = $community.Add('trakt',@{'votecount'=$ratings['trakt'].votecount;'percentage'=$traktpercentvotes;'adjpercent'=$adjtraktpercentvotes } ) $null = $community.Add('themoviedb',@{'votecount'=$ratings['themoviedb'].votecount;'percentage'=$tmdbpercentvotes;'adjpercent'=$adjtmdbpercentvotes } ) $null = $community.Add('tomatometerallaudience',@{'votecount'=$ratings['tomatometerallaudience'].votecount;'percentage'=$rtpercentvotes;'adjpercent'=$adjrtpercentvotes } ) $communityweight = 70; if ( !$ratings.ContainsKey('metacritic') ) { $communityweight = $communityweight + 20 } if ( !$ratings.ContainsKey('tomatometerallcritics') ){ $communityweight = $communityweight + 10 } $scoring = @{}; $scoringtable = New-Object System.Collections.ArrayList $ratings.GetEnumerator() | ForEach-Object { $current = $_; $source = $current.Name $sourcetype = $null; if ( $source -in ('tomatometerallcritics','metacritic') ) { $sourcetype = "Critic" } else { $sourcetype = "Community" } $sourcerating = $current.Value.rating $sourcemax = $current.Value.MaxValue if ( $sourcemax -eq 5 ) { $adjustedmax = $sourcemax*20; $adjustedrating = $sourcerating*20 } elseif ( $sourcemax -eq 10 ) { $adjustedmax = $sourcemax*10; $adjustedrating = $sourcerating*10 } else { $adjustedmax = $sourcemax; $adjustedrating = $sourcerating } $sourcevotecount = $current.Value.votecount $communitylookup = $null; $communitylookup = $community[$source] $communityvotepercent = $communitylookup.percentage $communityadjvotepercent = $communitylookup.adjpercent $weighting = 0; if ( $sourcetype -eq "Community" ) { $weighting = $communityadjvotepercent * $communityweight } else { $weighting = $current.Value.weight } $newcompositerating = ($adjustedrating * ($weighting/100 ) ) $null = $scoring.Add($source,@{'SourceType'=$sourcetype;'SourceVoteCount'=$sourcevotecount;'SourceRating'=$sourcerating;'SourceMax'=$sourcemax;'AdjustedRating'=$adjustedrating;'AdjustedMax'=$adjustedmax;'CommunityVotePrc'=$communityvotepercent;'AdjCommunityVotePrc'=$communityadjvotepercent; 'Weight'=$weighting; 'NewRating'= $newcompositerating } ) $null = $scoringtable.Add([pscustomobject]@{'Source' =$source;'SourceType'=$sourcetype;'SourceVoteCount'=$sourcevotecount;'SourceRating'=$sourcerating;'SourceMax'=$sourcemax;'AdjustedRating'=$adjustedrating;'AdjustedMax'=$adjustedmax;'CommunityVotePrc'=$communityvotepercent;'AdjCommunityVotePrc'=$communityadjvotepercent; 'Weight'=$weighting; 'NewRating'= $newcompositerating } ) } #$highestweight = $scoringtable | Sort-Object Weight -Descending | Select-Object -First 1 if ( ($scoringtable.Weight | Measure-Object -Sum).Sum -gt 100.1 ) { Write-Warning "Weighting calculated over 100.1%" } elseif ( ($scoringtable.Weight | Measure-Object -Sum).Sum -lt 99.9 ) { Write-Warning "Weighting calculated under 99.9%" } $NewRating = [math]::Round( (($scoringtable.NewRating | Measure-Object -Sum).Sum/10),1) Write-Output "","" Write-Output "Current movie is $($moviename)." Write-Output "Rotten Tomatoes Critic rating is $($rtcriticrating) out of 100." Write-Output "Rotten Tomatoes Community rating is $($rtaudiencerating) out of 100." Write-Output "Metacritic rating is $($metacriticrating) out of 100." Write-Output "Trakt community rating is $($traktrating) out of 10." Write-Output "IMDB community rating is $($imdbrating) out of 10." Write-Output "The MovieDB rating is $($tmdbrating) out of 10." Write-Output "","New composite rating is $($NewRating) out of 10."
-
I have a niche problem that I created a [not-perfect] solution for. I want to create stub files for my media that I don't have converted from physical media yet. When I do have those movies converted, there are already folders to put them in, but creating the folders and the files by hand is tedious. In response to this dilemma, I created a script (having never really using PowerShell and through about 3 hours of research, trial and error) that would help me make these properly formatted stub files faster. do { #Have user type in the Movie name and year using Emby Format; $proc = Read-Host -Prompt 'Input Movie Name and Year as `"NameOfFilm (YYYY)`". Otherwise, type `"done`"'; #If user types "done", the script will exit the loop and exit the terminal; If($proc -eq 'done') {break}; #Ask user for the movies' media type; $form = Read-Host -Prompt 'Input Movie Format (bluray, dvd, vhs)'; #Sets "$file" variable using user prompted variables "$proc" and "$form"; $file = "$proc\$proc.$form.disc"; #Creates movie folder first, and then creates the file; New-Item $proc -type Directory | Out-Null; New-Item $file -type File -Value $proc | Out-Null; #shows that script has recorded file in the terminal; Write-Host "Recorded $file"; #tests "$proc" variable: continues loop if not equal to "done"; }while ($proc -ne 'done') At the moment, it is a user prompted script, so there is still some tedium, but it isn't as bad as it used to be. I have the script stored in the library location for my Movies, and run it when I want to add a new stub. Once done, you can simply type "done" during the movie name prompt to close the script. With finessing, it could be reworked to use a spreadsheet as the source of the info, and I eventually want to do that (I'll need to learn more PowerShell scripting). Posting this for anyone else who might have this problem and need a solution, or for anyone who wants to contribute. V2: New-Item Output is silenced through Out-Null, to cleanup the terminal during use. stubMaker_v2.ps1 stubMaker_v1.ps1
-
Make API Requests for Library Scan and More in PowerShell - Help
Oracle posted a topic in Developer API
Hi, all. So, I've been just slowing chipping away at this PowerShell script I run every night to sync my server with some other drives and want to make an API request to scan the Emby library and call two other requests as well (Timelord Plugins). Has anyone does this that has some code they'd be willing to share (privately or publicly) as examples? Here is my barebones script, without any of my server's info in there. Thanks! server_sync (1).ps1- 11 replies
-
- powershell
- api
-
(and 4 more)
Tagged with:
-
TVDB constantly changing episodes from specials into a season and vice versa prompted this. I wanted a tool which would align my episode filenames and their indexes to TVDB. #Purpose Renames Files to conform to a prescribed naming scheme. Uses episode name in filename to conform the index in the filename to the matching episode name on TVDB, renaming and moving as necessary. Conservative when recommending a change in index, option for manual operator approval. #Requirements Powershell 7+ Needs access to Measure-StringDistance function add url, api key and server id to config #Constraints Windows Only. Must be run on machine with access to library paths as stored in db. TVDB indexed shows only, will stop processing shows without tvdb index. Only supports aired and dvd display orders, support for others could be changed in code Fixed File Naming Scheme - aligns to Sonarr's treatment of special characters in shows and episodes. eg. trailing . or ?/- in show name, and aggregation of multepisode episodenames with a common root) note - inspect function (extracts names and indexes from path) regex might be tweaked for different naming schemes. Only works with seasons stored as SXX not XX (S is required in filename) - less flexible than embys widest supported naming scheme the filename design is hardcoded to "\Season XX\Showname - SXXEYYEZZ - episodename.ext" , this could be changed in code note: the shows root folder is never touched but the filenames and related season parent folders are prescribed by the filename design Hardcoded to English TVDB, can be changed in code #> changes 0.0.0.4 New - One,More or All shows GUI selection 0.0.0.3 bug fix - file move function broken after subtitle support. 0.0.0.2 new - also rename/move associated subtitle files....limited testing download Assisted Library Clean v0.0.0.4.zip notes Full disclosure, the file matching and confidence engine is sub optimal (if being nice). The script errs on operator assisted matching rather than automation. I had cleaned my library before I got to end, so testing was more academic than practical (less thorough) towards the end. I want to make the recommended matching much stronger/automated but there will always be case when a script can not know, eg for two 'switched' files in season, has the index changed or have the names just switched. So some human intervention might always be required. Example of TVDB Alignment issues / suggestions welcome
-
- 2
-
- powershell
- index change
-
(and 2 more)
Tagged with:
-
ItemsService : /Users/{UserId}/Items with parameter AnyProviderIdEquals
NoEmbyNoFun posted a topic in Developer API
Hello all I would like to get the information about exactly one movie using the API /Users/{UserId}/Items, using Powershell 5.1 on Windows 10. Authentication as a user works fine. Searching directly for the title works fine and returns two items. # Code: $mu = 'http://myembyserver:8096/users/' + $uid + '/items?SearchTerm="Southpaw"&Recursive=true&api_key=' + $apikey Invoke-WebRequest -Uri $mu -Method Get -ContentType "application/json" # Result: StatusCode : 200 StatusDescription : OK Content : {"Items":[{"Name":"Southpaw","ServerId":"721f2a80d300464984d9a0e141800e84","Id":"30969","RunTimeTic ks":74554990000,"IsFolder":false,"Type":"Movie","UserData":{"PlaybackPositionTicks":0,"PlayCount":0 ,"... However, when I use the parameter AnyProviderIdEquals 0 items are returned. # Code: $mu = 'http://myembyserver:8096/users/' + $uid + '/items?AnyProviderIdEquals="imdbid.tt1798684"&Recursive=true&api_key=' + $apikey Invoke-WebRequest -Uri $mu -Method Get -ContentType "application/json" # Result: StatusCode : 200 StatusDescription : OK Content : {"Items":[],"TotalRecordCount":0} RawContent : HTTP/1.1 200 OK Access-Control-Allow-Headers: Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Rang... Also with the tmdbid (tmdbid.307081) the result looks the same. Even if I try to use this parameter in the Swagger UI, I get no result. What am I doing wrong? Many thanks in advance for your advice. Many greetings, Dani -
ItemUpdateService : POST /Items/{ItemId} failes with 204
NoEmbyNoFun posted a topic in Developer API
Hello all I'd like to update an item (a movie) using the code pattern from PenkethBoy ( Setting Folder Sort Sequence via API - Developer API - Emby Community ) The information is fetched using GET /emby/{UserId}/items/{ItemId}. Then exactly two pieces of information are changed: UserData.PlayCount and UserData.Played. Then the information should be updated using POST /emby/items/{ItemId}. # edit item $item.UserData.Played = $true $item.UserData.PlayCount = 1 # update item $url = $es + "/Items/73667?api_key=" + $ac $result = Invoke-Webrequest -uri $url -Method POST -Body ( $item | ConvertTo-Json ) -ContentType "application/json; charset=utf-8" # returns StatusCode : 204 StatusDescription : No Content Content : {} ... Unfortunately this POST does not work as hoped. It returns 204 with no content and the item is not updated. In the Swagger UI the code 204 is not explained. In this forum I didn't find anything about it. Also in the wiki I found no hints regarding updating of items. What am I missing? (The user has the right to manage the emby server). Is there any further documentation? Many thanks in advance for any hint. Dani (Environment: Emby 4.5.4.0, Powershell-Script on Windows 10) -
For anyone like me who started off creating their library of media and and deciding at a later date that maybe they want to move the those movies into their own folders, but don't want to manually create thousands of folders, and then manually move the files, you can automate that process with PowerShell (on WIndows). Open up a PowerShell prompt and navigate to the directory with your movies being stored, in my case on a network share. cd \\unraid\media\movies Make sure this command will create a folder for every file in the directory you just navigated to. WARNING, I was lazy when I made this. This will technically create a folder for any object in the folder that has a period in the name. So, if for whatever reason, you already have folders with a period in the name, it will try to create a folder for it as well. If you already have a folder structure with periods, either don't use this or revise the command. Get-ChildItem | Where-Object {$_.Name -Like "*.*"} | Select BaseName | ForEach-Object {New-Item -Name $_.BaseName -ItemType "Directory"} This next command will actually move every item with a period in the name, into a folder of the same name, minus the file extension. So, if you have multiple copies of a movie, with multiple resolutions, or if you keep your metadata in NFO files, ALL of those files will be moved into the same folder. Get-ChildItem | Where-Object {$_.Name -Like "*.*"} | ForEach-Object {Move-Item $_.Name $_.BaseName}
- 10 replies
-
- 1
-
- powershell
- windows
- (and 9 more)
-
PowerShell script to update server when running as a service
Quicky posted a topic in General/Windows
Hi all, I've been using emby as a service for while now, and having gone through quite a few updates of the server, have always found it a bit long-winded to complete the update steps, thanks to the emby installer automatically starting the desktop app version of the server rather than the service. I've finally got round to writing a quick PowerShell script that automates it a bit more: stop the current service, download the server installer, run the installer, kill the emby app and finally start the service again. I've posted it here in case anyone's got a similar workflow to me for updating emby, and is only marginally lazier than I am: # Installer download path $downloadPath = "$env:USERPROFILE\Downloads" # Stop the emby service $service = 'Media Browser' if ((get-service -DisplayName $service).Status -eq "started") { Stop-Service -DisplayName $service } # Download installer $filename = 'setup.exe' $source = "http://mb3admin.com/downloads/release/server/$filename" $destination = $downloadPath + $fileName Invoke-WebRequest $source -OutFile $destination # Run installer & $destination | Out-Null # Kill the emby app that gets started. $emby = Get-Process -Name MediaBrowser.ServerApplication -ErrorAction SilentlyContinue while (!$emby) { # Check the app is running. Wait until it starts Sleep 5 $emby = Get-Process -Name MediaBrowser.ServerApplication -ErrorAction SilentlyContinue } Stop-Process $emby -Force Sleep 5 # Delete downloaded installer Remove-Item $destination #Restart the emby service Start-Service -DisplayName $service- 18 replies
-
- 6
-
- server
- powershell
-
(and 2 more)
Tagged with: