kodi-pvr / pvr.iptvsimple

IPTV Simple client for Kodi PVR
GNU General Public License v2.0
773 stars 372 forks source link

add option for change "user_agent" #225

Closed efirshik closed 4 years ago

ryao commented 5 years ago

I don't understand how it works offhand, but you can add a useragent after the URL by doing something like this:

https://example|FooBar/1.2.3

It breaks compatibility with VLC. It would be nice to have a proper user agent tag added.

ryao commented 5 years ago

Adding support for the #EXTVLCOPT directive from VLC (e.g. #EXTVLCOPT:http-user-agent=“Foobot/1.2.3”) could work in a way that would be consistent with what others are doing:

https://github.com/Cigaras/IPTV.bundle/issues/164

ryao commented 5 years ago

A quick look through Kodi's API shows no obvious way of passing information to change the user agent string beyond the URL hack that I mentioned. pvr.iptvsimple is also completely unaware of this as it passes the URL as is:

https://github.com/kodi-pvr/pvr.iptvsimple/blob/6e44490841e31e149b1d71348fc29df4a04f89d9/src/PVRIptvData.cpp#L497

It seems that more than one operation is supported through this hack too:

https://github.com/xbmc/xbmc/blob/eb161cdb7c4c97e9f054192c9ea9e8d00839c305/xbmc/addons/kodi-addon-dev-kit/include/kodi/Filesystem.h#L186

There are also other VLC options that use #EXTVLCOPT. I don't see a comprehensive list, but the relevant ones can be seen on the lines that have var_InheritString:

https://github.com/videolan/vlc/blob/master/modules/access/http.c

The only two that are in common between the subset above and the ones xmbc supports from curl are referer and user agent. It would not be hard for someone to modify the code to implement support for these by doing some manipulation on the URL, although passing it through the URL feels wrong to me.

shamanNS commented 5 years ago

Take a look here: #177 The crucial information that can be gained from there is that GetFFMpegOptionsFromInput() method is called if you play m3u playlist directly as a file (outside of PVR component) but is not called when you let PVR addon parse the same m3u playlist.

There reason for that is here: link

So in order for HTTP headers you pass on by that construct "http://blabla.com/njah.m3u8|User-Agent=Mozilla" to be used not only by cURL request but also subsequent ffmpeg requests you will have to modify that if conditional and add OR condition to whatever "stream type" gets set by PVR addon , and compile that Kodi fork.

Here is the enum with available types: link

I can confirm that after doing that code change user-agent override will work in combination with pvr.iptvsimple addon, but can't really help you with what exactly would be correct stream type (maybe "DVDSTREAM_TYPE_HTTP" ???) because I'm using a fork of Kodi with changes added by CoreELEC team that were required in order to support seeking and watching "cutv" / "archive" / "server-backed X days timeshift" and among those changes that linked "DVDStreamType" enum now has a new member "DVDSTREAM_TYPE_PVR_ARCHIVE" that is used to indicate / to "mark" streams that support "archive seeking" functionality. So I used that stream type.

This is something that used to work on Kodi v16 out of the box and stopped working on v17 and now v18.

ryao commented 5 years ago

@shamanNS I do not see any changes made by CoreELEC to the code that you linked. At the time that I write this, the two functions are exactly the same:

https://github.com/CoreELEC/xbmc/blob/coreelec-9.0/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp#L241 https://github.com/xbmc/xbmc/blob/master/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp#L241

If you have a patch for this, why don't you submit it to the kodi project? At the very least, you could open an issue with kodi:

https://github.com/xbmc/xbmc/issues

At the moment, they have no open issues concerning what you described.

shamanNS commented 5 years ago

@ryao You can't see any changes because CoreELEC codebase doesn't include that particular change (also as far as I've noticed all those "support for archive" changes are added as patch files into CoreELEC repo). Kodi team doesn't want to include those changes "upstream". For reference see this topic on Kodi forum.

What I did on my own is this:

  1. forked both Kodi and pvr.iptvsimple repos
  2. checkout appropriate commits
  3. downloaded patch files from CoreELEC repo, referenced here
  4. applied the patches
  5. added that one extra change that is not used by CoreELEC's fork of Kodi codebase (actually I've also reverted one change made by CoreELEC team in regards to that "archive" functionality to remove added requirement that URL contains ".php" or ".m3u8" in order for seeking to be enabled)
  6. compiled my Kodi and pvr.iptvsimple forks for Windows

The problem is fixed for my use-case. And like I stated I have no idea what would value of that ENUM I've previously mentioned (since you can't just use "DVDSTREAM_TYPE_PVR_ARCHIVE" on official Kodi repo code). So to make things somewhat clearer: you (probably) don't need all those changes that were added to Kodi's codebase used by CoreELEC project but you will "just" have to figure out what type of stream is assigned when using unmodified Kodi + unmodified pvr.iptvsimple codebase.

Feel free to create an issues yourself. I'm not even sure is it is a bug or it functions with those imposed limitation "by design".

I'm actually not a programmer / developer and thus I have next to zero knowledge of the whole "Github workflow", in regards to creating and submitting Pull requests "upstream" ( I don't even know how to create "patch" file similar to those used by CoreELEC team).

efirshik commented 5 years ago

found how to make useragent work:

EXTM3U

EXTINF:-1,YourChannel

http://ip:port|user-agent=NameYourUserAgent

work on libreelec Kodi v18.1, raspberry pi

phunkyfish commented 4 years ago

@efirshik

You are correct. This is the right way to pass user agent to kodi:

EXTM3U

EXTINF:-1,YourChannel

http://ip:port|user-agent=NameYourUserAgent

phunkyfish commented 4 years ago

For other custom user http headers this PR provides a method to send them in kodi 19: https://github.com/xbmc/xbmc/pull/16847

phunkyfish commented 4 years ago

And as of this PR #305 headers that were not being passed to ffmpeg should also be covered including support for supplying user-agent and referrer using EXTVLCOPT.

Be4stElectrjc commented 4 years ago

Hi, using the headers passing option found an easy solution for the problem. Simply added on the fly the User-Agent during the streams parsing. From the addon settings you can choose the User-Agent you like. I can do pull request eventually, even if i didn't update all the strings for the new UI feature...

phunkyfish commented 4 years ago

This is a weird one. While we want to allow the flexibility to deal with all situations at the same time overriding Kodi’s own user agent should be an advanced action that is rarely required. Kodi should represent itself as Kodi. In time all provider’s should accept Kodi’s user agent.

So I’m not sure it should be added as an addon setting. Because when it’s no longer needed we then need to remove it and we really shouldn’t need it in the first place.

Be4stElectrjc commented 4 years ago

In reality the User-Agent change it's only for the streams included in the playlist, so Kodi keeps it's own identity. If was permanent, one time would be enough. Outside of the parsing loop.

Evandro1975 commented 4 years ago

Hi, the magic words are "should accept", but the reality is that some providers, because of some malicious 3rd parts add-ons, they block kodi requests.

Be4stElectrjc commented 4 years ago

It's an option however, one should even don't use it. Then the addon takes the streams as written by the playlist.

phunkyfish commented 4 years ago

Added in #323 and #334