Skip to content

Instantly share code, notes, and snippets.

@nicholastay
Created December 11, 2019 04:20
Show Gist options
  • Save nicholastay/fe1e44fba88ef5b87f1c0dc4e9165081 to your computer and use it in GitHub Desktop.
Save nicholastay/fe1e44fba88ef5b87f1c0dc4e9165081 to your computer and use it in GitHub Desktop.
scuffed streamlink plugin for fb gaming links
import re
from streamlink.plugin import PluginError
from streamlink.plugin.api import useragents
from streamlink.plugins.facebook import Facebook
class Facebookgg(Facebook):
_gaming_url_re = re.compile(r'''https?://(?:www\.)?(?:fb\.gg|facebook\.com/gaming)/(?P<fb_page>.*)''')
_gaming_re = re.compile(r'''"permalinkURL":"(.*?)"''')
@classmethod
def can_handle_url(cls, url):
return cls._gaming_url_re.match(url) is not None
def _get_streams(self):
self.session.http.headers.update({'User-Agent': useragents.CHROME})
res = self.session.http.get(self.url)
if res.status_code != 200:
raise PluginError('Could not get fbgg page (not 200)')
data = res.text
if '"isLive":true' not in data:
return dict()
mat = self._gaming_re.search(data)
if not mat:
raise PluginError('Could not get livestream information')
self.url = 'https://www.facebook.com' + mat.group(1).replace('\\', '')
return super()._get_streams()
__plugin__ = Facebookgg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment