• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Development Feature Requests Create collections within seconds based on lists from mdblist

     
    • 0 Vote(s) - 0 Average

    Create collections within seconds based on lists from mdblist

    python script
    soy_titooo
    Offline

    Junior Member

    Posts: 12
    Threads: 4
    Joined: 2023 Jul
    Reputation: 0
    #1
    2023-10-04, 12:09 PM (This post was last modified: 2023-10-04, 12:15 PM by soy_titooo. Edited 4 times in total.)
    The following script I did with chatgpt works Emby. It does not work with Jellyfin , but I'm sure it'd be very easy to port it to jellyfin. I just don't know how to....

    Here is a python script that would create a collection with the top movies of the week (again, it works in Emby but not jellyfin)

    Code:
    import requests
    import json
    import subprocess
    from urllib.parse import quote

    # URL of the JSON file containing movie data
    json_url = "https://mdblist.com/lists/garycrawfordgc/top-movies-of-the-week/json/"

    # Fetch the JSON data from the URL
    response = requests.get(json_url)

    if response.status_code == 200:
        # Parse the JSON data
        movie_data = json.loads(response.text)

        # Extract IMDb IDs from the JSON data and add the "imdb." prefix
        imdb_ids = ["imdb." + movie["imdb_id"] for movie in movie_data]

        # Construct the IMDb IDs string for the Emby API request
        imdb_ids_str = "%2C".join(imdb_ids)

        # Define your Emby API key
        emby_api_key = 'YOUR-EMBY-API-KEY'

        # Build the Emby API URL with the IMDb IDs
        emby_api_url = f"https://YOUR-EMBY-DOMAIN-OR-IPADDRESS/emby/Items?Recursive=true&AnyProviderIdEquals={imdb_ids_str}&api_key={emby_api_key}"

        # Print the Emby API URL
        print("Emby API URL:", emby_api_url)

        # Execute the curl command to get movie data from Emby
        subprocess.run(["curl", emby_api_url])

        ### SECOND PART
        # Extract the movie IDs from the Emby API URL JSON dataA
        emby_response = requests.get(emby_api_url)
        emby_data = emby_response.json()

        movie_ids = [item['Id'] for item in emby_data['Items']]

        # Create a comma-separated string of movie IDs
        movie_ids_str = '%2C'.join(map(str, movie_ids))

        # Define the collection name (without %20)
        collection_name = 'Top Movies of the week'

        # Encode the collection name with %20
        encoded_collection_name = quote(collection_name)

        # Construct the curl command to create the collection
        curl_command = f'curl -X POST "https://YOUR-EMBY-DOMAIN-OR-IPADDRESS/emby/Collections?Name={encoded_collection_name}&Ids={movie_ids_str}&api_key={emby_api_key}" -H "accept: application/json"'

        # Print the curl command
        print("Curl command:", curl_command)

        # Execute the curl command
        subprocess.run(curl_command, shell=True)

    else:
        print("Failed to fetch JSON data")

    Additional comments:
    1-You might want to replace json_url by the mdblist url of a different list. Then you'll also want to modify the collection_name line
    2-Replace YOUR-EMBY-API-KEY by your actual api key that you can find in your emby settings
    3- Replace YOUR-EMBY-DOMAIN-OR-IPADDRESS with your server details (there are two lines where you need to do that)

    I got this idea from this thread on emby forums https://emby.media/community/index.php?/...rt/page/2/

    There are some guys that apparently managed to do more than I did, and probably even better but they don't seem interested on sharing their code.

    I'm hoping this community is more open minded and someone can take port it to Jellyfin and take it to the next level (eg: add collections to a main screen row like Top Picks plugin does with its own collection)
    mcarlton00
    Offline

    Kodi Addon Maintainer

    Posts: 145
    Threads: 1
    Joined: 2023 Sep
    Reputation: 9
    Country:United States
    #2
    2023-10-05, 12:56 PM
    > emby_api_url = f"https://YOUR-EMBY-DOMAIN-OR-IPADDRESS/emby/Items?Recursive=true&AnyProviderIdEquals={imdb_ids_str}&api_key={emby_api_key}"

    At a glance, I see two reasons this probably isn't working.

    1. I'm pretty confident that /emby/whatever api endpoints don't work in Jellyfin anymore.  It's just /Items or /Collections now.
    2. Jellyfin doesn't have a AnyProviderEquals URL parameter option.  That's something Emby added after the fork.  So I believe you'd need to query all items and filter them locally, but there may be another way I'm not aware of off the top of my head.

    There's some general code structure cleanup that could happen too, if you're interested.

    * I'm not sure why you're utilizing both curl and requests.  Requests could handle all of it.
    * Manually building URL strings.  A bit cleaner method is to build out your parameters in a dictionary and then urlencode() it into a string.

    Code:
    from urllib.parse import urlencode
    parameters = {
        "Name" = collection_name,
        "Ids" = ','.join(movie_ids),
        "api_key" = emby_api_key
    }
    parameter_string = urlencode(parameters)
    url = f"https://{your_domain_or_ipaddress}/Collections?{parameter_string}"

    It's just a little easier to read and understand when you revisit this later.
    soy_titooo
    Offline

    Junior Member

    Posts: 12
    Threads: 4
    Joined: 2023 Jul
    Reputation: 0
    #3
    2023-10-10, 09:11 AM (This post was last modified: 2023-10-10, 09:30 AM by soy_titooo. Edited 1 time in total.)
    Thanks. I tried but I failed (due to lack of skills).

    Let's hope someone with better knowledge can do something so we can create our own collections based off mdblist.com lists and then even better if we find the option to add a particular collection to a new row in the homescreen.

    Some guys at emby forums already managed to do that but so far some of them are very protective of their code and others just don't want to share anything because they plan to charge for it once they get it working.

    My hopes are on jellyfin. I hope that after latest Plex decisions we get more people contributing to make Jellyfin better.
    Yankees4life
    Offline

    Junior Member

    Posts: 21
    Threads: 1
    Joined: 2023 Jun
    Reputation: 1
    #4
    2023-10-13, 02:10 AM (This post was last modified: 2023-10-13, 02:10 AM by Yankees4life.)
    As I expect with those people over at the emby forums 🤣😂
    If they have the power to charge a nickle a second we breathe air, they would. 🤣😂

    Obviously, if you want something done quick, you gotta build it yourself and the api is there to take a look.

    I've chipped in plenty for this community (via Jellyfin Auto Collections, Smart Playlists and even my own collection of JF scripts on my git). You need patience and a bit of practice. ChatGPT won't hold your hand. They'll give you something to work off of but the rest is up to you...
    1
    soy_titooo
    Offline

    Junior Member

    Posts: 12
    Threads: 4
    Joined: 2023 Jul
    Reputation: 0
    #5
    2023-10-13, 11:43 PM (This post was last modified: 2023-10-14, 10:59 AM by soy_titooo. Edited 3 times in total.)
    @Yankees4life

    Thanks for your reply. I googled your username + GitHub to see the scripts you did and I managed to copy it and modifiy  so I could have one script to create a collecion of Top 10 Trending Movies in Trakt (using mdblist) . Here is the Code:

    Code:
    # Set variables
    $jellyfinServerURL = "http://myjellyfin.tld/jellyfin"
    $jellyfinAPIKey = "my-jellyfin-spi-key"
    $libraryId = ""  # Replace with your library ID
    $collectionName = "- Trending Movies (Trakt)"
    $minRating = 2
    $minYear = 2022

    # Fetch the JSON from the URL
    $jsonURL = "https://mdblist.com/lists/titooo7/top-10-trending-trakt/json"
    $json = Invoke-RestMethod -Uri $jsonURL

    # Extract movie titles from the JSON
    $movieTitles = $json | ForEach-Object { $_.title }

    # Loop through libraries and create collections
    # Assume you have one library with ID $libraryId
    # You can modify the loop for multiple libraries if needed
    Write-Host "Creating collection: $($collectionName)"

    # Get list of items in library
    $itemsURL = "$jellyfinServerURL/items?ParentId=$libraryId&IncludeItemTypes=Movie&api_key=$jellyfinAPIKey&Recursive=true"
    $itemsResponse = Invoke-RestMethod -Uri $itemsURL -Method Get
    $items = $itemsResponse.Items | Where-Object { $movieTitles -contains $_.Name -and $_.PremiereDate.Year -ge $minYear -and $_.CommunityRating -ge $minRating }

    # Create collection
    if ($items.Count -gt 0) {
        $itemIDs = $items.Id -join ","
        $collectionURL = "$jellyfinServerURL/Collections?Name=$collectionName&Ids=$itemIDs&api_key=$jellyfinAPIKey"
        $collectionResponse = Invoke-RestMethod -Uri $collectionURL -Method Post
        Write-Host "Collection created with $($items.Count) movies."
    } else {
        Write-Host "No matching movies found in the library."
    }

    Again, it was chatgpt who helped me to modify your script to fit my purpose. I'm sure it could be better but..It works! Maybe one day I'll learn to do It myself, lol.

    Only annoying part is duplicated movies on Collections due to the different versiond of the movie being presente several times in the same library, but that seems an issue that Jellyfin Autocollection plugin can't fix yet.
    1
    soy_titooo
    Offline

    Junior Member

    Posts: 12
    Threads: 4
    Joined: 2023 Jul
    Reputation: 0
    #6
    2023-10-14, 11:00 AM
    (2023-10-13, 11:43 PM)soy_titooo Wrote: @Yankees4life

    Thanks for your reply. I googled your username + GitHub to see the scripts you did and I managed to copy it and modifiy  so I could have one script to create a collecion of Top 10 Trending Movies in Trakt (using mdblist) . Here is the ps1 script:

    Code:
    # Set variables
    $jellyfinServerURL = "http://myjellyfin.tld/jellyfin"
    $jellyfinAPIKey = "my-jellyfin-spi-key"
    $libraryId = ""  # Replace with your library ID
    $collectionName = "- Trending Movies (Trakt)"
    $minRating = 2
    $minYear = 2022

    # Fetch the JSON from the URL
    $jsonURL = "https://mdblist.com/lists/titooo7/top-10-trending-trakt/json"
    $json = Invoke-RestMethod -Uri $jsonURL

    # Extract movie titles from the JSON
    $movieTitles = $json | ForEach-Object { $_.title }

    # Loop through libraries and create collections
    # Assume you have one library with ID $libraryId
    # You can modify the loop for multiple libraries if needed
    Write-Host "Creating collection: $($collectionName)"

    # Get list of items in library
    $itemsURL = "$jellyfinServerURL/items?ParentId=$libraryId&IncludeItemTypes=Movie&api_key=$jellyfinAPIKey&Recursive=true"
    $itemsResponse = Invoke-RestMethod -Uri $itemsURL -Method Get
    $items = $itemsResponse.Items | Where-Object { $movieTitles -contains $_.Name -and $_.PremiereDate.Year -ge $minYear -and $_.CommunityRating -ge $minRating }

    # Create collection
    if ($items.Count -gt 0) {
        $itemIDs = $items.Id -join ","
        $collectionURL = "$jellyfinServerURL/Collections?Name=$collectionName&Ids=$itemIDs&api_key=$jellyfinAPIKey"
        $collectionResponse = Invoke-RestMethod -Uri $collectionURL -Method Post
        Write-Host "Collection created with $($items.Count) movies."
    } else {
        Write-Host "No matching movies found in the library."
    }

    Again, it was chatgpt who helped me to modify your script to fit my purpose. I'm sure it could be better but..It works! Maybe one day I'll learn to do It myself, lol.

    Only annoying part is duplicated movies on Collections due to the different versiond of the movie being presente several times in the same library, but that seems an issue that Jellyfin Autocollection plugin can't fix yet.
    Yankees4life
    Offline

    Junior Member

    Posts: 21
    Threads: 1
    Joined: 2023 Jun
    Reputation: 1
    #7
    2023-10-14, 06:19 PM
    Nice to see that you're able to pierce something together. I'm actually working on a script that was use trakt directly to create collections but it's not done yet. 🤣
    soy_titooo
    Offline

    Junior Member

    Posts: 12
    Threads: 4
    Joined: 2023 Jul
    Reputation: 0
    #8
    2023-10-15, 07:13 AM
    (2023-10-14, 06:19 PM)Yankees4life Wrote: Nice to see that you're able to pierce something together. I'm actually working on a script that was use trakt directly to create collections but it's not done yet. 🤣

    But why don't you use mdblist for that?
    With  mdblist you can create lists in Trakt and then you can use the script I modified based on yours  🙂

    Here is the link by the way:
    https://github.com/titooo7/Jellyfin-Tool...s-week.ps1


    Now what I would like to do is to find the way to avoid duplicated posters in that collection, and especially find a way to add a new row to the homescreen with th items of the collection.
    Yankees4life
    Offline

    Junior Member

    Posts: 21
    Threads: 1
    Joined: 2023 Jun
    Reputation: 1
    #9
    2023-10-18, 07:33 PM
    (2023-10-15, 07:13 AM)soy_titooo Wrote:
    (2023-10-14, 06:19 PM)Yankees4life Wrote: Nice to see that you're able to pierce something together. I'm actually working on a script that was use trakt directly to create collections but it's not done yet. 🤣

    But why don't you use mdblist for that?
    With  mdblist you can create lists in Trakt and then you can use the script I modified based on yours  🙂

    Here is the link by the way:
    https://github.com/titooo7/Jellyfin-Tool...s-week.ps1


    Now what I would like to do is to find the way to avoid duplicated posters in that collection, and especially find a way to add a new row to the homescreen with th items of the collection.

    Sounds like a plan to me. Trying to reverse engineer mdblist to use trakt lists (most anticipated , trending, popular) and anilist/mal might be the way to do it. I'll just borrow the PMM posters 🤣😂 to make it look nice.
    « Next Oldest | Next Newest »

    Users browsing this thread: 3 Guest(s)


    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode