تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Inspect RSS XML Data0:00

The first thing I want to do is just make sure I'm getting the right information. If I was to pull up the XML from the Lyricast snippet, for example, we should be able to grab most of the information that we need from this XML file. For example, we have the title of the podcast, so that way we can add that into the Podcast model. We have the artwork, so this is the JPEG of the file that we need. That's great. We have image URL, and that's exactly what we need for the artwork. We have specific episodes, so now we have the first episode right here. First episode, first item would have the title of that episode, as well as looks like the

We have specific episodes, so now we have the first episode right here. First episode, first item would have the title of that episode, as well as looks like the enclosure length and audio URL. This is what we would need right here. We have these iTunes namespaces for the episode number, as well as the episode duration right here. Those are the things that we need from this process job. Why don't we first just kind of die and dump all this information, and then get it stored in specific variables. Let's just say that this XML is going to be set to simplexml_load_file, and then we're

Debug XML Parsing1:19

in specific variables. Let's just say that this XML is going to be set to simplexml_load_file, and then we're going to pass in the RSS URL. Then what we can do here is actually grab the information we need. The first thing we can say the podcast title is going to be xml->channel->title, but before we even try to guess that, why don't we just go ahead and dd this information. We have the XML, and we're just going to dd that. We're going to be able to display it in our terminal to see what we need to grab, and then save. Let's run this from our DashboardComponent.

then save. Let's run this from our dashboard component. What we can do is process podcast URL, dispatch, and then we're going to send it this media URL. We could also send it to the listening party. This is what Copilot kind of set up for me. I'm trying to think of the best way because we have the media URL, and that's linked to the episode itself. We probably won't need it, but it's also just great to have because if we have that, then we can easily set the end time without having to do any kind of query.

We probably won't need it, but it's also just great to have because if we have that, then we can easily set the end time without having to do any kind of query. We do set the public listening party and set that in here so that when we accept that listening party, we can then update it further down the road. Why don't we actually do the same for the episode itself? We'll say episode. There we go. In the process podcast URL, we have the RSS URL, we have the listening party, and we have the episode. Now we have all the pieces that we should need.

the episode. Now we have all the pieces that we should need. The last thing we'll need to do is bring in this namespace here. We can use app/jobs, and then we called it processPodcastURL. Perfect. Let's go ahead and try this out in the browser. In our listening party, we have the Lyricast snippet launch new episode. Then we can paste in the RSS feed and set a specific end time or a specific start time for this listening party, create listening party. Now we have that new listening party entry in our database, but if we go into our terminal,

for this listening party, create listening party. Now we have that new listening party entry in our database, but if we go into our terminal, we should, oops, we need to actually run the queue. We should see that information. Here we go. This is going to be a lot of information, so why don't we go ahead and scroll all the way up to the top one. This is first. Here we go. Yes.

Here we go. Yes. We have, this is basically the entire RSS feed. You'll notice that when we were taking a look here, there's a lot of iTunes namespaces. Within XML, we actually have to register those namespace to be able to grab that information. We do know that we at least need the iTunes duration. It looks like the XML does have, for example, the first item does have this attributes of length. If we assumed that every audio podcast episode was at a bit rate of 128 kilobytes per second, then we could estimate the length, but it's nice to have this iTunes duration with this

If we assumed that every audio podcast episode was at a bit rate of 128 kilobytes per second, then we could estimate the length, but it's nice to have this iTunes duration with this iTunes namespace right here, but it looks like within the XML, without having to grab the iTunes namespace for everything else, we can get the title of the first element, which is going to be the most recent episode. We can get the title of the podcast, and we can get the image URL of the podcast, as well as the episode URL. Why don't we do that? Let's grab image URL, podcast name, episode name, episode URL. Our process podcast URL, we can say, let's go ahead and say the podcast title is going

Let's grab imageURL, podcastName, episodeName, episodeURL. Our process podcastURL, we can say, let's go ahead and say the podcastTitle is going to be, and if we were to take a look at that element again, we have this channelTitle. That works great. So XML channelTitle. We have the podcastArtworkURL is going to be XML channelImageURL. Then we have the episode. So we have the episodeTitle is going to be the first item in the channel and that title. Before we grab the episodeMediaURL, one thing that is helpful to do because of how XML is processed and the simpleXMLLoadFile works within php is we can first, let's first

Before we grab the episode media URL, one thing that is helpful to do because of how XML is processed and the simplexml_load_file function works within php is we can first, let's first set the latestEpisode. So that way we have latestEpisode and the XML title would be latestEpisodeTitle. Then we have the episode media URL, and here's where it's going to be a little bit different than what has kind of already been scaffolded out for us. It's going to be the latestEpisode, but we want to cast this to a string because if we take a look at the enclosure here, we have this @attributes and simplexml returns this SimpleXMLElement object instead for attributes. And so what we want to do is cast that then to a string because we need the URL for that.

Read iTunes Duration6:55

this simple XML element object instead for attributes. And so what we want to do is cast that then to a string because we need the URL for that specific attribute. So what we can do is cast this to a string and then we want the latest episode enclosure and that's going to be an array for the URL item. Perfect. And next we need the length of the episode. And now this is where we need to register the iTunes namespace so that we can grab that from the XML. So we can say namespaces is equal to XML::getNamespaces(true), and then we need the

from the XML. So we can say namespaces is equal to XML, getNamespaces(true), and then we need the iTunes namespace, which is namespaces with the array item of iTunes. Then the episodeLength is going to be the latest episode's children with the iTunes namespace for duration because if we take a look at that XML here, we have the first children, then we have the iTunes namespace duration. And that's what we're looking for the XML. The namespace is basically just using maybe something similar to like dot notation or similar to how we are scaffolding out within JSON. But now we've registered that iTunes namespace to be able to grab that colon duration piece.

Compute End Time8:12

similar to how we are scaffolding out within JSON. But now we've registered that iTunes namespace to be able to grab that colon duration piece. So because this iTunes duration that we're grabbing is in this format of hours, minutes, seconds, we do have to use some Carbon magic to be able to take that time, get it into the format we want it so that we can add it to our original start time and set our end time for the time it should be after the episode was to finish. We already have the episode length, and that's going to be in that. It's just the strict something like, you know, 000001257, for example. So what we need to do next is get the interval, in this case, Carbon interval, so that we can add it to our start time, and that's how we set our end time.

So what we need to do next is get the interval, in this case, Carbon interval, so that we can add it to our start time, and that's how we set our end time. So our interval is going to be – we can set this to a Carbon interval. We can createFromFormat, and it's going to be the hour, minutes, seconds, and we can bring Carbon interval in as the namespace, and we're setting the episode length. So then we can set the end time. So if we say end time is equal to this listening party start time, and then we're just adding the interval, and it's as simple as that. I believe now we have all of the pieces. So we have the podcast title.

I believe now we have all of the pieces. So we have the podcast title. We have the podcast artwork URL. We have the latest episode so that we can grab the episode title, the episode media URL. We can grab the length of the episode and add that to the startTime to get an endTime. Again, we're not modifying the startTime here, but we're using Carbon interval to grab this format so that way we can modify the startTime and add it to create our endTime. And now we'll go ahead and save these to the database. So what we're going to do is first, we already have the podcast.

Save Podcast and Episode10:11

And now we'll go ahead and save these to the database. So what we're going to do is first, we already have the Podcast. Actually, we don't have a Podcast created yet. So why don't we go ahead and create the Podcast? So first we need to create the Podcast and then update the Episode to be linked to the Podcast. So we can go ahead and say Podcast::create, and we can say the title is podcast title. The artworkUrl is podcast artwork URL. Okay, that looks good. Next, we can go ahead and update the Episode.

Okay, that looks good. Next, we can go ahead and update the episode. Let's bring in the Podcast model. Now we can update that episode and associate it with that podcast. But one thing that we do need to make sure of is in our podcast table, we do have a unique identifier of this title. So we should find if there is a podcast with this title, and because we're using RSS feeds, we shouldn't have any overlap for the most part. There's probably multiple podcasts with the same title, but we'll run into that issue when we get there.

There's probably multiple podcasts with the same title, but we'll run into that issue when we get there. So what we can do is podcast, and then we can say update or create. And this is just saying that we want to update the podcast if we find one, or we'll create a new one if one doesn't exist. So first the name, and that's the, or excuse me, the title. That's the podcast title. We have the artwork URL, and then we have the RSS URL. And let's take a look just to make sure we're not missing anything. We do have a section for description and hosts, and we can grab that if we really wanted to.

And let's take a look just to make sure we're not missing anything. We do have a section for description and hosts, and we can grab that if we really wanted to. But for now, we'll just kind of set this for here. And now that we have this podcast that is either being updated or created, why don't we go ahead and cast this to a variable so that we can use this podcast variable to update our episode. And we can say this episode. First, we want to get the podcast and associate it to the podcast that we have. So we just created a podcast, and now because we have in our episode, it belongs to a podcast, we can do that right here.

So we just created a Podcast, and now because we have in our Episode, it belongs to a Podcast, we can do that right here. Then we can start filling the rest, updating the Episode with the information that we have. So we can say this Episode, and we want to update it with the title, with episodeTitle. We have the media URL of episodeMediaURL, and that should be it because, yeah, we have the rss_episodes table. We have the title and media URL. Perfect. And now we can update the ListeningParty as the final step of this job. So let's go ahead and head back to our job, and that's been updated.

Test Job and Database13:02

And now we can update the ListeningParty as the final step of this job. So let's go ahead and head back to our job, and that's been updated. So now we can update the ListeningParty. So ListeningParty, we want to update, and we want to set the endTime to endTime. And then we should be good to go because now we have all the pieces in place to start this moving. So why don't we run a test and make sure in our database everything has been saved properly. Just so we have a clean slate, I always like to just start off with something fresh. So we will php artisan migrate:fresh, and we're good to go. Let's go ahead and test this out. And before we start that, why don't we start our queue:work and then create a ListeningParty.

Let's go ahead and test this out. And before we start that, why don't we start our Queue server and then create a listening party. My first listening party has been created. Let's take a look at our job that is running and looks like it's done. So completed in 312 milliseconds, and that is why we have a background job. We're not actually even working with additional information right now. It's just grabbing all that information and making sure we're processing it properly. So let's go ahead and take a look at our database. So I'm using TablePlus here. We have our first listening party.

So I'm using TablePlus here. We have our first listening party. It's active. It's registered to an episode. So everything looks good there. We have a start time, and then we have an end time. That is exactly 12 minutes and 57 seconds after our start time. In our podcasts, we have a new podcast, the Laricast snippet. We have the RSS URL. We have the artwork URL.

We have the RSS URL. We have the artwork URL. Here we go. And then in the episodes, we have the first episode, which is the newest episode of the podcast. We have the media URL, and everything looks good to go. So now we can actually start displaying this on our listening party page, updating the front end so that we can show what podcasts this is listening to. So in the next episode, we'll take a look at how we can start scaffolding out this page to have a listening party that is worth attending.

So in the next episode, we'll take a look at how we can start scaffolding out this page to have a listening party that is worth attending.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟