K-vanc / Tempest-EPG-Generator

The fastest XMLTV formatted EPG Generator with GUI and the lowest memory usage
https://hub.docker.com/r/kvanc/tempest_epg
Other
100 stars 17 forks source link

For Schedules Direct, token is always invalid #69

Closed wdwms closed 6 months ago

wdwms commented 6 months ago

For schedules direct, i get the guide, get all the images/icons.. but once my system tries to fetch the images, i get the

{"response":"INVALID_USER","code":4003,"serverID":"20141201.web","message":"Invalid username or token has expired.","datetime":"2023-12-29T20:14:36Z"}

How is the token being set?

K-vanc commented 6 months ago

Hi, I tested some and it works fine. According to Schedules Direct JSON API, token has to be hardcoded to the end of image urls and Tempest siteconfig with showicons, is exactly doing this. This token generated by API privately for you with your username and password. It has an expire date but I dont know how long it is since not mentioned by SD. As far as i know, it remains valid minimum a week(this was my longest check so it can be even more). Since it is hardcoded into generated xmltv file, you can increase your update inverval so Tempest will renew those image urls with fresh tokens.

Another possible issue is, it is also not so clear in SD but there could be an IP limit for token usage. Again as far as I know, they put some restrictions to reduce amazon server(where they are storing images) requests so if you are using a publicated epg file or you are sharing your epg file with others, they could be already fetched images with your token then system will block you as token expired.

Since both above cases are not a bug/issue from Tempest and Tempest is properly setting up icon urls, I dont see any problem here to be fixed so have to close issue.

wdwms commented 6 months ago

Ok i was able to replicate the issue. I don't know how your code exactly works, but a token with SD is only good until you request another token. I tested getting two channels from SD, both of them have unique tokens. And the only one that works is the last one.

This script needs to be updated to obtain only ONE token and append that to all image requests. I'm assuming you are requesting a token for each channel/request.

K-vanc commented 6 months ago

Yes, you are right. This siteconfig was working fine for almost last 2 years and it was the first thing that I checked several times if multiple tokens were working fine but suddenly they started cancelling previously generated tokens. Tempest creating fresh token for each channel which this method was also suggested in SD forum.

Anyway, I probably will not update anything for it. This SD people keep telling that they are supporting hobbiest applications but all they are doing to stop those applications by modifying their api and/or changing rules without any reason or notice. Instead of telling that they can write "we are supporting only our Manager's and 1 of his good friend's application" which will be more logical.

Sorry but to make it request single token for all, I need to revise my grabbing engine. I will not waste my time anymore for SD

K-vanc commented 6 months ago

I checked their forum and saw 1 reply from Robert to a discussion as now the tokens will be valid for 24 hours or till a new token generated(if earlier than 24 hours). That new approach is totally ridiculous because that token has to be generated for almost everything related with SD such as channel list update, adding/deleting your line-ups or even just querying available channels/line-ups, login into your account etc. since they are using that token instead of Sessions or Cookies so even if somehow i update Tempest to handle this and lets say you grab 100s of channels with single token showicon, as soon as you login your SD account to check something, your generated file will be trash for showicons since new token will be generated on your login and it will outdate the one in generated xml. Basicly, now they are expecting people to generate xml in single login/token for 1 day only and keep waiting without touching anything because even if you grab for multiple days, token will expire again tomorrow. I dont know yours but the players/PVRs that i use are not downloading all images of following 15days on the first load of epg file. They are just caching next 1-2days(depends on cache size) and stops till next update.

this is absolutely waste of time. I am really sorry about not helping but i feel like i can spend my limited free time for something more useful than unlimited and never-ending SD restrictions.. I know they are trying to limit requests to amazon server since they are paying them based on request amount but this is not the way of doing this.. SD is charging money for epg service so they have to adjust their price accordingly or they have to find better/cheaper solution than using a third-party storage server for images.

K-vanc commented 6 months ago

Anyway, what is done is done. Currently, i can only advise you to open resulting file with a regex replace supporting editor and replace all showicon tokens with latest one. You may auto do the same in command line with sed, i think. I will think about editing my grab engine. Maybe i can take advantage of some static url option in other web sources also but now i am working on repo maintenance then will release pending Tempest update. Only i can start working a solution after those so it will take some time.

wdwms commented 6 months ago

I wrote php for you and have it as a corn job running that replaces all the tokens with a new one, I'm away from that computer until tomorrow but will post it here. Happy New Year!

K-vanc commented 6 months ago

thanks, Happy New Year to you

wdwms commented 6 months ago

Here is the code i wrote, i have this as a cron job running about an hour or so after the SD update runs..

`<?php

// File paths $inputFilePath = "guide.xml"; // Replace with the actual input file path $outputFilePath = "guide-Fixed.xml"; // Replace with the actual output file path $userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36";

$curl = curl_init();

curl_setopt_array($curl, array( CURLOPT_URL => 'https://json.schedulesdirect.org/20141201/token', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_USERAGENT => $userAgent, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "username": "USERNAME", "password": "SD_PASSWORD" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), ));

$authResponse = curl_exec($curl);

// Check for cURL errors if (curl_errno($curl)) { echo 'Error during cURL request: ' . curl_error($curl); exit; }

// Close cURL session curl_close($curl);

// Decode the JSON response $authData = json_decode($authResponse, true);

// Check if authentication was successful if (isset($authData['token'])) { // Authentication successful, update the token $newToken = $authData['token'];

// Load the XML file
$xml = simplexml_load_file($inputFilePath);

// Check if the XML was loaded successfully
if ($xml === false) {
    echo "Failed to load XML file.\n";
    exit;
}

// Iterate through <icon> elements and replace the token in the src attribute
foreach ($xml->xpath('//icon/@src') as $src) {
    $url = (string) $src;

    // Validate that the URL is not empty
    if (!empty($url)) {
        // Extract existing token from the URL (if any)
        $urlParts = parse_url($url);
        $query = isset($urlParts['query']) ? $urlParts['query'] : '';
        parse_str($query, $queryParameters);
        $existingToken = isset($queryParameters['token']) ? $queryParameters['token'] : '';

        // Replace the existing token with the new one
        $newUrl = str_replace("token={$existingToken}", "token={$newToken}", $url);

        // Update the attribute value
        $src[0] = $newUrl;
    }
}

// Save the modified XML to the output file
$xml->asXML($outputFilePath);

echo "Updated URLs written to: $outputFilePath\n";

} else { // Authentication failed echo "Authentication failed. Please check your credentials.\n"; } ?> `

K-vanc commented 5 months ago

hi @wdwms

I modified grabbing engine a little bit to keep some required urls as static by flagging them with a new option tickbox. It is working very good on SD and some other websites that using first url for authentication. Actually it worked perfectly even with other conditions such as keepindex and cyclone modules and I made it very easily which usually shouldn't be like that for the most cases..πŸ˜„ so it made me consider to test more before releasing new update. So probably within this month(close to end of it), I will publish new version which will resolve that token issue and also speed up grabbing of several siteconfigs by eliminating recall of 1-time needed urls.

wdwms commented 5 months ago

Thank you. I've moved on from this product to another that serves my needs better

zackpollard commented 4 months ago

hi @wdwms

I modified grabbing engine a little bit to keep some required urls as static by flagging them with a new option tickbox. It is working very good on SD and some other websites that using first url for authentication. Actually it worked perfectly even with other conditions such as keepindex and cyclone modules and I made it very easily which usually shouldn't be like that for the most cases..πŸ˜„ so it made me consider to test more before releasing new update. So probably within this month(close to end of it), I will publish new version which will resolve that token issue and also speed up grabbing of several siteconfigs by eliminating recall of 1-time needed urls.

Just mentioning that I am also experiencing this issue and looking forward to the update to fix it πŸ˜„ Thought I would mention to show there is still interest as the original reporter has switched to other software.

K-vanc commented 4 months ago

Hi @zackpollard

New version is working fine and update will be published when I return back from vacation next week. Actually, both i wanted to test more and held the release while i am in vacation because in case of an unexpected error, i wouldn't have chance to fix. So please try to stand 1 week moreΒ πŸ˜„

K-vanc commented 4 months ago

hi @zackpollard

You can update Tempest into 1.6.2.0 and download updated SchedulesDirect siteconfig for static url option now. Now similar to keepindex behaviour, generated token from the first SD channel will be stored as long as following channel belongs to same siteconfig(in this case SD siteconfig).

Note: Do not forget to replace your username/password before using new siteconfig