Is it possible to add a filter to only show live streams?
Additionally, an ability to show how many viewers in a field would be a great addition as well.

Comments

GDrupal’s picture

Status: Active » Postponed

Twitch API does not provide the current viewers and no live status for now, so no much to do there. If you find some property from API response that could give us a clue about that just let me know. Until we have something to deal with this from the API I will mark this issue as postponed.

ColdSun’s picture

Status: Postponed » Active

Wow, pretty quick reply. For that I thank you deeply.

According to Twitch, their API does support current viewers and live status.
https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md

Here's two examples of their api being used:

http://codepen.io/svinkle/pen/qIyAE
http://www.incendiarymedia.org/twitch/status.php

GDrupal’s picture

Hey thanks for look into this, it seems that the key is on "https://api.twitch.tv/kraken/streams/" I was reviewing the json object provided by the api urls I'm already using and look that they work differently. So we have a mechanism for get the live stream status. The actual status and viewers could be included in the preprocess function it's not a big deal. But, what do you mean with filter? Are you talking about a view filter handler?

ColdSun’s picture

Yes, a view handle filter would be great so we could filter only live streams in a block and hide the block accordingly.

GDrupal’s picture

That handler could be tricky, the most probably I will not have time to work on that in short term but I will be happy to review any patch if you want to add the functionality.

ColdSun’s picture

Currently I'm swamped with working on launching a site, but may have sometime in the future.

Would you be able to address the live stream status and viewers via preprocess function though, as I think that it in itself is viable even without a views filter handler (which I can look into once this site is out the door :P)

  • Commit 3f0ffe1 on 7.x-1.x by GDrupal:
    Issue #2239445 by ColdSun: Ability to filter based on Live?.
    
GDrupal’s picture

Status: Active » Needs review
tuutti’s picture

StatusFileSize
new16.2 KB

I needed this feature as well and wrote custom module to extend the functionality, but decided to try to merge it with this.

At the moment, it fetch 'metadata' (like viewers, followers, game name, total views etc.) when you first time save the file field and saves the fetched data to file_entity's file_metadata table.

Caveats at this approach are that metadata is stored in a BLOB field as serialized string, thus it cannot be used to create complex SQL queries like sort by viewer count etc.

I didn't test this with file_entity bundled with media 7.x-1.x, so this most likely requires media and file_entity 7.x-2.x.

I wrote basic views and rules integrations as well. You can use it by adding relationship to file_managed entity. For example if you had media field called 'field_stream_url' the relationship field name would be 'Stream url (field_stream_url:fid) '.

Once you have the relationship, you should be able to use the following fields/filters:
- Field: Media Twitch: Stream delay
- Field: Media Twitch: Followers
- Field: Media Twitch: Views
- Field: Media Twitch: Game name
- Field: Media Twitch: Current viewers
- Field: Media Twitch: Stream is online
- Filter: Media Twitch: Stream status

Rules can be used to re-fetch the data with cron. We use more complex queue system to re-fetch/update the data that requires Beanstalk, so I included version that works with cron.

I also needed functionality for embedding twitch chat, so I added new new file formatter for chat (included in this patch). Let me know if you want me to create a separate issue for it.

GDrupal’s picture

@tuutti dude this is huge! Thanks for this great work, i will need some time to review it for sure. At first sight perhaps will be good idea to fetch the data directly from twitch (perhaps with a cache per url) rather than save it as metadata but I do not know if that will fit your approach... any way I will take time and try to give it try. Thanks again.

tuutti’s picture

You are right, caching Twitch data might actually be better than using metadata table since we can't use complex sql queries anyways and it would be compatible with media 7.x-1.x.

I'll look into it once I have time.

youkho’s picture

When using this patch the chat is showing but the video isn't... if someone can fix it that would be helpful thanks.

pradeep22saini’s picture

table or view not found: 1146 Table 'drupal.file_metadata' doesn't exist
After applying patch #9 I am getting above error on adding a twitch channel link using media selector in the field.

I checked this patch with Media 7.1.x branch. Which don't have the Metadata table.

pradeep22saini’s picture

For 7.x.2.x branch the above patch #9 is working fine.

pradeep22saini’s picture

There is not option for adding sort by. Can somebody suggest some logic for sort by with online filter with this patch

pradeep22saini’s picture

StatusFileSize
new8.8 KB

on applying patch #9 on the latest dev branch not applied cleanly on the info file. So, modified accordingly for this.
Other then this logic is working good for with media 7.x.2 branch.

pradeep22saini’s picture

StatusFileSize
new17.27 KB

Above patch is incomplete this is a complete patch with info clean and added new sort handler.