Questions about PypoFetch & getSchedule for automated dynamic smart blocks
  • I've been spending the weekend studying Airtime code and attempting to come up with a solution that will allow the delayed & automatic creation of shows containing smart blocks. I'll offer more on my proposed solution after this question.

    I think that pypo fetch component routinely uses the Airtime API via - it imports and calls the get_schedule function.
           def get_schedule(self):
            # TODO : properly refactor this routine
            # For now the return type is a little messed up for compatibility reasons
            try: return (True,
            except: return (False, None)

    From here I've had to make some jumps of logic because I believe is the URL for the API which I believe calls the ApiController.php. In the API controller code I don't see a get_schedule function only a function called scheduleAction() which seems like it would return the actual schedule data via instantiating a the Application_Model_Schedule object. and calling getSchedule function. Is this scheduleAction() called routinely by PypoFetch or am I mistaken ?

    If I'm mistaken what does PypoFetch actually hit in the API ? I plan on testing this if I don't hear back from anyone but I thought I'd ask as I need something that will routinely trigger a function that I can use as a jumping point for my proposed automatically scheduled playlist.

    So in more details here is the partial solution that I came up with after analyzing the code. (any feedback/suggestions are welcome)

    My solution is for shows to have an additional field added to them called Default Playlist.

    This would be connected with an AJAX based autocomplete form that would allow the show producers to select a Play List from Airtime's list of Playlists and tie it the default for that show and add it to the schedule whenever that show is created or repeated (and added to the schedule). By itself this isn't much different from a linked show.

    But in conjunction there will be an option (checkbox) for Delay Scheduling of Playlist and a optional Time Select Dropbox (default 1 hour) that would allow you to select a time before this show is set to air to schedule the addition of the playlist. There would be another option (checkbox) that would be something like Wipe Existing Show when Scheduling Playlist.

    Basically there would be a hook (possibly placed inside of a function call from getSchedule()) that gets called and checks to see if any upcoming shows have a delayed scheduling request that is now within the time window. If so the AddPlaylistToShow function is called with the default playlist for this show.

    If the Wipe Existing Show option was checked it will first wipe out any content in the show already scheduled and then build the play list, otherwise it will simply append the play list onto the end of the show with whatever content was already scheduled. If the show content was already fully scheduled it will simply overbook, but if for instance a program producer forgot to schedule their show or left a lot of dead air this could be used as a filler mechanism.

    If the Default Playlist contains Smart Blocks they should be scheduled dynamically at this time as well, using the modifications to the Smart Blocp { margin-bottom: 0.1in; line-height: 120%; }k that allows filtering via newest or oldest (that I contributed) you could say for instance have it schedule the most recently added News Item into your block without requiring manual human intervention.

    I think this will work based upon my code analysis and would use the existing functions without requiring a huge rewrite of the code or breaking backwards compatibility with the existing functionality. It opens up more options for hands-free automation and I plan to code this as my time allows, although I'm more than happy to confer with the airtime developers to make this happen.

    The other option I considered coding was to have some kind of placeholder inside of the shows for unscheduled dynamic smart blocks, that would then be scheduled automatically when a threshold happens. This seemed like it would be more complicated and would require rewriting/modifying a lot more of the code than simply adding a default play list that gets added based upon a scheduled delay. Option 2 also has the potential to cause a lot more headaches and introduce bugs for users as the behaviour of the smart blocks would be harder to predict (ie knowing how long the would last beforehand). So I thought I'd try to do it in the least intrusive fashion so that it has a higher probability of getting into the next version of airtime and actually being useful.

    If I am able to get this coded then our station will finally be able to use Airtime as our primary automation system instead of simply a piece of middleware.

    Once this functionality is implemented I plan on adding a RSS podcast importer option to Airtime so that podcasts can be automatically imported then scheduled. Also I may be spending more time adding more functionality to the Smart Playlist (so that you can be more granular with sorting ie sort by other date fields such as last played or scheduled).

    Again any thoughts and especially help with determining the best way to hook back into airtime for automatic scheduling is appreciated. I think that the rest of it should be pretty straightforward after really reading the code.

  • 6 Comments sorted by
  • Vote Up0Vote Down hoerichhoerich
    Posts: 627Member, Airtime Moderator
    I wished I could help you, but I'm to small for this yet.
    In a few weeks we will try to parse schedule infos to feed our website.
    Maybe I can help you further later on...

    If you would achieve what you are trying to do, that would make soooo many users soooo happy.
    That's probably the feature request with highest demand!
    Keep goin!
    Post edited by hoerich at 2015-09-23 15:00:39
    Official Airtime Forum Manager
    Most of the time an issue is located between keyboard and chair.
  • Love the autodj fuction work around you have going..... would be happy to help test

    "Once this functionality is implemented I plan on adding a RSS podcast importer option to Airtime so that podcasts can be automatically imported then scheduled" This has already been successfully done and works perfectly for going on two years now airtime-rss-importer ....

    then the file is added to a playlist and scheduled, the script runs via cronjob, works like a charm!

  • A quick update. I have yet to start coding this.
    We at WCRS recently had to transition over to Airtime Pro as our primary automation instance, and so I've seen the SAAS version that is in development (and will probably be released as 3.0 at some point). It's a really nice overhaul of the interface. And makes it easier for end-users to use. 

    But the unreleased dev version also makes it somewhat confusing as to where I should be making any code contributions. I suspect that the SAAS code is all on airtime and thus available but actually getting it to run so I can use it as a development environment is a little tricky. I will most likely just continue to use 2.5 as the version to develop off of. I haven't had the time to spend to test and answer my own questions about the API and how to best trigger an automatic playlist generation. Again if anyone from the Airtime dev time has any ideas or suggestions here feel free to e-mail me or post on the forum. Otherwise I still plan on doing this but I have a lot of other day to day obligations (that now include manually downloading and uploading shows to Airtime Pro).

  • I wonder if you know what triggers filling of linked shows and for what period of time the filling is done.

    I think than controlling these parameters I could use scheduler in its current state for filling shows with updated files.

    If these parameters are stored somewhere like in the database it would be easy to control, but I fear they're embedded in code because I've searched in the database and found nothing, this would require changing the code, that seems too difficult for me.


  • The linked files I believe are scheduled when a view of the calendar is made. This was what my limited testing led me to believe. I also thought perhaps this would be a point of intervention but I wasn't able to pinpoint it exactly.
  • Ok, I'm studying the code pretty intently.
    This is all pretty complex, but the link shows aren't filled until you view them with the Calendar.
    This happens in this monster function insertAfter in the Scheduler.php which is called by the scheduleAfter function.

    There is a bug CC-5665 mentioned in the code that relates to linked smart playlists being generated and it taking time to generate them. This bug appears unresolved. This function the insertAfter one also appears to be a good point to modify the code to make it work as meets my needs.

    And the linked shows are created by the delegateInstanceCreation function in ShowService which calls Application_Service_SchedulerService::fillLinkedInstances which looks up the ShowsPopulatedUntil date. This date moves forward based upon calendar views by the Schedule.php model that calls createAndFillShowInstancesPastPopulatedUntilDate.

    So just to update anyone who stumbles upon this.

    My current thinking is that the ideal modification would be to just add another checkbox to the UI after the linked option in shows that says "Rebuild smart playlists in linked instances "15 minutes" before scheduled to air. The 15 minutes would be either an autocomplete or a drop box.

    Now figuring out how exactly to modify the code to make this work is the bigger challenge. Which is why I'm currently scouring and studying the code to understand exactly why each option happens and what triggers it. It's not horribly complicated but somewhat convoluted.

    This option will also only be useful if I add a smartblock that expands itself to fill an entire show length vs. the existing options for number of items and time. I think this could be done with my tightly time limited smart block code but then just modify the parameter to meet the time remaining in the show.

    I'll continue to update this post as I find time. I also still haven't delved too deeply into the best way to trigger this rescheduling event at a certain point but I'm confident that won't be too difficult once I decide upon how I want it coded. My fallback is to do things the way I originally proposed but the UI seemed a bit confusing compared to the approach I just suggested.
    Post edited by Robbt at 2016-01-10 11:46:01