How to create schema for series episodes with multiple URL fields in Sanity?

49 replies
Last updated: Dec 6, 2022
Hello everyone, I am making a project in which have movies and series, i have achieved movie part which have link/url of the movie but i want to make schema for episode in series, in which i need to have like + button where i can add url fields and add multiple links to one episode. For example, One season have multiple episode and for the multiple episode there are multiple links to each episode of the season.
user Y
AI Update

You'll want to use an array field with object members for your episode schema! This is perfect for your use case where each episode needs multiple streaming links.

Here's how to structure your series schema:

import {defineType, defineField, defineArrayMember} from 'sanity'

export default defineType({
  name: 'series',
  title: 'Series',
  type: 'document',
  fields: [
    defineField({
      name: 'title',
      title: 'Series Title',
      type: 'string',
    }),
    defineField({
      name: 'seasons',
      title: 'Seasons',
      type: 'array',
      of: [
        defineArrayMember({
          type: 'object',
          name: 'season',
          title: 'Season',
          fields: [
            {
              name: 'seasonNumber',
              title: 'Season Number',
              type: 'number',
            },
            {
              name: 'episodes',
              title: 'Episodes',
              type: 'array',
              of: [
                defineArrayMember({
                  type: 'object',
                  name: 'episode',
                  title: 'Episode',
                  fields: [
                    {
                      name: 'episodeNumber',
                      title: 'Episode Number',
                      type: 'number',
                    },
                    {
                      name: 'title',
                      title: 'Episode Title',
                      type: 'string',
                    },
                    {
                      name: 'streamingLinks',
                      title: 'Streaming Links',
                      type: 'array',
                      of: [
                        defineArrayMember({
                          type: 'object',
                          name: 'link',
                          fields: [
                            {
                              name: 'url',
                              title: 'URL',
                              type: 'url',
                            },
                            {
                              name: 'platform',
                              title: 'Platform Name',
                              type: 'string',
                              description: 'e.g., Netflix, Prime Video, etc.'
                            },
                            {
                              name: 'quality',
                              title: 'Quality',
                              type: 'string',
                              options: {
                                list: ['720p', '1080p', '4K']
                              }
                            }
                          ],
                          preview: {
                            select: {
                              title: 'platform',
                              subtitle: 'url'
                            }
                          }
                        })
                      ]
                    }
                  ],
                  preview: {
                    select: {
                      title: 'title',
                      episode: 'episodeNumber'
                    },
                    prepare({title, episode}) {
                      return {
                        title: `Episode ${episode}: ${title}`
                      }
                    }
                  }
                })
              ]
            }
          ],
          preview: {
            select: {
              season: 'seasonNumber'
            },
            prepare({season}) {
              return {
                title: `Season ${season}`
              }
            }
          }
        })
      ]
    })
  ]
})

This schema gives you:

  1. Nested arrays - Series → Seasons → Episodes → Streaming Links
  2. The + button you want - Array fields automatically provide the "Add item" button for adding multiple URLs
  3. Custom previews - So you can see episode titles and platform names at a glance without opening each item
  4. Flexible link structure - Each episode can have as many streaming links as needed

In the Studio, users will:

  1. Click the + button next to "Streaming Links"
  2. Add a URL, platform name, and quality for each link
  3. Keep clicking + to add more links to that episode

You can also add validation if needed (like requiring at least one streaming link per episode):

{
  name: 'streamingLinks',
  title: 'Streaming Links',
  type: 'array',
  validation: Rule => Rule.required().min(1).error('At least one streaming link is required'),
  of: [...]
}

The array field documentation has more details on customization options if you want to enhance the UI further!

Show original thread
49 replies
Maybe not tag people
He said he's here to help, so i guess he can help maybe
did you create the movie startup?
Ya! I am trying to make a startup and maybe sell it later
I mean, did you use the Sanity starter with movies and such?
Nope
Started as a blog and then later converted into Movie Streaming service
Understand, what you described seems pretty straight forward
It is that pretty straight forward
Yes, maybe give it a try and send a message if you are struggeling?
What should i give a try to?
Create
Episode
schema
Ohh yes ure
sure*
Can you help if possible?
Ill help with references and such
yes
Just dont have the time to create it for you!
Ya, can you just give me a hint or something with field type using
Yes, just let me know when you need a hint 😉
RN
Hint of what?
I have researched it for 3 days still no hint so i reached to slack
Can you be more specific of what you need help with exactly?
Look, Could you understand my main question?
Yes i understand it.
So, this what looks like in movie section
So should be any + button where i just click and link of next episode or something like that.
Okey so you need an array with the reference of episodes
So, In frontend I will create one post and from that i will just change the url of the episode
 {
        title: 'Episodes',
        name: 'episodes',
        type: 'array',
        of: [
          {
            type: 'reference',
            to: [
              {type: 'episodes'},
             
            ]
          }
        ]
      }
Not specificly an array
Look, Sanity gives only 10K docs space so it would be easily full
So, I need to paste URL of all episode of a series in one Document
Could you understand?
So like in this photo there is 2 fields, i.e, URL1 and URL2 but i want to make something like dynamic thing that adds fields as i click on the button
why not an array of urls then?
Can you pls expand?
{
  title: 'Url',
  name: 'url',
  type: 'array',
  of: [{type: 'string'}]
}

ok
So this will help me with?
You can create urls by pressing button yes
I really appreciate thank you very much, I could not thank you enough
I was looking for this like for 3-4 days
Any time!
Actually can i add you as teammates in slack?
Yes, just dont expect me to stop everything to answer you
Yes, I do mostly on my own as I said but sometimes just goes psstt..

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?