diff -Nru kodi-pvr-teleboy-18.2.3/CMakeLists.txt kodi-pvr-teleboy-19.8.0/CMakeLists.txt --- kodi-pvr-teleboy-18.2.3/CMakeLists.txt 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/CMakeLists.txt 2021-01-09 11:27:13.000000000 +0000 @@ -5,23 +5,14 @@ find_package(PkgConfig) find_package(Kodi REQUIRED) -find_package(kodiplatform REQUIRED) -find_package(p8-platform REQUIRED) find_package(RapidJSON REQUIRED) -include_directories(${kodiplatform_INCLUDE_DIRS} - ${p8-platform_INCLUDE_DIRS} - ${KODI_INCLUDE_DIR} +include_directories(${KODI_INCLUDE_DIR} ${RAPIDJSON_INCLUDE_DIRS} ) -set(DEPLIBS ${kodiplatform_LIBRARIES} - ${p8-platform_LIBRARIES} -) - set(TELEBOY_SOURCES src/Utils.cpp - src/client.cpp src/Curl.cpp src/md5.cpp src/Cache.cpp @@ -35,10 +26,10 @@ src/md5.h src/Cache.h src/UpdateThread.h - src/client.h src/TeleBoy.h src/to_string.h src/Utils.h + src/windows.h src/categories.h ) diff -Nru kodi-pvr-teleboy-18.2.3/debian/changelog kodi-pvr-teleboy-19.8.0/debian/changelog --- kodi-pvr-teleboy-18.2.3/debian/changelog 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/debian/changelog 2013-05-31 22:59:22.000000000 +0000 @@ -1,4 +1,4 @@ -kodi-pvr-teleboy (18.2.3-1~bionic) bionic; urgency=low +kodi-pvr-teleboy (19.8.0-1~bionic) bionic; urgency=low [ kodi ] * autogenerated dummy changelog diff -Nru kodi-pvr-teleboy-18.2.3/debian/control kodi-pvr-teleboy-19.8.0/debian/control --- kodi-pvr-teleboy-18.2.3/debian/control 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/debian/control 2013-05-31 22:59:22.000000000 +0000 @@ -1,9 +1,9 @@ Source: kodi-pvr-teleboy Priority: extra Maintainer: rbuehlma -Build-Depends: debhelper (>= 9.0.0), cmake, pkg-config, libkodiplatform-dev (>= 17.1), - kodi-addon-dev, rapidjson-dev, libp8-platform-dev -Standards-Version: 3.9.4 +Build-Depends: debhelper (>= 9.0.0), cmake, pkg-config, + kodi-addon-dev, rapidjson-dev +Standards-Version: 4.1.2 Section: libs Homepage: http://kodi.tv diff -Nru kodi-pvr-teleboy-18.2.3/debian/copyright kodi-pvr-teleboy-19.8.0/debian/copyright --- kodi-pvr-teleboy-18.2.3/debian/copyright 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/debian/copyright 2013-05-31 22:59:22.000000000 +0000 @@ -5,7 +5,7 @@ Files: * Copyright: 2016-2017 rbuehlma 2016-2017 trummerjo - 2005-2013 Team XBMC + 2005-2020 Team Kodi License: GPL-2+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,7 +50,8 @@ http://www.pulse-eight.net/ Files: debian/* -Copyright: 2015 Jean-Luc Barriere +Copyright: 2020 Team Kodi + 2015 Jean-Luc Barriere 2015 wsnipex 2017 rbuehlma License: GPL-2+ diff -Nru kodi-pvr-teleboy-18.2.3/debian/source/format kodi-pvr-teleboy-19.8.0/debian/source/format --- kodi-pvr-teleboy-18.2.3/debian/source/format 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/debian/source/format 2013-05-31 22:59:22.000000000 +0000 @@ -1 +1 @@ -3.0 (native) +3.0 (quilt) diff -Nru kodi-pvr-teleboy-18.2.3/.gitignore kodi-pvr-teleboy-19.8.0/.gitignore --- kodi-pvr-teleboy-18.2.3/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/.gitignore 2021-01-09 11:27:13.000000000 +0000 @@ -0,0 +1,50 @@ +# build artifacts +build/ +pvr.*/addon.xml + +# Debian build files +debian/changelog +debian/files +debian/*.log +debian/*.substvars +debian/.debhelper/ +debian/tmp/ +debian/kodi-pvr-*/ +obj-x86_64-linux-gnu/ + +# commonly used editors +# vim +*.swp + +# Eclipse +*.project +*.cproject +.classpath +*.sublime-* +.settings/ + +# KDevelop 4 +*.kdev4 + +# gedit +*~ + +# CLion +/.idea + +# clion +.idea/ + +# to prevent add after a "git format-patch VALUE" and "git add ." call +/*.patch + +# Visual Studio Code +.vscode + +# to prevent add if project code opened by Visual Studio over CMake file +.vs/ + +# General MacOS +.DS_Store +.AppleDouble +.LSOverride diff -Nru kodi-pvr-teleboy-18.2.3/Jenkinsfile kodi-pvr-teleboy-19.8.0/Jenkinsfile --- kodi-pvr-teleboy-18.2.3/Jenkinsfile 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/Jenkinsfile 2021-01-09 11:27:13.000000000 +0000 @@ -1 +1 @@ -buildPlugin(version: "Leia") +buildPlugin(version: "Matrix") diff -Nru kodi-pvr-teleboy-18.2.3/LICENSE.md kodi-pvr-teleboy-19.8.0/LICENSE.md --- kodi-pvr-teleboy-18.2.3/LICENSE.md 1970-01-01 00:00:00.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/LICENSE.md 2021-01-09 11:27:13.000000000 +0000 @@ -0,0 +1,264 @@ +The GNU General Public License, Version 2, June 1991 (GPLv2) +============================================================ + +> Copyright (C) 1989, 1991 Free Software Foundation, Inc. +> 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + + +Preamble +-------- + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public License is intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. This General Public License applies to most +of the Free Software Foundation's software and to any other program whose +authors commit to using it. (Some other Free Software Foundation software is +covered by the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our +General Public Licenses are designed to make sure that you have the freedom to +distribute copies of free software (and charge for this service if you wish), +that you receive source code or can get it if you want it, that you can change +the software or use pieces of it in new free programs; and that you know you can +do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny +you these rights or to ask you to surrender the rights. These restrictions +translate to certain responsibilities for you if you distribute copies of the +software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a +fee, you must give the recipients all the rights that you have. You must make +sure that they, too, receive or can get the source code. And you must show them +these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer +you this license which gives you legal permission to copy, distribute and/or +modify the software. + +Also, for each author's protection and ours, we want to make certain that +everyone understands that there is no warranty for this free software. If the +software is modified by someone else and passed on, we want its recipients to +know that what they have is not the original, so that any problems introduced by +others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish +to avoid the danger that redistributors of a free program will individually +obtain patent licenses, in effect making the program proprietary. To prevent +this, we have made it clear that any patent must be licensed for everyone's free +use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification +follow. + + +Terms And Conditions For Copying, Distribution And Modification +--------------------------------------------------------------- + +**0.** This License applies to any program or other work which contains a notice +placed by the copyright holder saying it may be distributed under the terms of +this General Public License. The "Program", below, refers to any such program or +work, and a "work based on the Program" means either the Program or any +derivative work under copyright law: that is to say, a work containing the +Program or a portion of it, either verbatim or with modifications and/or +translated into another language. (Hereinafter, translation is included without +limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by +this License; they are outside its scope. The act of running the Program is not +restricted, and the output from the Program is covered only if its contents +constitute a work based on the Program (independent of having been made by +running the Program). Whether that is true depends on what the Program does. + +**1.** You may copy and distribute verbatim copies of the Program's source code +as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and +disclaimer of warranty; keep intact all the notices that refer to this License +and to the absence of any warranty; and give any other recipients of the Program +a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at +your option offer warranty protection in exchange for a fee. + +**2.** You may modify your copy or copies of the Program or any portion of it, +thus forming a work based on the Program, and copy and distribute such +modifications or work under the terms of Section 1 above, provided that you also +meet all of these conditions: + +* **a)** You must cause the modified files to carry prominent notices stating + that you changed the files and the date of any change. + +* **b)** You must cause any work that you distribute or publish, that in whole + or in part contains or is derived from the Program or any part thereof, to + be licensed as a whole at no charge to all third parties under the terms of + this License. + +* **c)** If the modified program normally reads commands interactively when + run, you must cause it, when started running for such interactive use in the + most ordinary way, to print or display an announcement including an + appropriate copyright notice and a notice that there is no warranty (or + else, saying that you provide a warranty) and that users may redistribute + the program under these conditions, and telling the user how to view a copy + of this License. (Exception: if the Program itself is interactive but does + not normally print such an announcement, your work based on the Program is + not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Program, and can be reasonably +considered independent and separate works in themselves, then this License, and +its terms, do not apply to those sections when you distribute them as separate +works. But when you distribute the same sections as part of a whole which is a +work based on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the entire whole, +and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your +rights to work written entirely by you; rather, the intent is to exercise the +right to control the distribution of derivative or collective works based on the +Program. + +In addition, mere aggregation of another work not based on the Program with the +Program (or with a work based on the Program) on a volume of a storage or +distribution medium does not bring the other work under the scope of this +License. + +**3.** You may copy and distribute the Program (or a work based on it, under +Section 2) in object code or executable form under the terms of Sections 1 and 2 +above provided that you also do one of the following: + +* **a)** Accompany it with the complete corresponding machine-readable source + code, which must be distributed under the terms of Sections 1 and 2 above on + a medium customarily used for software interchange; or, + +* **b)** Accompany it with a written offer, valid for at least three years, to + give any third party, for a charge no more than your cost of physically + performing source distribution, a complete machine-readable copy of the + corresponding source code, to be distributed under the terms of Sections 1 + and 2 above on a medium customarily used for software interchange; or, + +* **c)** Accompany it with the information you received as to the offer to + distribute corresponding source code. (This alternative is allowed only for + noncommercial distribution and only if you received the program in object + code or executable form with such an offer, in accord with Subsection b + above.) + +The source code for a work means the preferred form of the work for making +modifications to it. For an executable work, complete source code means all the +source code for all modules it contains, plus any associated interface +definition files, plus the scripts used to control compilation and installation +of the executable. However, as a special exception, the source code distributed +need not include anything that is normally distributed (in either source or +binary form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component itself +accompanies the executable. + +If distribution of executable or object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the source code +from the same place counts as distribution of the source code, even though third +parties are not compelled to copy the source along with the object code. + +**4.** You may not copy, modify, sublicense, or distribute the Program except as +expressly provided under this License. Any attempt otherwise to copy, modify, +sublicense or distribute the Program is void, and will automatically terminate +your rights under this License. However, parties who have received copies, or +rights, from you under this License will not have their licenses terminated so +long as such parties remain in full compliance. + +**5.** You are not required to accept this License, since you have not signed +it. However, nothing else grants you permission to modify or distribute the +Program or its derivative works. These actions are prohibited by law if you do +not accept this License. Therefore, by modifying or distributing the Program (or +any work based on the Program), you indicate your acceptance of this License to +do so, and all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +**6.** Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these terms and +conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties to this License. + +**7.** If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), conditions +are imposed on you (whether by court order, agreement or otherwise) that +contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot distribute so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not distribute the Program at all. +For example, if a patent license would not permit royalty-free redistribution of +the Program by all those who receive copies directly or indirectly through you, +then the only way you could satisfy both it and this License would be to refrain +entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply and the +section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or +other property right claims or to contest validity of any such claims; this +section has the sole purpose of protecting the integrity of the free software +distribution system, which is implemented by public license practices. Many +people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose that +choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +**8.** If the distribution and/or use of the Program is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Program under this License may add an explicit +geographical distribution limitation excluding those countries, so that +distribution is permitted only in or among countries not thus excluded. In such +case, this License incorporates the limitation as if written in the body of this +License. + +**9.** The Free Software Foundation may publish revised and/or new versions of +the General Public License from time to time. Such new versions will be similar +in spirit to the present version, but may differ in detail to address new +problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that version +or of any later version published by the Free Software Foundation. If the +Program does not specify a version number of this License, you may choose any +version ever published by the Free Software Foundation. + +**10.** If you wish to incorporate parts of the Program into other free programs +whose distribution conditions are different, write to the author to ask for +permission. For software which is copyrighted by the Free Software Foundation, +write to the Free Software Foundation; we sometimes make exceptions for this. +Our decision will be guided by the two goals of preserving the free status of +all derivatives of our free software and of promoting the sharing and reuse of +software generally. + + +No Warranty +----------- + +**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR +THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM +"AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR +INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA +BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER +OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. diff -Nru kodi-pvr-teleboy-18.2.3/pvr.teleboy/addon.xml.in kodi-pvr-teleboy-19.8.0/pvr.teleboy/addon.xml.in --- kodi-pvr-teleboy-18.2.3/pvr.teleboy/addon.xml.in 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/pvr.teleboy/addon.xml.in 2021-01-09 11:27:13.000000000 +0000 @@ -1,13 +1,13 @@ @ADDON_DEPENDS@ - + Kodi-PVR-Client für Teleboy Kodi's frontend for Teleboy @@ -25,7 +25,95 @@ The authors are in no way responsible for failed recordings, incorrect timers, wasted hours, or any other undesirable effects.. The authors are in no way responsible for failed recordings, incorrect timers, wasted hours, or any other undesirable effects.. @PLATFORM@ + GPL-2.0-or-later + https://github.com/rbuehlma/pvr.teleboy + + icon.png + fanart.jpg + +v19.8.0 + - Update PVR API 7.1.0 +v19.7.1 + - Rebuild +v19.7.0 + - Update PVR API 7.0.2 +v19.6.2 + - Remove p8 from debian control file +v19.6.1 + - Remove p8-platform dependency + - Use std::thread + - Use std:mutex + - Remove unused p8-platform headers + - Fix saving data.json +v19.6.0 + - Update PVR API 7.0.0 + - Major changes to match new API +v19.5.0 + - Update PVR API 6.5.1 + - Update Global API 1.2.0 +v19.4.9 + - Update PVR API 6.5.0 +v19.4.8 + - Update PVR API 6.4.0 + - Correct license name on addon.xml +v19.4.7 + - Fix cache cleanup + - Prevent log flooding about missing categories +v19.4.6 + - Rebuild of 19.4.5 +v19.4.5 + - Update PVR API 6.3.0 +v19.4.4 + - Update Debian build code + - Minor cleanups + - Add license name and source url to addon.xml + - Add GPL2 license file and show GPL2 on README.md +v19.4.3 + - Update PVR API 6.2.0 +v19.4.2 + - Fix replay of currently running program + - Do not show cache parse error if file has been removed +v19.4.1 + - Set genre on (planned) recordings +v19.4.0 + - Disable addon for free accounts +v19.3.8 + - Load recordings only when addon is ready +v19.3.7 + - Init update threads after login + - Fix error messages + - Reduce number of update threads +v19.3.6 + - Implement HTTP request caching + - Add addon information to user agent +v19.3.5 + - Add inputstream.adaptive as dependency + - Move changelog to addon metadata +v19.3.4 + - Use Kodi epg categories + - Add option to disable Dolby +v19.3.3 + - Use new stream api for replay and recordings + - Support Dolby +v19.3.2 + - Fix logos + - Serialize sending EPG to Kodi +v19.3.1 + - Actually use dash streams +v19.3.0 + - Persist session cookie + - Use dash streams +v19.2.2 + - Correctly load genres +v19.2.1 + - Update cmake build system to Version 3.5 +v19.2.0 +- Recompile for 6.1.0 PVR Addon API compatibility +v19.1.0 + - Update to GUI addon API v5.14.0 +v19.0.0 + - Update to PVR addon API v6.0.0 v18.2.3 - Fix cache cleanup - Prevent log flooding about missing categories @@ -50,7 +138,7 @@ - Move changelog to addon metadata v18.1.4 - Use Kodi epg categories - - Add option to disable Dolby + - Add option to disable Dolby v18.1.3 - Use new stream api for replay and recordings - Support Dolby diff -Nru kodi-pvr-teleboy-18.2.3/README.md kodi-pvr-teleboy-19.8.0/README.md --- kodi-pvr-teleboy-18.2.3/README.md 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/README.md 2021-01-09 11:27:13.000000000 +0000 @@ -1,11 +1,14 @@ +[![License: GPL-2.0-or-later](https://img.shields.io/badge/License-GPL%20v2+-blue.svg)](LICENSE.md) +[![Build Status](https://jenkins.kodi.tv/view/Addons/job/kodi-pvr/job/pvr.teleboy/job/Matrix/badge/icon)](https://jenkins.kodi.tv/blue/organizations/jenkins/rbuehlma%2Fpvr.teleboy/branches/) + # Teleboy PVR addon for Kodi This is a [Kodi](https://kodi.tv) PVR addon for streaming live TV from [Teleboy](https://www.teleboy.ch). ## Build instructions -1. `git clone --branch Leia https://github.com/xbmc/xbmc` -2. `git clone --branch Leia https://github.com/rbuehlma/pvr.teleboy` +1. `git clone --branch master https://github.com/xbmc/xbmc` +2. `git clone --branch Matrix https://github.com/rbuehlma/pvr.teleboy` 3. `cd pvr.teleboy && mkdir build && cd build` 4. `cmake -DADDONS_TO_BUILD=pvr.teleboy -DADDON_SRC_PREFIX=../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../xbmc/addons -DPACKAGE_ZIP=1 ../../xbmc/cmake/addons` 5. `make package-pvr.teleboy` diff -Nru kodi-pvr-teleboy-18.2.3/src/Cache.cpp kodi-pvr-teleboy-19.8.0/src/Cache.cpp --- kodi-pvr-teleboy-18.2.3/src/Cache.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/Cache.cpp 2021-01-09 11:27:13.000000000 +0000 @@ -1,22 +1,11 @@ #include "Cache.h" -#include "client.h" #include "Utils.h" -#include "kodi_vfs_types.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" -#ifdef TARGET_WINDOWS -#include -#ifdef CreateDirectory -#undef CreateDirectory -#endif -#ifdef DeleteFile -#undef DeleteFile -#endif -#endif +#include "kodi/Filesystem.h" using namespace rapidjson; -using namespace ADDON; constexpr char CACHE_DIR[] = "special://profile/addon_data/pvr.teleboy/cache/"; @@ -25,7 +14,7 @@ bool Cache::Read(const std::string& key, std::string& data) { std::string cacheFile = CACHE_DIR + key; - if (!XBMC->FileExists(cacheFile.c_str(), true)) + if (!kodi::vfs::FileExists(cacheFile, true)) { return false; } @@ -38,40 +27,40 @@ doc.Parse(jsonString.c_str()); if (doc.GetParseError()) { - if (XBMC->FileExists(cacheFile.c_str(), true)) + if (kodi::vfs::FileExists(cacheFile.c_str(), true)) { - XBMC->Log(LOG_ERROR, "Parsing cache file [%s] failed.", cacheFile.c_str()); + kodi::Log(ADDON_LOG_ERROR, "Parsing cache file [%s] failed.", cacheFile.c_str()); } return false; } if (!IsStillValid(doc)) { - XBMC->Log(LOG_DEBUG, "Ignoring cache file [%s] due to expiry.", + kodi::Log(ADDON_LOG_DEBUG, "Ignoring cache file [%s] due to expiry.", cacheFile.c_str()); return false; } - XBMC->Log(LOG_DEBUG, "Load from cache file [%s].", cacheFile.c_str()); + kodi::Log(ADDON_LOG_DEBUG, "Load from cache file [%s].", cacheFile.c_str()); data = doc["data"].GetString(); return !data.empty(); } void Cache::Write(const std::string& key, const std::string& data, time_t validUntil) { - if (!XBMC->DirectoryExists(CACHE_DIR)) + if (!kodi::vfs::DirectoryExists(CACHE_DIR)) { - if (!XBMC->CreateDirectory(CACHE_DIR)) + if (!kodi::vfs::CreateDirectory(CACHE_DIR)) { - XBMC->Log(LOG_ERROR, "Could not crate cache directory [%s].", CACHE_DIR); + kodi::Log(ADDON_LOG_ERROR, "Could not crate cache directory [%s].", CACHE_DIR); return; } } std::string cacheFile = CACHE_DIR + key; - void* file; - if (!(file = XBMC->OpenFileForWrite(cacheFile.c_str(), true))) + kodi::vfs::CFile file; + if (!file.OpenFileForWrite(cacheFile, true)) { - XBMC->Log(LOG_ERROR, "Could not write to cache file [%s].", + kodi::Log(ADDON_LOG_ERROR, "Could not write to cache file [%s].", cacheFile.c_str()); return; } @@ -87,8 +76,7 @@ Writer writer(buffer); d.Accept(writer); const char* output = buffer.GetString(); - XBMC->WriteFile(file, output, strlen(output)); - XBMC->CloseFile(file); + file.Write(output, strlen(output)); } void Cache::Cleanup() @@ -100,24 +88,24 @@ return; } m_lastCleanup = currTime; - if (!XBMC->DirectoryExists(CACHE_DIR)) + if (!kodi::vfs::DirectoryExists(CACHE_DIR)) { return; } - VFSDirEntry *items; - unsigned int itemCount; - if (!XBMC->GetDirectory(CACHE_DIR, "", &items, &itemCount)) + + std::vector items; + if (!kodi::vfs::GetDirectory(CACHE_DIR, "", items)) { - XBMC->Log(LOG_ERROR, "Could not get cache directory."); + kodi::Log(ADDON_LOG_ERROR, "Could not get cache directory."); return; } - for (unsigned int i = 0; i < itemCount; i++) + for (const auto& item : items) { - if (items[i].folder) + if (item.IsFolder()) { continue; } - char *path = items[i].path; + std::string path = item.Path(); std::string jsonString = Utils::ReadFile(path); if (jsonString.empty()) { @@ -127,22 +115,19 @@ doc.Parse(jsonString.c_str()); if (doc.GetParseError()) { - XBMC->Log(LOG_ERROR, "Parsing cache file [%s] failed. -> Delete", path); - XBMC->DeleteFile(path); + kodi::Log(ADDON_LOG_ERROR, "Parsing cache file [%s] failed. -> Delete", path.c_str()); + kodi::vfs::DeleteFile(path); } if (!IsStillValid(doc)) { - XBMC->Log(LOG_DEBUG, "Deleting expired cache file [%s].", path); - if (!XBMC->DeleteFile(path)) + kodi::Log(ADDON_LOG_DEBUG, "Deleting expired cache file [%s].", path.c_str()); + if (!kodi::vfs::DeleteFile(path)) { - XBMC->Log(LOG_DEBUG, "Deletion of file [%s] failed.", path); + kodi::Log(ADDON_LOG_DEBUG, "Deletion of file [%s] failed.", path.c_str()); } } - } - - XBMC->FreeDirectory(items, itemCount); } bool Cache::IsStillValid(const Value& cache) diff -Nru kodi-pvr-teleboy-18.2.3/src/categories.cpp kodi-pvr-teleboy-19.8.0/src/categories.cpp --- kodi-pvr-teleboy-18.2.3/src/categories.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/categories.cpp 2021-01-09 11:27:13.000000000 +0000 @@ -21,9 +21,10 @@ */ #include "categories.h" -#include "client.h" #include -#include +#include + +#include "kodi/Filesystem.h" #define CATEGORIES_MAXLINESIZE 255 @@ -32,8 +33,6 @@ # define strtok_r strtok_s #endif -using namespace ADDON; - Categories::Categories() : m_categoriesById() { @@ -75,7 +74,7 @@ auto it = m_categoriesByName.find(category); if (it != m_categoriesByName.end()) return it->second; - XBMC->Log(LOG_NOTICE, "Missing category: %s", category.c_str()); + kodi::Log(ADDON_LOG_INFO, "Missing category: %s", category.c_str()); m_categoriesByName[category]=0; return 0; } @@ -83,56 +82,39 @@ void Categories::LoadEITCategories() { const char *filePath = "special://home/addons/pvr.teleboy/resources/eit_categories.txt"; - if (!XBMC->FileExists(filePath, false)) { + if (!kodi::vfs::FileExists(filePath, false)) { filePath = "special://xbmc/addons/pvr.teleboy/resources/eit_categories.txt"; } - if (XBMC->FileExists(filePath, false)) + if (kodi::vfs::FileExists(filePath, false)) { - XBMC->Log(LOG_DEBUG, "%s: Loading EIT categories from file '%s'", + kodi::Log(ADDON_LOG_DEBUG, "%s: Loading EIT categories from file '%s'", __FUNCTION__, filePath); - void *file = XBMC->OpenFile(filePath, 0); - auto *line = new char[CATEGORIES_MAXLINESIZE + 1]; - auto *name = new char[CATEGORIES_MAXLINESIZE + 1]; - while (XBMC->ReadFileString(file, line, CATEGORIES_MAXLINESIZE)) + kodi::vfs::CFile file; + if (!file.OpenFile(filePath, 0)) + { + kodi::Log(ADDON_LOG_ERROR, "%s: File '%s' failed to open", __FUNCTION__, filePath); + return; + } + + std::string line; + std::regex rgx("^ *(0x.*)*; *\"(.*)\""); + while (file.ReadLine(line)) { - char* end = line + strlen(line); - char* pos = strchr(line, ';'); - if (pos != nullptr) + std::smatch matches; + if (std::regex_search(line, matches, rgx) && matches.size() == 3) { - bool encaps = false; - int catId; - *pos = '\0'; - if (sscanf(line, "%x", &catId) == 1) - { - unsigned p = 0; - memset(name, 0, CATEGORIES_MAXLINESIZE + 1); - do - { - ++pos; - } - while (isspace(*pos)); - if (*pos == '"') - encaps = true; - while (++pos < end) - { - if (encaps && *pos == '"' && *(++pos) != '"') - break; - if (!iscntrl(*pos)) - name[p++] = *pos; - } - m_categoriesById.insert(std::pair(catId, name)); - XBMC->Log(LOG_DEBUG, "%s: Add name [%s] for category %.2X", - __FUNCTION__, name, catId); - } + int catId = std::stoi(matches[1].str(), nullptr, 16); + std::string name = matches[2].str(); + + m_categoriesById.insert(std::pair(catId, name)); + kodi::Log(ADDON_LOG_DEBUG, "%s: Add name [%s] for category %.2X", + __FUNCTION__, name.c_str(), catId); } } - delete[] name; - delete[] line; - XBMC->CloseFile(file); } else { - XBMC->Log(LOG_INFO, "%s: File '%s' not found", __FUNCTION__, filePath); + kodi::Log(ADDON_LOG_INFO, "%s: File '%s' not found", __FUNCTION__, filePath); } } diff -Nru kodi-pvr-teleboy-18.2.3/src/client.cpp kodi-pvr-teleboy-19.8.0/src/client.cpp --- kodi-pvr-teleboy-18.2.3/src/client.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/client.cpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,725 +0,0 @@ -#include "client.h" -#include "TeleBoy.h" -#include "kodi/xbmc_pvr_dll.h" -#include "kodi/libKODI_guilib.h" -#include -#include - - -using namespace ADDON; - -#ifdef TARGET_WINDOWS -#define snprintf _snprintf -#endif - -#ifdef TARGET_ANDROID -#include "to_string.h" -#endif - -ADDON_STATUS m_CurStatus = ADDON_STATUS_UNKNOWN; -TeleBoy *teleboy = NULL; - -/* User adjustable settings are saved here. - * Default values are defined inside client.h - * and exported to the other source files. - */ -std::string g_strUserPath = ""; -std::string g_strClientPath = ""; - -CHelper_libXBMC_addon *XBMC = NULL; -CHelper_libXBMC_pvr *PVR = NULL; - -std::string teleboyUsername = ""; -std::string teleboyPassword = ""; -bool teleboyFavoritesOnly = false; -bool teleboyEnableDolby = true; -int runningRequests = 0; - -extern "C" -{ - -void ADDON_ReadSettings(void) -{ - char buffer[1024]; - bool boolBuffer; - XBMC->Log(LOG_DEBUG, "Read settings"); - if (XBMC->GetSetting("username", &buffer)) - { - teleboyUsername = buffer; - } - if (XBMC->GetSetting("password", &buffer)) - { - teleboyPassword = buffer; - } - if (XBMC->GetSetting("favoritesonly", &boolBuffer)) - { - teleboyFavoritesOnly = boolBuffer; - } - if (XBMC->GetSetting("enableDolby", &boolBuffer)) - { - teleboyEnableDolby = boolBuffer; - } - XBMC->Log(LOG_DEBUG, "End Readsettings"); -} - -ADDON_STATUS ADDON_Create(void *hdl, void *props) -{ - if (!hdl || !props) - { - return ADDON_STATUS_UNKNOWN; - } - - PVR_PROPERTIES *pvrprops = (PVR_PROPERTIES *) props; - - XBMC = new CHelper_libXBMC_addon; - XBMC->RegisterMe(hdl); - - if (!XBMC->RegisterMe(hdl)) - { - SAFE_DELETE(XBMC); - return ADDON_STATUS_PERMANENT_FAILURE; - } - - PVR = new CHelper_libXBMC_pvr; - if (!PVR->RegisterMe(hdl)) - { - SAFE_DELETE(PVR); - SAFE_DELETE(XBMC); - return ADDON_STATUS_PERMANENT_FAILURE; - } - - XBMC->Log(LOG_DEBUG, "%s - Creating the PVR Teleboy add-on", __FUNCTION__); - - m_CurStatus = ADDON_STATUS_NEED_SETTINGS; - - g_strClientPath = pvrprops->strClientPath; - g_strUserPath = pvrprops->strUserPath; - - teleboyUsername = ""; - teleboyPassword = ""; - ADDON_ReadSettings(); - - if (teleboyUsername.empty() || teleboyPassword.empty()) { - XBMC->Log(LOG_NOTICE, "Username or password not set."); - XBMC->QueueNotification(QUEUE_WARNING, XBMC->GetLocalizedString(30100)); - return m_CurStatus; - } - - XBMC->Log(LOG_DEBUG, "Create Teleboy"); - teleboy = new TeleBoy(teleboyFavoritesOnly, teleboyEnableDolby); - XBMC->Log(LOG_DEBUG, "Login Teleboy"); - if (teleboy->Login(teleboyUsername, teleboyPassword)) { - XBMC->Log(LOG_DEBUG, "Login done"); - m_CurStatus = ADDON_STATUS_OK; - } else { - XBMC->Log(LOG_ERROR, "Login failed"); - XBMC->QueueNotification(QUEUE_ERROR, XBMC->GetLocalizedString(30101)); - } - - return m_CurStatus; -} - -ADDON_STATUS ADDON_GetStatus() -{ - return m_CurStatus; -} - -void ADDON_Destroy() -{ - TeleBoy *oldTeleboy = teleboy; - teleboy = nullptr; - - int waitCount = 10; - while (runningRequests > 0 && waitCount > 0) - { - XBMC->Log(LOG_NOTICE, "Wait for %d requests to finish for %d seconds.", runningRequests, waitCount); - std::this_thread::sleep_for(std::chrono::seconds(1)); - waitCount--; - } - - SAFE_DELETE(oldTeleboy); - SAFE_DELETE(PVR); - SAFE_DELETE(XBMC); - - m_CurStatus = ADDON_STATUS_UNKNOWN; -} - -ADDON_STATUS ADDON_SetSetting(const char *settingName, const void *settingValue) -{ - string name = settingName; - - if (name == "username") - { - string username = (const char*) settingValue; - if (username != teleboyUsername) - { - teleboyUsername = username; - return ADDON_STATUS_NEED_RESTART; - } - } - - if (name == "password") - { - string password = (const char*) settingValue; - if (password != teleboyPassword) - { - teleboyPassword = password; - return ADDON_STATUS_NEED_RESTART; - } - } - - if (name == "favoritesonly") - { - bool favOnly = *(bool *) settingValue; - if (favOnly != teleboyFavoritesOnly) - { - teleboyFavoritesOnly = favOnly; - return ADDON_STATUS_NEED_RESTART; - } - } - - return ADDON_STATUS_OK; -} - -void ADDON_Stop() -{ -} - -/*********************************************************** - * PVR Client AddOn specific public library functions - ***********************************************************/ - -void OnSystemSleep() -{ -} - -void OnSystemWake() -{ -} - -void OnPowerSavingActivated() -{ -} - -void OnPowerSavingDeactivated() -{ -} - -PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) -{ - pCapabilities->bSupportsEPG = true; - pCapabilities->bSupportsTV = true; - pCapabilities->bSupportsRadio = false; - pCapabilities->bSupportsChannelGroups = false; - pCapabilities->bSupportsRecordingPlayCount = false; - pCapabilities->bSupportsLastPlayedPosition = false; - pCapabilities->bSupportsRecordingsRename = false; - pCapabilities->bSupportsRecordingsLifetimeChange = false; - pCapabilities->bSupportsDescrambleInfo = false; - pCapabilities->bSupportsEPGEdl = true; - pCapabilities->bSupportsRecordingEdl = true; - - runningRequests++; - if (teleboy) - { - teleboy->GetAddonCapabilities(pCapabilities); - } - runningRequests--; - return PVR_ERROR_NO_ERROR; -} - -const char *GetBackendName(void) -{ - static const char *strBackendName = "Teleboy PVR Add-on"; - return strBackendName; -} - -const char *GetBackendVersion(void) -{ - static std::string strBackendVersion = STR(IPTV_VERSION); - return strBackendVersion.c_str(); -} - -const char *GetConnectionString(void) -{ - static std::string strConnectionString = "connected"; - return strConnectionString.c_str(); -} - -const char *GetBackendHostname(void) -{ - return ""; -} - -PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL &channel, - time_t iStart, time_t iEnd) -{ - runningRequests++; - PVR_ERROR ret = PVR_ERROR_SERVER_ERROR; - if (teleboy) - { - teleboy->GetEPGForChannel(channel, iStart, iEnd); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - - return ret; -} - -int GetChannelsAmount(void) -{ - int ret = 0; - runningRequests++; - if (teleboy) - ret = teleboy->GetChannelsAmount(); - - runningRequests--; - - return ret; -} - -PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio) -{ - if (bRadio) - return PVR_ERROR_NO_ERROR; - - PVR_ERROR ret = PVR_ERROR_NO_ERROR; - runningRequests++; - if (teleboy) - ret = teleboy->GetChannels(handle, bRadio); - - runningRequests--; - - return ret; -} - -bool OpenLiveStream(const PVR_CHANNEL &channel) -{ - return false; -} - -void CloseLiveStream(void) -{ - -} - -int GetCurrentClientChannel(void) -{ - return -1; -} - -bool SwitchChannel(const PVR_CHANNEL &channel) -{ - CloseLiveStream(); - - return OpenLiveStream(channel); -} - -PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES* pProperties) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} - -int GetChannelGroupsAmount(void) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} - -PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio) -{ - return PVR_ERROR_SERVER_ERROR; -} - -PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, - const PVR_CHANNEL_GROUP &group) -{ - return PVR_ERROR_SERVER_ERROR; -} - -void setStreamProperty(PVR_NAMED_VALUE* properties, unsigned int* propertiesCount, std::string name, std::string value) -{ - strncpy(properties[*propertiesCount].strName, name.c_str(), sizeof(properties[*propertiesCount].strName) - 1); - strncpy(properties[*propertiesCount].strValue, value.c_str(), sizeof(properties[*propertiesCount].strValue) - 1); - *propertiesCount = (*propertiesCount) + 1; -} - -void setStreamProperties(PVR_NAMED_VALUE* properties, unsigned int* propertiesCount, std::string url) -{ - setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_STREAMURL, url); - setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_INPUTSTREAMADDON, "inputstream.adaptive"); - setStreamProperty(properties, propertiesCount, "inputstream.adaptive.manifest_type", "mpd"); - setStreamProperty(properties, propertiesCount, "inputstream.adaptive.manifest_update_parameter", "full"); - setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_MIMETYPE, "application/xml+dash"); -} - -PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL* channel, - PVR_NAMED_VALUE* properties, unsigned int* propertiesCount) -{ - PVR_ERROR ret = PVR_ERROR_FAILED; - runningRequests++; - std::string strUrl = teleboy->GetChannelStreamUrl(channel->iUniqueId); - if (!strUrl.empty()) - { - *propertiesCount = 0; - setStreamProperties(properties, propertiesCount, strUrl); - setStreamProperty(properties, propertiesCount, PVR_STREAM_PROPERTY_ISREALTIMESTREAM, "true"); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -PVR_ERROR GetRecordingStreamProperties(const PVR_RECORDING* recording, - PVR_NAMED_VALUE* properties, unsigned int* propertiesCount) -{ - PVR_ERROR ret = PVR_ERROR_FAILED; - runningRequests++; - std::string strUrl = teleboy->GetRecordingStreamUrl(recording->strRecordingId); - if (!strUrl.empty()) - { - *propertiesCount = 0; - setStreamProperties(properties, propertiesCount, strUrl); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -/** Recording API **/ -int GetRecordingsAmount(bool deleted) -{ - return 0; -} - -PVR_ERROR GetRecordings(ADDON_HANDLE handle, bool deleted) -{ - if (deleted) - { - return PVR_ERROR_NO_ERROR; - } - PVR_ERROR ret = PVR_ERROR_SERVER_ERROR; - runningRequests++; - if (teleboy && m_CurStatus == ADDON_STATUS_OK) - { - teleboy->GetRecordings(handle, "ready"); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -int GetTimersAmount(void) -{ - return 0; -} - -PVR_ERROR GetTimers(ADDON_HANDLE handle) -{ - PVR_ERROR ret = PVR_ERROR_SERVER_ERROR; - runningRequests++; - if (teleboy && m_CurStatus == ADDON_STATUS_OK) - { - teleboy->GetRecordings(handle, "planned"); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -PVR_ERROR AddTimer(const PVR_TIMER &timer) -{ - if (timer.iEpgUid <= EPG_TAG_INVALID_UID) - { - return PVR_ERROR_REJECTED; - } - runningRequests++; - PVR_ERROR ret = PVR_ERROR_SERVER_ERROR; - if (teleboy) - { - ret = PVR_ERROR_REJECTED; - if (teleboy->Record(timer.iEpgUid)) - { - PVR->TriggerTimerUpdate(); - PVR->TriggerRecordingUpdate(); - ret = PVR_ERROR_NO_ERROR; - } - } - runningRequests--; - return ret; -} - -PVR_ERROR DeleteRecording(const PVR_RECORDING &recording) -{ - PVR_ERROR ret = PVR_ERROR_SERVER_ERROR; - runningRequests++; - if (teleboy) - { - ret = PVR_ERROR_REJECTED; - if (teleboy->DeleteRecording(recording.strRecordingId)) - { - ret = PVR_ERROR_NO_ERROR; - } - } - runningRequests--; - return ret; -} - -PVR_ERROR DeleteTimer(const PVR_TIMER &timer, bool bForceDelete) -{ - PVR_ERROR ret = PVR_ERROR_SERVER_ERROR; - runningRequests++; - if (teleboy) - { - ret = PVR_ERROR_REJECTED; - if (teleboy->DeleteRecording(to_string(timer.iClientIndex))) - { - PVR->TriggerTimerUpdate(); - PVR->TriggerRecordingUpdate(); - ret = PVR_ERROR_NO_ERROR; - } - } - runningRequests--; - return ret; -} - -void addTimerType(PVR_TIMER_TYPE types[], int idx, int attributes) -{ - types[idx].iId = idx + 1; - types[idx].iAttributes = attributes; - types[idx].iPrioritiesSize = 0; - types[idx].iLifetimesSize = 0; - types[idx].iPreventDuplicateEpisodesSize = 0; - types[idx].iRecordingGroupSize = 0; - types[idx].iMaxRecordingsSize = 0; -} - -PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int *size) -{ - addTimerType(types, 0, PVR_TIMER_TYPE_ATTRIBUTE_NONE); - addTimerType(types, 1, PVR_TIMER_TYPE_IS_MANUAL); - *size = 2; - return PVR_ERROR_NO_ERROR; -} - -PVR_ERROR IsEPGTagRecordable(const EPG_TAG* tag, bool* bIsRecordable) -{ - PVR_ERROR ret = PVR_ERROR_FAILED; - runningRequests++; - if (teleboy) - { - *bIsRecordable = teleboy->IsRecordable(tag); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -PVR_ERROR IsEPGTagPlayable(const EPG_TAG* tag, bool* bIsPlayable) -{ - PVR_ERROR ret = PVR_ERROR_FAILED; - runningRequests++; - if (teleboy) - { - *bIsPlayable = teleboy->IsPlayable(tag); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -PVR_ERROR GetEPGTagStreamProperties(const EPG_TAG* tag, - PVR_NAMED_VALUE* properties, unsigned int* iPropertiesCount) -{ - PVR_ERROR ret = PVR_ERROR_FAILED; - runningRequests++; - std::string strUrl = teleboy->GetEpgTagUrl(tag); - if (!strUrl.empty()) - { - *iPropertiesCount = 0; - setStreamProperties(properties, iPropertiesCount, strUrl); - ret = PVR_ERROR_NO_ERROR; - } - runningRequests--; - return ret; -} - -PVR_ERROR GetEPGTagEdl(const EPG_TAG* epgTag, PVR_EDL_ENTRY edl[], int *size) -{ - edl[0].start=0; - edl[0].end = 300000; - edl[0].type = PVR_EDL_TYPE_COMBREAK; - *size = 1; - return PVR_ERROR_NO_ERROR; -} - -PVR_ERROR SetRecordingPlayCount(const PVR_RECORDING &recording, int count) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} - -PVR_ERROR SetRecordingLastPlayedPosition(const PVR_RECORDING &recording, - int lastplayedposition) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} - -int GetRecordingLastPlayedPosition(const PVR_RECORDING &recording) -{ - return -1; -} - -/** UNUSED API FUNCTIONS */ -bool CanPauseStream(void) -{ - return true; -} -PVR_ERROR OpenDialogChannelScan(void) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR CallMenuHook(const PVR_MENUHOOK &menuhook, - const PVR_MENUHOOK_DATA &item) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR DeleteChannel(const PVR_CHANNEL &channel) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR RenameChannel(const PVR_CHANNEL &channel) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR OpenDialogChannelSettings(const PVR_CHANNEL &channel) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR OpenDialogChannelAdd(const PVR_CHANNEL &channel) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -bool OpenRecordedStream(const PVR_RECORDING &recording) -{ - return false; -} -void CloseRecordedStream(void) -{ -} -int ReadRecordedStream(unsigned char *pBuffer, unsigned int iBufferSize) -{ - return 0; -} -long long SeekRecordedStream(long long iPosition, int iWhence /* = SEEK_SET */) -{ - return 0; -} -long long LengthRecordedStream(void) -{ - return 0; -} -void DemuxReset(void) -{ -} -void DemuxFlush(void) -{ -} -int ReadLiveStream(unsigned char *pBuffer, unsigned int iBufferSize) -{ - return 0; -} -long long SeekLiveStream(long long iPosition, int iWhence /* = SEEK_SET */) -{ - return -1; -} -long long LengthLiveStream(void) -{ - return -1; -} -PVR_ERROR RenameRecording(const PVR_RECORDING &recording) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR GetRecordingEdl(const PVR_RECORDING& recording, PVR_EDL_ENTRY edl[], int *size) -{ - edl[0].start=0; - edl[0].end = 300000; - edl[0].type = PVR_EDL_TYPE_COMBREAK; - *size = 1; - return PVR_ERROR_NO_ERROR; -} -PVR_ERROR UpdateTimer(const PVR_TIMER &timer) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -void DemuxAbort(void) -{ -} -DemuxPacket* DemuxRead(void) -{ - return NULL; -} -unsigned int GetChannelSwitchDelay(void) -{ - return 0; -} -bool IsTimeshifting(void) -{ - return false; -} -bool IsRealTimeStream(void) -{ - return true; -} -void PauseStream(bool bPaused) -{ -} -bool CanSeekStream(void) -{ - return true; -} -bool SeekTime(double, bool, double*) -{ - return false; -} -void SetSpeed(int) -{ -} -PVR_ERROR UndeleteRecording(const PVR_RECORDING& recording) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR DeleteAllRecordingsFromTrash() -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR SetEPGTimeFrame(int) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR GetDescrambleInfo(PVR_DESCRAMBLE_INFO*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR SetRecordingLifetime(const PVR_RECORDING*) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES *times) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR GetDriveSpace(long long *iTotal, long long *iUsed) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} -PVR_ERROR SignalStatus(PVR_SIGNAL_STATUS &signalStatus) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} - -PVR_ERROR GetStreamReadChunkSize(int* chunksize) -{ - return PVR_ERROR_NOT_IMPLEMENTED; -} - -} diff -Nru kodi-pvr-teleboy-18.2.3/src/client.h kodi-pvr-teleboy-19.8.0/src/client.h --- kodi-pvr-teleboy-18.2.3/src/client.h 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/client.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -#ifndef CLIENT_H -#define CLIENT_H - -#include "kodi/libXBMC_addon.h" -#include "kodi/libXBMC_pvr.h" -#include "p8-platform/threads/threads.h" -#include "p8-platform/util/util.h" - -extern std::string g_strUserPath; -extern std::string g_strClientPath; -extern ADDON::CHelper_libXBMC_addon *XBMC; -extern CHelper_libXBMC_pvr *PVR; - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#pragma comment(lib, "ws2_32.lib") -#include -#include -#define timegm _mkgmtime - -#define gmtime_r __gmtime_r -static inline struct tm *gmtime_r(const time_t *clock, struct tm *result) -{ - struct tm *data; - if (!clock || !result) - return NULL; - data = gmtime(clock); - if (!data) - return NULL; - memcpy(result, data, sizeof(*result)); - return result; -} - -#endif -#endif diff -Nru kodi-pvr-teleboy-18.2.3/src/Curl.cpp kodi-pvr-teleboy-19.8.0/src/Curl.cpp --- kodi-pvr-teleboy-18.2.3/src/Curl.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/Curl.cpp 2021-01-09 11:27:13.000000000 +0000 @@ -1,9 +1,9 @@ #include "Curl.h" -#include "client.h" #include "Utils.h" +#include "kodi/Filesystem.h" + using namespace std; -using namespace ADDON; Curl::Curl() { @@ -55,53 +55,45 @@ string Curl::Request(string action, string url, string postData, int &statusCode) { - void* file = XBMC->CURLCreate(url.c_str()); - if (!file) + kodi::vfs::CFile file; + if (!file.CURLCreate(url)) { statusCode = -1; return ""; } - XBMC->CURLAddOption(file, XFILE::CURL_OPTION_PROTOCOL, "customrequest", - action.c_str()); - - XBMC->CURLAddOption(file, XFILE::CURL_OPTION_HEADER, "acceptencoding", - "gzip"); + file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "customrequest", action); + file.CURLAddOption(ADDON_CURL_OPTION_HEADER, "acceptencoding", "gzip"); if (postData.size() != 0) { string base64 = Base64Encode((const unsigned char *) postData.c_str(), postData.size(), false); - XBMC->CURLAddOption(file, XFILE::CURL_OPTION_PROTOCOL, "postdata", - base64.c_str()); + file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "postdata", + base64); } for (auto const &entry : headers) { - XBMC->CURLAddOption(file, XFILE::CURL_OPTION_HEADER, entry.first.c_str(), - entry.second.c_str()); + file.CURLAddOption(ADDON_CURL_OPTION_HEADER, entry.first, entry.second); } for (auto const &entry : options) { - XBMC->CURLAddOption(file, XFILE::CURL_OPTION_PROTOCOL, entry.first.c_str(), - entry.second.c_str()); + file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, entry.first, entry.second); } - if (!XBMC->CURLOpen(file, XFILE::READ_NO_CACHE)) + if (!file.CURLOpen(ADDON_READ_NO_CACHE)) { statusCode = 403; //Fake statusCode for now return ""; } - int numValues; - char **cookiesPtr = XBMC->GetFilePropertyValues(file, - XFILE::FILE_PROPERTY_RESPONSE_HEADER, "set-cookie", &numValues); + const std::vector cookieList = file.GetPropertyValues( + ADDON_FILE_PROPERTY_RESPONSE_HEADER, "set-cookie"); - for (int i = 0; i < numValues; i++) + for (auto cookie : cookieList) { - char *cookiePtr = cookiesPtr[i]; - if (cookiePtr && *cookiePtr) + if (!cookie.empty()) { - string cookie = cookiePtr; std::string::size_type paramPos = cookie.find(';'); if (paramPos != std::string::npos) cookie.resize(paramPos); @@ -111,30 +103,23 @@ continue; } cookies[parts[0]] = parts[1]; - XBMC->Log(LOG_DEBUG, "Got cookie: %s.", parts[0].c_str()); + kodi::Log(ADDON_LOG_DEBUG, "Got cookie: %s.", parts[0].c_str()); } } - XBMC->FreeStringArray(cookiesPtr, numValues); - - char *tmp = XBMC->GetFilePropertyValue(file, - XFILE::FILE_PROPERTY_RESPONSE_HEADER, "Location"); - location = tmp != nullptr ? tmp : ""; - - XBMC->FreeString(tmp); + location = file.GetPropertyValue(ADDON_FILE_PROPERTY_RESPONSE_HEADER, "Location"); // read the file static const unsigned int CHUNKSIZE = 16384; char buf[CHUNKSIZE + 1]; size_t nbRead; string body = ""; - while ((nbRead = XBMC->ReadFile(file, buf, CHUNKSIZE)) > 0 && ~nbRead) + while ((nbRead = file.Read(buf, CHUNKSIZE)) > 0 && ~nbRead) { buf[nbRead] = 0x0; body += buf; } - XBMC->CloseFile(file); statusCode = 200; return body; } diff -Nru kodi-pvr-teleboy-18.2.3/src/TeleBoy.cpp kodi-pvr-teleboy-19.8.0/src/TeleBoy.cpp --- kodi-pvr-teleboy-18.2.3/src/TeleBoy.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/TeleBoy.cpp 2021-01-09 11:27:13.000000000 +0000 @@ -1,23 +1,28 @@ +#include "TeleBoy.h" +#include "Cache.h" +#include "md5.h" +#include "Utils.h" +#ifdef TARGET_WINDOWS +#include "windows.h" +#endif + #include #include #include -#include "TeleBoy.h" #include -#include "p8-platform/sockets/tcp.h" #include #include #include -#include "Utils.h" -#include "Cache.h" -#include "md5.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" +#include "kodi/General.h" +#include "kodi/Filesystem.h" + #ifdef TARGET_ANDROID #include "to_string.h" #endif -using namespace ADDON; using namespace std; using namespace rapidjson; @@ -25,7 +30,7 @@ static const string apiDeviceType = "desktop"; static const string apiVersion = "2.0"; const char data_file[] = "special://profile/addon_data/pvr.teleboy/data.json"; -P8PLATFORM::CMutex TeleBoy::sendEpgToKodiMutex; +std::mutex TeleBoy::sendEpgToKodiMutex; static const std::string user_agent = std::string("Kodi/") + std::string(STR(KODI_VERSION)) + std::string(" pvr.teleboy/") + std::string(STR(TELEBOY_VERSION)) + std::string(" (Kodi PVR addon)"); @@ -70,7 +75,7 @@ { curl.AddHeader("User-Agent", user_agent); int statusCode; - XBMC->Log(LOG_DEBUG, "Http-Request: %s %s.", action.c_str(), url.c_str()); + kodi::Log(ADDON_LOG_DEBUG, "Http-Request: %s %s.", action.c_str(), url.c_str()); string content; if (action.compare("POST") == 0) { @@ -150,25 +155,88 @@ return ApiGetResult(content, doc); } -TeleBoy::TeleBoy(bool favoritesOnly, bool enableDolby) : - username(""), password(""), maxRecallSeconds(60 * 60 * 24 * 7), cinergySCookies( +TeleBoy::TeleBoy() : + teleboyUsername(""), teleboyPassword(""), maxRecallSeconds(60 * 60 * 24 * 7), cinergySCookies( ""), isPlusMember(false), isComfortMember(false) { - XBMC->Log(LOG_NOTICE, "Using useragent: %s", user_agent.c_str()); + kodi::Log(ADDON_LOG_INFO, "Using useragent: %s", user_agent.c_str()); ReadDataJson(); - this->favoritesOnly = favoritesOnly; - this->enableDolby = enableDolby; } TeleBoy::~TeleBoy() { for (auto const &updateThread : updateThreads) { - updateThread->StopThread(200); delete updateThread; } } +ADDON_STATUS TeleBoy::Create() +{ + kodi::Log(ADDON_LOG_DEBUG, "%s - Creating the PVR Teleboy add-on", __FUNCTION__); + + favoritesOnly = kodi::GetSettingBoolean("favoritesonly"); + enableDolby = kodi::GetSettingBoolean("enableDolby"); + teleboyUsername = kodi::GetSettingString("username"); + teleboyPassword = kodi::GetSettingString("password"); + + if (teleboyUsername.empty() || teleboyPassword.empty()) + { + kodi::Log(ADDON_LOG_INFO, "Username or password not set."); + kodi::QueueNotification(QUEUE_WARNING, "", kodi::GetLocalizedString(30100)); + return ADDON_STATUS_NEED_SETTINGS; + } + + kodi::Log(ADDON_LOG_DEBUG, "Login Teleboy"); + if (Login(teleboyUsername, teleboyPassword)) + { + kodi::Log(ADDON_LOG_DEBUG, "Login done"); + } + else + { + kodi::Log(ADDON_LOG_ERROR, "Login failed"); + kodi::QueueNotification(QUEUE_ERROR, "", kodi::GetLocalizedString(30101)); + return ADDON_STATUS_NEED_SETTINGS; + } + + return ADDON_STATUS_OK; +} + +ADDON_STATUS TeleBoy::SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) +{ + if (settingName == "username") + { + string username = settingValue.GetString(); + if (username != teleboyUsername) + { + teleboyUsername = username; + return ADDON_STATUS_NEED_RESTART; + } + } + + if (settingName == "password") + { + string password = settingValue.GetString(); + if (password != teleboyPassword) + { + teleboyPassword = password; + return ADDON_STATUS_NEED_RESTART; + } + } + + if (settingName == "favoritesonly") + { + bool favOnly = settingValue.GetBoolean(); + if (favOnly != favoritesOnly) + { + favoritesOnly = favOnly; + return ADDON_STATUS_NEED_RESTART; + } + } + + return ADDON_STATUS_OK; +} + bool TeleBoy::Login(string u, string p) { string tbUrl = "https://www.teleboy.ch"; @@ -180,14 +248,14 @@ string result = HttpGet(curl, tbUrl + "/live"); bool isAuthenticated = result.find("setIsAuthenticated(true") != std::string::npos; curl.AddHeader("redirect-limit", "0"); - + if (!isAuthenticated) { - XBMC->Log(LOG_INFO, "Not yet authenticated. Try to login."); + kodi::Log(ADDON_LOG_INFO, "Not yet authenticated. Try to login."); HttpGet(curl, tbUrl + "/login"); string location = curl.GetLocation(); if (location.find("t.teleboy.ch") != string::npos) { - XBMC->Log(LOG_NOTICE, "Using t.teleboy.ch."); + kodi::Log(ADDON_LOG_INFO, "Using t.teleboy.ch."); tbUrl = "https://t.teleboy.ch"; HttpGet(curl, tbUrl + "/login"); } @@ -210,25 +278,25 @@ curl.ResetHeaders(); if (result.empty()) { - XBMC->Log(LOG_ERROR, "Failed to login."); + kodi::Log(ADDON_LOG_ERROR, "Failed to login."); return false; } } else { - XBMC->Log(LOG_INFO, "Already authenticated."); + kodi::Log(ADDON_LOG_INFO, "Already authenticated."); } - + size_t pos = result.find("tvapiKey:"); size_t pos1 = result.find("'", pos) + 1; if (pos == std::string::npos || pos1 > pos + 50) { - XBMC->Log(LOG_ERROR, "No api key found."); + kodi::Log(ADDON_LOG_ERROR, "No api key found."); return false; } size_t endPos = result.find("'", pos1); if (endPos - pos1 > 65 || endPos <= pos) { - XBMC->Log(LOG_DEBUG, "Got HTML body: %s", result.c_str()); - XBMC->Log(LOG_ERROR, "Received api key is invalid."); + kodi::Log(ADDON_LOG_DEBUG, "Got HTML body: %s", result.c_str()); + kodi::Log(ADDON_LOG_ERROR, "Received api key is invalid."); return false; } apiKey = result.substr(pos1, endPos - pos1); @@ -236,15 +304,15 @@ pos = result.find("setId("); if (pos == std::string::npos) { - XBMC->Log(LOG_ERROR, "No user settings found."); + kodi::Log(ADDON_LOG_ERROR, "No user settings found."); return false; } pos += 6; endPos = result.find(")", pos); if (endPos - pos > 15 || endPos <= pos) { - XBMC->Log(LOG_DEBUG, "Got HTML body: %s", result.c_str()); - XBMC->Log(LOG_ERROR, "Received userId is invalid."); + kodi::Log(ADDON_LOG_DEBUG, "Got HTML body: %s", result.c_str()); + kodi::Log(ADDON_LOG_ERROR, "Received userId is invalid."); return false; } userId = result.substr(pos, endPos - pos); @@ -253,26 +321,57 @@ isComfortMember = result.find("setIsComfortMember(1", endPos) != std::string::npos; if (!isPlusMember) { - XBMC->Log(LOG_NOTICE, "Free accounts are not supported.", userId.c_str()); - XBMC->QueueNotification(QUEUE_ERROR, XBMC->GetLocalizedString(30102)); + kodi::Log(ADDON_LOG_INFO, "Free accounts are not supported.", userId.c_str()); + kodi::QueueNotification(QUEUE_ERROR, "", kodi::GetLocalizedString(30102)); return false; } - XBMC->Log(LOG_DEBUG, "Got userId: %s.", userId.c_str()); - + kodi::Log(ADDON_LOG_DEBUG, "Got userId: %s.", userId.c_str()); + for (int i = 0; i < 3; ++i) { - updateThreads.emplace_back(new UpdateThread(i, this)); + updateThreads.emplace_back(new UpdateThread(i, *this)); } - + LoadChannels(); LoadGenres(); return true; } -void TeleBoy::GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities) +PVR_ERROR TeleBoy::GetCapabilities(kodi::addon::PVRCapabilities& capabilities) { - pCapabilities->bSupportsRecordings = true; - pCapabilities->bSupportsTimers = true; + capabilities.SetSupportsEPG(true); + capabilities.SetSupportsTV(true); + capabilities.SetSupportsRadio(false); + capabilities.SetSupportsChannelGroups(false); + capabilities.SetSupportsRecordingPlayCount(false); + capabilities.SetSupportsLastPlayedPosition(false); + capabilities.SetSupportsRecordingsRename(false); + capabilities.SetSupportsRecordingsLifetimeChange(false); + capabilities.SetSupportsDescrambleInfo(false); + capabilities.SetSupportsEPGEdl(true); + capabilities.SetSupportsRecordingEdl(true); + capabilities.SetSupportsRecordings(true); + capabilities.SetSupportsTimers(true); + + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::GetBackendName(std::string& name) +{ + name = "Teleboy PVR Add-on"; + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::GetBackendVersion(std::string& version) +{ + version = STR(TELEBOY_VERSION); + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::GetConnectionString(std::string& connection) +{ + connection = "connected"; + return PVR_ERROR_NO_ERROR; } void TeleBoy::LoadGenres() @@ -280,7 +379,7 @@ Document json; if (!ApiGet("/epg/genres", json, 3600)) { - XBMC->Log(LOG_ERROR, "Error loading genres."); + kodi::Log(ADDON_LOG_ERROR, "Error loading genres."); return; } Value& genres = json["data"]["items"]; @@ -293,7 +392,7 @@ teleboyGenre.name = GetStringOrEmpty(genre, "name"); teleboyGenre.nameEn = GetStringOrEmpty(genre, "name_en"); genresById[id] = teleboyGenre; - + if (genre.HasMember("sub_genres")) { const Value& subGenres = genre["sub_genres"]; @@ -316,7 +415,7 @@ Document json; if (!ApiGet("/epg/stations?expand=logos&language=de", json, 3600)) { - XBMC->Log(LOG_ERROR, "Error loading channels."); + kodi::Log(ADDON_LOG_ERROR, "Error loading channels."); return false; } Value& channels = json["data"]["items"]; @@ -338,7 +437,7 @@ if (!ApiGet("/users/" + userId + "/stations", json, 3600)) { - XBMC->Log(LOG_ERROR, "Error loading sorted channels."); + kodi::Log(ADDON_LOG_ERROR, "Error loading sorted channels."); return false; } channels = json["data"]["items"]; @@ -354,22 +453,26 @@ return true; } -int TeleBoy::GetChannelsAmount(void) +PVR_ERROR TeleBoy::GetChannelsAmount(int& amount) { if (favoritesOnly) { - return sortedChannels.size(); + amount = sortedChannels.size(); + } + else + { + amount = channelsById.size(); } - return channelsById.size(); + return PVR_ERROR_NO_ERROR; } -PVR_ERROR TeleBoy::GetChannels(ADDON_HANDLE handle, bool bRadio) +PVR_ERROR TeleBoy::GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& results) { int channelNum = 0; for (int const &cid : sortedChannels) { channelNum++; - TransferChannel(handle, channelsById[cid], channelNum); + TransferChannel(results, channelsById[cid], channelNum); } if (!favoritesOnly) { @@ -381,41 +484,59 @@ continue; } channelNum++; - TransferChannel(handle, item.second, channelNum); + TransferChannel(results, item.second, channelNum); } } return PVR_ERROR_NO_ERROR; } -void TeleBoy::TransferChannel(ADDON_HANDLE handle, TeleBoyChannel channel, +void TeleBoy::TransferChannel(kodi::addon::PVRChannelsResultSet& results, TeleBoyChannel channel, int channelNum) { - PVR_CHANNEL kodiChannel; - memset(&kodiChannel, 0, sizeof(PVR_CHANNEL)); + kodi::addon::PVRChannel kodiChannel; + + kodiChannel.SetUniqueId(channel.id); + kodiChannel.SetIsRadio(false); + kodiChannel.SetChannelNumber(channelNum); + kodiChannel.SetChannelName(channel.name); + kodiChannel.SetIconPath(channel.logoPath); - kodiChannel.iUniqueId = channel.id; - kodiChannel.bIsRadio = false; - kodiChannel.iChannelNumber = channelNum; - PVR_STRCPY(kodiChannel.strChannelName, channel.name.c_str()); - PVR_STRCPY(kodiChannel.strIconPath, channel.logoPath.c_str()); - PVR->TransferChannelEntry(handle, &kodiChannel); + results.Add(kodiChannel); } -string TeleBoy::GetChannelStreamUrl(int uniqueId) +void TeleBoy::SetStreamProperties(std::vector& properties, const std::string& url, bool realtime) { + properties.emplace_back(PVR_STREAM_PROPERTY_STREAMURL, url); + properties.emplace_back(PVR_STREAM_PROPERTY_INPUTSTREAM, "inputstream.adaptive"); + properties.emplace_back("inputstream.adaptive.manifest_type", "mpd"); + properties.emplace_back("inputstream.adaptive.manifest_update_parameter", "full"); + properties.emplace_back(PVR_STREAM_PROPERTY_MIMETYPE, "application/xml+dash"); + properties.emplace_back(PVR_STREAM_PROPERTY_ISREALTIMESTREAM, realtime ? "true" : "false"); +} + +PVR_ERROR TeleBoy::GetChannelStreamProperties(const kodi::addon::PVRChannel& channel, std::vector& properties) +{ + PVR_ERROR ret = PVR_ERROR_FAILED; + Document json; if (!ApiGet( - "/users/" + userId + "/stream/live/" + to_string(uniqueId) + "/users/" + userId + "/stream/live/" + to_string(channel.GetUniqueId()) + "?expand=primary_image,flags&https=1" + GetStreamParameters(), json, 0)) { - XBMC->Log(LOG_ERROR, "Error getting live stream url for channel %i.", - uniqueId); - return ""; + kodi::Log(ADDON_LOG_ERROR, "Error getting live stream url for channel %i.", + channel.GetUniqueId()); + return ret; } string url = GetStringOrEmpty(json["data"]["stream"], "url"); - XBMC->Log(LOG_INFO, "Play URL: %s.", url.c_str()); + kodi::Log(ADDON_LOG_INFO, "Play URL: %s.", url.c_str()); url = FollowRedirect(url); - return url; + + if (!url.empty()) + { + SetStreamProperties(properties, url, true); + ret = PVR_ERROR_NO_ERROR; + } + return ret; } string TeleBoy::FollowRedirect(string url) @@ -430,19 +551,19 @@ string nextUrl = curl.GetLocation(); if (nextUrl.empty()) { - XBMC->Log(LOG_DEBUG, "Final url : %s.", currUrl.c_str()); + kodi::Log(ADDON_LOG_DEBUG, "Final url : %s.", currUrl.c_str()); return currUrl; } - XBMC->Log(LOG_DEBUG, "Redirected to : %s.", nextUrl.c_str()); + kodi::Log(ADDON_LOG_DEBUG, "Redirected to : %s.", nextUrl.c_str()); currUrl = nextUrl; } return currUrl; } -void TeleBoy::GetEPGForChannel(const PVR_CHANNEL &channel, time_t iStart, - time_t iEnd) +PVR_ERROR TeleBoy::GetEPGForChannel(int channelUid, time_t start, time_t end, kodi::addon::PVREPGTagsResultSet& results) { - UpdateThread::LoadEpg(channel.iUniqueId, iStart, iEnd); + UpdateThread::LoadEpg(channelUid, start, end); + return PVR_ERROR_NO_ERROR; } void TeleBoy::GetEPGForChannelAsync(int uniqueChannelId, time_t iStart, @@ -459,67 +580,62 @@ + to_string(sum) + "&sort=station&station=" + to_string(uniqueChannelId), json, 60*60*24)) { - XBMC->Log(LOG_ERROR, "Error getting epg for channel %i.", + kodi::Log(ADDON_LOG_ERROR, "Error getting epg for channel %i.", uniqueChannelId); return; } totals = json["data"]["total"].GetInt(); const Value& items = json["data"]["items"]; - - if (!sendEpgToKodiMutex.Lock()) { - XBMC->Log(LOG_ERROR, "Failed to lock sendEpgToKodiMutex."); - return; - } - + + std::lock_guard lock(sendEpgToKodiMutex); + for (Value::ConstValueIterator itr1 = items.Begin(); itr1 != items.End(); ++itr1) { const Value& item = (*itr1); sum++; - EPG_TAG tag; - memset(&tag, 0, sizeof(EPG_TAG)); - tag.iUniqueBroadcastId = item["id"].GetInt(); - tag.strTitle = strdup(GetStringOrEmpty(item, "title").c_str()); - tag.iUniqueChannelId = uniqueChannelId; - tag.startTime = Utils::StringToTime(GetStringOrEmpty(item, "begin")); - tag.endTime = Utils::StringToTime(GetStringOrEmpty(item, "end")); - tag.strPlotOutline = strdup(GetStringOrEmpty(item, "headline").c_str()); - tag.strPlot = strdup(GetStringOrEmpty(item, "short_description").c_str()); - tag.strOriginalTitle = strdup(GetStringOrEmpty(item, "original_title").c_str()); - tag.strCast = nullptr; /* not supported */ - tag.strDirector = nullptr; /*SA not supported */ - tag.strWriter = nullptr; /* not supported */ - tag.iYear = item.HasMember("year") ? item["year"].GetInt() : 0; - tag.strIMDBNumber = nullptr; /* not supported */ - tag.strIconPath = nullptr; /* not supported */ - tag.iParentalRating = 0; /* not supported */ - tag.iStarRating = 0; /* not supported */ - tag.bNotify = false; /* not supported */ - tag.iSeriesNumber = - item.HasMember("serie_season") ? item["serie_season"].GetInt() : 0; - tag.iEpisodeNumber = - item.HasMember("serie_episode") ? item["serie_episode"].GetInt() : 0; - tag.iEpisodePartNumber = 0; /* not supported */ - tag.strEpisodeName = strdup(GetStringOrEmpty(item, "subtitle").c_str()); + kodi::addon::PVREPGTag tag; + + tag.SetUniqueBroadcastId(item["id"].GetInt()); + tag.SetTitle(GetStringOrEmpty(item, "title")); + tag.SetUniqueChannelId(uniqueChannelId); + tag.SetStartTime(Utils::StringToTime(GetStringOrEmpty(item, "begin"))); + tag.SetEndTime(Utils::StringToTime(GetStringOrEmpty(item, "end"))); + tag.SetPlotOutline(GetStringOrEmpty(item, "headline")); + tag.SetPlot(GetStringOrEmpty(item, "short_description")); + tag.SetOriginalTitle(GetStringOrEmpty(item, "original_title")); + tag.SetCast(""); /* not supported */ + tag.SetDirector(""); /*SA not supported */ + tag.SetWriter(""); /* not supported */ + tag.SetYear(item.HasMember("year") ? item["year"].GetInt() : 0); + tag.SetIMDBNumber(""); /* not supported */ + tag.SetIconPath(""); /* not supported */ + tag.SetParentalRating(0); /* not supported */ + tag.SetStarRating(0); /* not supported */ + tag.SetSeriesNumber( + item.HasMember("serie_season") ? item["serie_season"].GetInt() : EPG_TAG_INVALID_SERIES_EPISODE); + tag.SetEpisodeNumber( + item.HasMember("serie_episode") ? item["serie_episode"].GetInt() : EPG_TAG_INVALID_SERIES_EPISODE); + tag.SetEpisodePartNumber(EPG_TAG_INVALID_SERIES_EPISODE); /* not supported */ + tag.SetEpisodeName(GetStringOrEmpty(item, "subtitle")); if (item.HasMember("genre_id")) { int genreId = item["genre_id"].GetInt(); TeleboyGenre genre = genresById[genreId]; int kodiGenre = m_categories.Category(genre.nameEn); if (kodiGenre == 0) { - tag.iGenreType = EPG_GENRE_USE_STRING; - tag.iGenreSubType = 0; - tag.strGenreDescription = genre.name.c_str(); + tag.SetGenreType(EPG_GENRE_USE_STRING); + tag.SetGenreSubType(0); + tag.SetGenreDescription(genre.name); } else { - tag.iGenreSubType = kodiGenre & 0x0F; - tag.iGenreType = kodiGenre & 0xF0; + tag.SetGenreSubType(kodiGenre & 0x0F); + tag.SetGenreType(kodiGenre & 0xF0); } } - tag.iFlags = EPG_TAG_FLAG_UNDEFINED; + tag.SetFlags(EPG_TAG_FLAG_UNDEFINED); - PVR->EpgEventStateChange(&tag, EPG_EVENT_CREATED); + EpgEventStateChange(tag, EPG_EVENT_CREATED); } - sendEpgToKodiMutex.Unlock(); - XBMC->Log(LOG_DEBUG, "Loaded %i of %i epg entries for channel %i.", sum, + kodi::Log(ADDON_LOG_DEBUG, "Loaded %i of %i epg entries for channel %i.", sum, totals, uniqueChannelId); } return; @@ -534,34 +650,28 @@ return buff; } -bool TeleBoy::Record(int programId) +PVR_ERROR TeleBoy::GetRecordingsAmount(bool deleted, int& amount) { - string postData = "{\"broadcast\": " + to_string(programId) - + ", \"alternative\": false}"; - Document json; - if (!ApiPost("/users/" + userId + "/recordings", postData, json)) - { - XBMC->Log(LOG_ERROR, "Error recording program %i.", programId); - return false; - } - return true; + amount = 0; + return PVR_ERROR_NOT_IMPLEMENTED; } -bool TeleBoy::DeleteRecording(string recordingId) +PVR_ERROR TeleBoy::DeleteRecording(const kodi::addon::PVRRecording& recording) { Document doc; - if (!ApiDelete("/users/" + userId + "/recordings/" + recordingId, doc)) + if (!ApiDelete("/users/" + userId + "/recordings/" + recording.GetRecordingId(), doc)) { - XBMC->Log(LOG_ERROR, "Error deleting recording %s.", recordingId.c_str()); - return false; + kodi::Log(ADDON_LOG_ERROR, "Error deleting recording %s.", recording.GetRecordingId().c_str()); + return PVR_ERROR_SERVER_ERROR; } - return true; + return PVR_ERROR_NO_ERROR; } -void TeleBoy::GetRecordings(ADDON_HANDLE handle, string type) +PVR_ERROR TeleBoy::GetRecordings(bool deleted, kodi::addon::PVRRecordingsResultSet& results) { int totals = -1; int sum = 0; + string type = "ready"; while (totals == -1 || sum < totals) { Document json; @@ -569,9 +679,9 @@ "/users/" + userId + "/recordings/" + type + "?desc=1&expand=flags,logos&limit=100&skip=" + to_string(sum) + "&sort=date", json, 10)) { - XBMC->Log(LOG_ERROR, "Error getting recordings of type %s.", + kodi::Log(ADDON_LOG_ERROR, "Error getting recordings of type %s.", type.c_str()); - return; + return PVR_ERROR_SERVER_ERROR; } totals = json["data"]["total"].GetInt(); const Value& items = json["data"]["items"]; @@ -581,117 +691,237 @@ const Value& item = (*itr1); sum++; - if (type.find("planned") == 0) - { - PVR_TIMER tag; - memset(&tag, 0, sizeof(PVR_TIMER)); + kodi::addon::PVRRecording tag; - tag.iClientIndex = item["id"].GetInt(); - PVR_STRCPY(tag.strTitle, GetStringOrEmpty(item, "title").c_str()); - PVR_STRCPY(tag.strSummary, GetStringOrEmpty(item, "subtitle").c_str()); - tag.startTime = Utils::StringToTime(GetStringOrEmpty(item, "begin")); - tag.endTime = Utils::StringToTime(GetStringOrEmpty(item, "end")); - tag.state = PVR_TIMER_STATE_SCHEDULED; - tag.iTimerType = 1; - tag.iEpgUid = item["id"].GetInt(); - tag.iClientChannelUid = item["station_id"].GetInt(); - if (item.HasMember("genre_id")) { - int genreId = item["genre_id"].GetInt(); - TeleboyGenre genre = genresById[genreId]; - int kodiGenre = m_categories.Category(genre.nameEn); - if (kodiGenre != 0) { - tag.iGenreSubType = kodiGenre & 0x0F; - tag.iGenreType = kodiGenre & 0xF0; - } + tag.SetSeriesNumber(PVR_RECORDING_INVALID_SERIES_EPISODE); + tag.SetEpisodeNumber(PVR_RECORDING_INVALID_SERIES_EPISODE); + tag.SetIsDeleted(false); + tag.SetRecordingId(to_string(item["id"].GetInt())); + tag.SetTitle(GetStringOrEmpty(item, "title")); + tag.SetEpisodeName(GetStringOrEmpty(item, "subtitle")); + tag.SetPlot(GetStringOrEmpty(item, "description")); + tag.SetPlotOutline(GetStringOrEmpty(item, "short_description")); + tag.SetChannelUid(item["station_id"].GetInt()); + tag.SetIconPath(channelsById[tag.GetChannelUid()].logoPath); + tag.SetChannelName(channelsById[tag.GetChannelUid()].name); + tag.SetRecordingTime(Utils::StringToTime(GetStringOrEmpty(item, "begin"))); + time_t endTime = Utils::StringToTime(GetStringOrEmpty(item, "end")); + tag.SetDuration(endTime - tag.GetRecordingTime()); + tag.SetEPGEventId(item["id"].GetInt()); + if (item.HasMember("genre_id")) { + int genreId = item["genre_id"].GetInt(); + TeleboyGenre genre = genresById[genreId]; + int kodiGenre = m_categories.Category(genre.nameEn); + if (kodiGenre == 0) { + tag.SetGenreType(EPG_GENRE_USE_STRING); + tag.SetGenreSubType(0); + tag.SetGenreDescription(genre.name); + } else { + tag.SetGenreSubType(kodiGenre & 0x0F); + tag.SetGenreType(kodiGenre & 0xF0); } - - PVR->TransferTimerEntry(handle, &tag); - UpdateThread::SetNextRecordingUpdate(tag.endTime + 60 * 21); - } - else - { - PVR_RECORDING tag; - memset(&tag, 0, sizeof(PVR_RECORDING)); - tag.bIsDeleted = false; - PVR_STRCPY(tag.strRecordingId, to_string(item["id"].GetInt()).c_str()); - PVR_STRCPY(tag.strTitle, GetStringOrEmpty(item, "title").c_str()); - PVR_STRCPY(tag.strEpisodeName, GetStringOrEmpty(item, "subtitle").c_str()); - PVR_STRCPY(tag.strPlot, GetStringOrEmpty(item, "description").c_str()); - PVR_STRCPY(tag.strPlotOutline, GetStringOrEmpty(item, "short_description").c_str()); - tag.iChannelUid = item["station_id"].GetInt(); - PVR_STRCPY(tag.strIconPath, channelsById[tag.iChannelUid].logoPath.c_str()); - PVR_STRCPY(tag.strChannelName, channelsById[tag.iChannelUid].name.c_str()); - tag.recordingTime = Utils::StringToTime(GetStringOrEmpty(item, "begin")); - time_t endTime = Utils::StringToTime(GetStringOrEmpty(item, "end")); - tag.iDuration = endTime - tag.recordingTime; - tag.iEpgEventId = item["id"].GetInt(); - if (item.HasMember("genre_id")) { - int genreId = item["genre_id"].GetInt(); - TeleboyGenre genre = genresById[genreId]; - int kodiGenre = m_categories.Category(genre.nameEn); - if (kodiGenre == 0) { - tag.iGenreType = EPG_GENRE_USE_STRING; - tag.iGenreSubType = 0; - PVR_STRCPY(tag.strGenreDescription, genre.name.c_str()); - } else { - tag.iGenreSubType = kodiGenre & 0x0F; - tag.iGenreType = kodiGenre & 0xF0; - } - } - PVR->TransferRecordingEntry(handle, &tag); - } + results.Add(tag); } } + return PVR_ERROR_NO_ERROR; } -string TeleBoy::GetRecordingStreamUrl(string recordingId) +PVR_ERROR TeleBoy::GetRecordingStreamProperties(const kodi::addon::PVRRecording& recording, std::vector& properties) { + PVR_ERROR ret = PVR_ERROR_FAILED; + Document json; - if (!ApiGet("/users/" + userId + "/stream/" + recordingId + "?" + GetStreamParameters(), json, 0)) + if (!ApiGet("/users/" + userId + "/stream/" + recording.GetRecordingId() + "?" + GetStreamParameters(), json, 0)) { - XBMC->Log(LOG_ERROR, "Could not get URL for recording: %s.", - recordingId.c_str()); - return ""; + kodi::Log(ADDON_LOG_ERROR, "Could not get URL for recording: %s.", + recording.GetRecordingId().c_str()); + return ret; } string url = GetStringOrEmpty(json["data"]["stream"], "url"); url = FollowRedirect(url); - return url; + + if (!url.empty()) + { + SetStreamProperties(properties, url, false); + ret = PVR_ERROR_NO_ERROR; + } + return ret; +} + +PVR_ERROR TeleBoy::GetRecordingEdl(const kodi::addon::PVRRecording& recording, std::vector& edl) +{ + kodi::addon::PVREDLEntry entry; + entry.SetStart(0); + entry.SetEnd(300000); + entry.SetType(PVR_EDL_TYPE_COMBREAK); + edl.emplace_back(entry); + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::GetTimerTypes(std::vector& types) +{ + AddTimerType(types, 0, PVR_TIMER_TYPE_ATTRIBUTE_NONE); + AddTimerType(types, 1, PVR_TIMER_TYPE_IS_MANUAL); + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::GetTimersAmount(int& amount) +{ + amount = 0; + return PVR_ERROR_NOT_IMPLEMENTED; +} + +PVR_ERROR TeleBoy::GetTimers(kodi::addon::PVRTimersResultSet& results) +{ + int totals = -1; + int sum = 0; + string type = "planned"; + while (totals == -1 || sum < totals) + { + Document json; + if (!ApiGet( + "/users/" + userId + "/recordings/" + type + + "?desc=1&expand=flags,logos&limit=100&skip=" + to_string(sum) + "&sort=date", json, 10)) + { + kodi::Log(ADDON_LOG_ERROR, "Error getting recordings of type %s.", + type.c_str()); + return PVR_ERROR_SERVER_ERROR; + } + totals = json["data"]["total"].GetInt(); + const Value& items = json["data"]["items"]; + for (Value::ConstValueIterator itr1 = items.Begin(); itr1 != items.End(); + ++itr1) + { + const Value& item = (*itr1); + sum++; + + kodi::addon::PVRTimer tag; + + tag.SetClientIndex(item["id"].GetInt()); + tag.SetTitle(GetStringOrEmpty(item, "title")); + tag.SetSummary(GetStringOrEmpty(item, "subtitle")); + tag.SetStartTime(Utils::StringToTime(GetStringOrEmpty(item, "begin"))); + tag.SetEndTime(Utils::StringToTime(GetStringOrEmpty(item, "end"))); + tag.SetState(PVR_TIMER_STATE_SCHEDULED); + tag.SetTimerType(1); + tag.SetEPGUid(item["id"].GetInt()); + tag.SetClientChannelUid(item["station_id"].GetInt()); + if (item.HasMember("genre_id")) { + int genreId = item["genre_id"].GetInt(); + TeleboyGenre genre = genresById[genreId]; + int kodiGenre = m_categories.Category(genre.nameEn); + if (kodiGenre != 0) { + tag.SetGenreSubType(kodiGenre & 0x0F); + tag.SetGenreType(kodiGenre & 0xF0); + } + } + + results.Add(tag); + UpdateThread::SetNextRecordingUpdate(tag.GetEndTime() + 60 * 21); + } + } + + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::AddTimer(const kodi::addon::PVRTimer& timer) +{ + if (timer.GetEPGUid() <= EPG_TAG_INVALID_UID) + { + return PVR_ERROR_REJECTED; + } + + string postData = "{\"broadcast\": " + to_string(timer.GetEPGUid()) + + ", \"alternative\": false}"; + Document json; + if (!ApiPost("/users/" + userId + "/recordings", postData, json)) + { + kodi::Log(ADDON_LOG_ERROR, "Error recording program %i.", timer.GetEPGUid()); + return PVR_ERROR_SERVER_ERROR; + } + + kodi::addon::CInstancePVRClient::TriggerTimerUpdate(); + kodi::addon::CInstancePVRClient::TriggerRecordingUpdate(); + return PVR_ERROR_NO_ERROR; +} + +PVR_ERROR TeleBoy::DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceDelete) +{ + Document doc; + if (!ApiDelete("/users/" + userId + "/recordings/" + to_string(timer.GetClientIndex()), doc)) + { + kodi::Log(ADDON_LOG_ERROR, "Error deleting timer %i.", timer.GetClientIndex()); + return PVR_ERROR_SERVER_ERROR; + } + + kodi::addon::CInstancePVRClient::TriggerTimerUpdate(); + kodi::addon::CInstancePVRClient::TriggerRecordingUpdate(); + return PVR_ERROR_NO_ERROR; +} + +void TeleBoy::AddTimerType(std::vector& types, int idx, int attributes) +{ + kodi::addon::PVRTimerType type; + type.SetId(static_cast(idx + 1)); + type.SetAttributes(static_cast(attributes)); + types.emplace_back(type); } -bool TeleBoy::IsPlayable(const EPG_TAG *tag) +PVR_ERROR TeleBoy::IsEPGTagPlayable(const kodi::addon::PVREPGTag& tag, bool& isPlayable) { if (!isComfortMember && !isPlusMember) { - return false; + isPlayable = false; + return PVR_ERROR_NO_ERROR; } + time_t current_time; time(¤t_time); - return ((current_time - tag->endTime) < maxRecallSeconds) - && (tag->startTime < current_time); + isPlayable = ((current_time - tag.GetEndTime()) < maxRecallSeconds) + && (tag.GetStartTime() < current_time); + return PVR_ERROR_NO_ERROR; } -bool TeleBoy::IsRecordable(const EPG_TAG *tag) +PVR_ERROR TeleBoy::IsEPGTagRecordable(const kodi::addon::PVREPGTag& tag, bool& isRecordable) { time_t current_time; time(¤t_time); - return ((current_time - tag->endTime) < maxRecallSeconds); + isRecordable = ((current_time - tag.GetEndTime()) < maxRecallSeconds); + return PVR_ERROR_NO_ERROR; } -string TeleBoy::GetEpgTagUrl(const EPG_TAG *tag) +PVR_ERROR TeleBoy::GetEPGTagStreamProperties(const kodi::addon::PVREPGTag& tag, std::vector& properties) { + PVR_ERROR ret = PVR_ERROR_FAILED; + Document json; if (!ApiGet( - "/users/" + userId + "/stream/"+ to_string(tag->iUniqueBroadcastId) + "?" + GetStreamParameters() + "/users/" + userId + "/stream/"+ to_string(tag.GetUniqueBroadcastId()) + "?" + GetStreamParameters() , json, 0)) { - XBMC->Log(LOG_ERROR, "Could not get URL for epg tag."); - return ""; + kodi::Log(ADDON_LOG_ERROR, "Could not get URL for epg tag."); + return ret; } string url = GetStringOrEmpty(json["data"]["stream"], "url"); url = FollowRedirect(url); - return url; + if (!url.empty()) + { + SetStreamProperties(properties, url, false); + ret = PVR_ERROR_NO_ERROR; + } + return ret; +} + +PVR_ERROR TeleBoy::GetEPGTagEdl(const kodi::addon::PVREPGTag& tag, std::vector& edl) +{ + kodi::addon::PVREDLEntry entry; + entry.SetStart(0); + entry.SetEnd(300000); + entry.SetType(PVR_EDL_TYPE_COMBREAK); + edl.emplace_back(entry); + return PVR_ERROR_NO_ERROR; } string TeleBoy::GetStringOrEmpty(const Value& jsonValue, const char* fieldName) @@ -705,14 +935,14 @@ bool TeleBoy::ReadDataJson() { - if (!XBMC->FileExists(data_file, true)) + if (!kodi::vfs::FileExists(data_file, true)) { return true; } std::string jsonString = Utils::ReadFile(data_file); if (jsonString.empty()) { - XBMC->Log(LOG_ERROR, "Loading data.json failed."); + kodi::Log(ADDON_LOG_ERROR, "Loading data.json failed."); return false; } @@ -720,33 +950,33 @@ doc.Parse(jsonString.c_str()); if (doc.GetParseError()) { - XBMC->Log(LOG_ERROR, "Parsing data.json failed."); + kodi::Log(ADDON_LOG_ERROR, "Parsing data.json failed."); return false; } if (doc.HasMember("cinergy_s")) { cinergySCookies = GetStringOrEmpty(doc, "cinergy_s"); - XBMC->Log(LOG_DEBUG, "Loaded cinergy_s: %s..", cinergySCookies.substr(0, 5).c_str()); + kodi::Log(ADDON_LOG_DEBUG, "Loaded cinergy_s: %s..", cinergySCookies.substr(0, 5).c_str()); } - XBMC->Log(LOG_DEBUG, "Loaded data.json."); + kodi::Log(ADDON_LOG_DEBUG, "Loaded data.json."); return true; } bool TeleBoy::WriteDataJson() { - void* file; - if (!(file = XBMC->OpenFileForWrite(data_file, true))) + kodi::vfs::CFile file; + if (!file.OpenFileForWrite(data_file, true)) { - XBMC->Log(LOG_ERROR, "Save data.json failed."); + kodi::Log(ADDON_LOG_ERROR, "Save data.json failed."); return false; } Document d; d.SetObject(); Document::AllocatorType& allocator = d.GetAllocator(); - + if (!cinergySCookies.empty()) { Value cinergySValue; @@ -758,8 +988,7 @@ Writer writer(buffer); d.Accept(writer); const char* output = buffer.GetString(); - XBMC->WriteFile(file, output, strlen(output)); - XBMC->CloseFile(file); + file.Write(output, strlen(output)); return true; } @@ -768,3 +997,5 @@ params += "&https=1&streamformat=dash"; return params; } + +ADDONCREATOR(TeleBoy) diff -Nru kodi-pvr-teleboy-18.2.3/src/TeleBoy.h kodi-pvr-teleboy-19.8.0/src/TeleBoy.h --- kodi-pvr-teleboy-18.2.3/src/TeleBoy.h 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/TeleBoy.h 2021-01-09 11:27:13.000000000 +0000 @@ -1,4 +1,3 @@ -#include "client.h" #include "UpdateThread.h" #include "Curl.h" #include "categories.h" @@ -6,15 +5,11 @@ #include #include "rapidjson/document.h" +#include "kodi/addon-instance/PVR.h" + using namespace std; using namespace rapidjson; -/*! - * @brief PVR macros for string exchange - */ -#define PVR_STRCPY(dest, source) do { strncpy(dest, source, sizeof(dest)-1); dest[sizeof(dest)-1] = '\0'; } while(0) -#define PVR_STRCLR(dest) memset(dest, 0, sizeof(dest)) - struct TeleBoyChannel { int id; @@ -28,39 +23,58 @@ std::string nameEn; }; -class TeleBoy +class ATTRIBUTE_HIDDEN TeleBoy : public kodi::addon::CAddonBase, + public kodi::addon::CInstancePVRClient { public: - TeleBoy(bool favoritesOnly, bool enableDolby); - virtual ~TeleBoy(); - virtual bool Login(string u, string p); - virtual void GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities); - virtual int GetChannelsAmount(void); - virtual PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio); - virtual void TransferChannel(ADDON_HANDLE handle, TeleBoyChannel channel, - int channelNum); - virtual std::string GetChannelStreamUrl(int uniqueId); - virtual void GetEPGForChannel(const PVR_CHANNEL &channel, time_t iStart, - time_t iEnd); + TeleBoy(); + ~TeleBoy() override; + + ADDON_STATUS Create() override; + ADDON_STATUS SetSetting(const std::string& settingName, + const kodi::CSettingValue& settingValue) override; + + PVR_ERROR GetCapabilities(kodi::addon::PVRCapabilities& capabilities) override; + PVR_ERROR GetBackendName(std::string& name) override; + PVR_ERROR GetBackendVersion(std::string& version) override; + PVR_ERROR GetConnectionString(std::string& connection) override; + + PVR_ERROR GetChannelsAmount(int& amount) override; + PVR_ERROR GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& results) override; + PVR_ERROR GetChannelStreamProperties(const kodi::addon::PVRChannel& channel, + std::vector& properties) override; + PVR_ERROR GetEPGForChannel(int channelUid, time_t start, time_t end, + kodi::addon::PVREPGTagsResultSet& results) override; void GetEPGForChannelAsync(int uniqueChannelId, time_t iStart, time_t iEnd); - virtual void GetRecordings(ADDON_HANDLE handle, string type); - virtual string GetRecordingStreamUrl(string recordingId); - virtual bool Record(int programId); - virtual bool DeleteRecording(string recordingId); - virtual bool IsPlayable(const EPG_TAG *tag); - virtual bool IsRecordable(const EPG_TAG *tag); - virtual string GetEpgTagUrl(const EPG_TAG *tag); + PVR_ERROR GetRecordingsAmount(bool deleted, int& amount) override; + PVR_ERROR GetRecordings(bool deleted, kodi::addon::PVRRecordingsResultSet& results) override; + PVR_ERROR GetRecordingStreamProperties(const kodi::addon::PVRRecording& recording, + std::vector& properties) override; + PVR_ERROR DeleteRecording(const kodi::addon::PVRRecording& recording) override; + PVR_ERROR GetRecordingEdl(const kodi::addon::PVRRecording& recording, + std::vector& edl) override; + PVR_ERROR GetTimerTypes(std::vector& types) override; + PVR_ERROR GetTimersAmount(int& amount) override; + PVR_ERROR GetTimers(kodi::addon::PVRTimersResultSet& results) override; + PVR_ERROR AddTimer(const kodi::addon::PVRTimer& timer) override; + PVR_ERROR DeleteTimer(const kodi::addon::PVRTimer& timer, bool forceDelete) override; + PVR_ERROR IsEPGTagPlayable(const kodi::addon::PVREPGTag& tag, bool& isPlayable) override; + PVR_ERROR IsEPGTagRecordable(const kodi::addon::PVREPGTag& tag, bool& isRecordable) override; + PVR_ERROR GetEPGTagStreamProperties(const kodi::addon::PVREPGTag& tag, + std::vector& properties) override; + PVR_ERROR GetEPGTagEdl(const kodi::addon::PVREPGTag& tag, + std::vector& edl) override; private: - string username; - string password; + string teleboyUsername; + string teleboyPassword; bool favoritesOnly; bool enableDolby; string userId; string apiKey; map channelsById; map genresById; - static P8PLATFORM::CMutex sendEpgToKodiMutex; + static std::mutex sendEpgToKodiMutex; vector sortedChannels; int64_t maxRecallSeconds; vector updateThreads; @@ -69,6 +83,7 @@ bool isComfortMember; Categories m_categories; + virtual bool Login(string u, string p); virtual string FormatDate(time_t dateTime); virtual string HttpGetCached(Curl &curl, const std::string& url, time_t cacheDuration); virtual string HttpGet(Curl &curl, string url); @@ -83,9 +98,14 @@ string postData); virtual string FollowRedirect(string url); virtual string GetStringOrEmpty(const Value& jsonValue, const char* fieldName); + void TransferChannel(kodi::addon::PVRChannelsResultSet& results, TeleBoyChannel channel, + int channelNum); bool WriteDataJson(); bool ReadDataJson(); std::string GetStreamParameters(); void LoadGenres(); bool LoadChannels(); + void SetStreamProperties(std::vector& properties, + const std::string& url, bool realtime); + void AddTimerType(std::vector& types, int idx, int attributes); }; diff -Nru kodi-pvr-teleboy-18.2.3/src/UpdateThread.cpp kodi-pvr-teleboy-19.8.0/src/UpdateThread.cpp --- kodi-pvr-teleboy-18.2.3/src/UpdateThread.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/UpdateThread.cpp 2021-01-09 11:27:13.000000000 +0000 @@ -1,47 +1,45 @@ #include "UpdateThread.h" #include -#include "client.h" #include "TeleBoy.h" #include "Cache.h" -using namespace ADDON; +#include "kodi/General.h" + +#include const time_t maximumUpdateInterval = 600; std::queue UpdateThread::loadEpgQueue; time_t UpdateThread::nextRecordingsUpdate; -P8PLATFORM::CMutex UpdateThread::mutex; +std::mutex UpdateThread::mutex; -UpdateThread::UpdateThread(int threadIdx, void *teleboy) : - CThread(), +UpdateThread::UpdateThread(int threadIdx, TeleBoy& teleboy) : + m_teleboy(teleboy), m_threadIdx(threadIdx) { - this->teleboy = teleboy; time(&UpdateThread::nextRecordingsUpdate); UpdateThread::nextRecordingsUpdate += maximumUpdateInterval; - CreateThread(false); + + m_running = true; + m_thread = std::thread([&] { Process(); }); } UpdateThread::~UpdateThread() { - + m_running = false; + if (m_thread.joinable()) + m_thread.join(); } void UpdateThread::SetNextRecordingUpdate(time_t nextRecordingsUpdate) { if (nextRecordingsUpdate < UpdateThread::nextRecordingsUpdate) { - if (!mutex.Lock()) - { - XBMC->Log(LOG_ERROR, - "UpdateThread::SetNextRecordingUpdate : Could not lock mutex."); - return; - } + std::lock_guard lock(mutex); if (nextRecordingsUpdate < UpdateThread::nextRecordingsUpdate) { UpdateThread::nextRecordingsUpdate = nextRecordingsUpdate; } - mutex.Unlock(); } } @@ -52,80 +50,57 @@ entry.uniqueChannelId = uniqueChannelId; entry.startTime = startTime; entry.endTime = endTime; - if (!mutex.Lock()) - { - XBMC->Log(LOG_ERROR, "UpdateThread::LoadEpg : Could not lock mutex."); - return; - } + + std::lock_guard lock(mutex); loadEpgQueue.push(entry); - mutex.Unlock(); } -void* UpdateThread::Process() +void UpdateThread::Process() { - XBMC->Log(LOG_DEBUG, "Update thread started."); - while (!IsStopped()) + kodi::Log(ADDON_LOG_DEBUG, "Update thread started."); + while (m_running) { - Sleep(100); - if (IsStopped()) + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + if (!m_running) { continue; } - + if (m_threadIdx == 0) { Cache::Cleanup(); } while (!loadEpgQueue.empty()) { - if (!mutex.Lock()) - { - XBMC->Log(LOG_ERROR, - "UpdateThread::Process : Could not lock mutex for epg queue"); - break; - } + std::unique_lock lock(mutex); if (!loadEpgQueue.empty()) { EpgQueueEntry entry = loadEpgQueue.front(); loadEpgQueue.pop(); - mutex.Unlock(); - ((TeleBoy*) teleboy)->GetEPGForChannelAsync(entry.uniqueChannelId, + lock.unlock(); + m_teleboy.GetEPGForChannelAsync(entry.uniqueChannelId, entry.startTime, entry.endTime); } - else - { - mutex.Unlock(); - } } - + time_t currentTime; time(¤tTime); if (currentTime >= UpdateThread::nextRecordingsUpdate) { - if (!mutex.Lock()) - { - XBMC->Log(LOG_ERROR, - "UpdateThread::Process : Could not lock mutex for recordings update"); - continue; - } + std::unique_lock lock(mutex); if (currentTime >= UpdateThread::nextRecordingsUpdate) { UpdateThread::nextRecordingsUpdate = currentTime + maximumUpdateInterval; - mutex.Unlock(); - PVR->TriggerTimerUpdate(); - PVR->TriggerRecordingUpdate(); - XBMC->Log(LOG_DEBUG, "Update thread triggered update."); - } - else - { - mutex.Unlock(); + lock.unlock(); + m_teleboy.TriggerTimerUpdate(); + m_teleboy.TriggerRecordingUpdate(); + kodi::Log(ADDON_LOG_DEBUG, "Update thread triggered update."); } } } - XBMC->Log(LOG_DEBUG, "Update thread stopped."); - return nullptr; + kodi::Log(ADDON_LOG_DEBUG, "Update thread stopped."); } diff -Nru kodi-pvr-teleboy-18.2.3/src/UpdateThread.h kodi-pvr-teleboy-19.8.0/src/UpdateThread.h --- kodi-pvr-teleboy-18.2.3/src/UpdateThread.h 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/UpdateThread.h 2021-01-09 11:27:13.000000000 +0000 @@ -1,9 +1,11 @@ #pragma once -#include -#include -#include "kodi/libXBMC_pvr.h" +#include +#include #include +#include + +class TeleBoy; struct EpgQueueEntry { @@ -12,19 +14,21 @@ time_t endTime; }; -class UpdateThread: public P8PLATFORM::CThread +class UpdateThread { public: - UpdateThread(int threadIdx, void *teleboy); - ~UpdateThread() override; + UpdateThread(int threadIdx, TeleBoy& teleboy); + ~UpdateThread(); static void SetNextRecordingUpdate(time_t nextRecordingsUpdate); static void LoadEpg(int uniqueChannelId, time_t startTime, time_t endTime); - void* Process() override; + void Process(); private: - void *teleboy; + TeleBoy& m_teleboy; int m_threadIdx; static std::queue loadEpgQueue; static time_t nextRecordingsUpdate; - static P8PLATFORM::CMutex mutex; + std::atomic m_running = {false}; + std::thread m_thread; + static std::mutex mutex; }; diff -Nru kodi-pvr-teleboy-18.2.3/src/Utils.cpp kodi-pvr-teleboy-19.8.0/src/Utils.cpp --- kodi-pvr-teleboy-18.2.3/src/Utils.cpp 2013-05-31 22:59:22.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/Utils.cpp 2021-01-09 11:27:13.000000000 +0000 @@ -1,20 +1,18 @@ #include "Utils.h" +#ifdef TARGET_WINDOWS +#include "windows.h" +#endif #include #include #include #include -#include "p8-platform/os.h" - -#include "client.h" - -using namespace ADDON; +#include "kodi/Filesystem.h" std::string Utils::GetFilePath(std::string strPath, bool bUserPath) { - return (bUserPath ? g_strUserPath : g_strClientPath) + PATH_SEPARATOR_CHAR - + strPath; + return (bUserPath ? kodi::GetAddonPath(strPath) : kodi::GetBaseUserPath(strPath)); } // http://stackoverflow.com/a/17708801 @@ -86,23 +84,21 @@ std::string Utils::ReadFile(const std::string path) { - void* file; - file = XBMC->CURLCreate(path.c_str()); - if (!file || !XBMC->CURLOpen(file, 0)) + kodi::vfs::CFile file; + if (!file.CURLCreate(path) || !file.CURLOpen(0)) { - XBMC->Log(LOG_ERROR, "Failed to open file [%s].", path.c_str()); + kodi::Log(ADDON_LOG_ERROR, "Failed to open file [%s].", path.c_str()); return ""; } char buf[1025]; size_t nbRead; std::string content; - while ((nbRead = XBMC->ReadFile(file, buf, 1024)) > 0) + while ((nbRead = file.Read(buf, 1024)) > 0) { buf[nbRead] = 0; content.append(buf); } - XBMC->CloseFile(file); return content; } diff -Nru kodi-pvr-teleboy-18.2.3/src/windows.h kodi-pvr-teleboy-19.8.0/src/windows.h --- kodi-pvr-teleboy-18.2.3/src/windows.h 1970-01-01 00:00:00.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/src/windows.h 2021-01-09 11:27:13.000000000 +0000 @@ -0,0 +1,47 @@ +#ifndef GMTIME_H +#define GMTIME_H +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) +#pragma comment(lib, "ws2_32.lib") +#include +#include +#include +#define timegm _mkgmtime + +#define gmtime_r __gmtime_r +static inline struct tm *gmtime_r(const time_t *clock, struct tm *result) +{ + struct tm *data; + if (!clock || !result) + return NULL; + data = gmtime(clock); + if (!data) + return NULL; + memcpy(result, data, sizeof(*result)); + return result; +} + +#include +#include +#include + +static inline char* strptime(const char* s, + const char* f, + struct tm* tm) { + // Isn't the C++ standard lib nice? std::get_time is defined such that its + // format parameters are the exact same as strptime. Of course, we have to + // create a string stream first, and imbue it with the current C locale, and + // we also have to make sure we return the right things if it fails, or + // if it succeeds, but this is still far simpler an implementation than any + // of the versions in any of the C standard libraries. + std::istringstream input(s); + input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input >> std::get_time(tm, f); + if (input.fail()) { + return nullptr; + } + return (char*)(s + input.tellg()); +} + +#endif +#endif + diff -Nru kodi-pvr-teleboy-18.2.3/.travis.yml kodi-pvr-teleboy-19.8.0/.travis.yml --- kodi-pvr-teleboy-18.2.3/.travis.yml 1970-01-01 00:00:00.000000000 +0000 +++ kodi-pvr-teleboy-19.8.0/.travis.yml 2021-01-09 11:27:13.000000000 +0000 @@ -0,0 +1,54 @@ +language: cpp + +# +# Define the builds to get up to date versions of cmake and gcc +# +env: + global: + - app_id=pvr.teleboy + +matrix: + include: + - os: linux + dist: bionic + sudo: required + compiler: gcc + - os: linux + dist: bionic + sudo: required + compiler: clang + - os: linux + dist: bionic + sudo: required + compiler: gcc + env: DEBIAN_BUILD=true + - os: linux + dist: focal + sudo: required + compiler: gcc + env: DEBIAN_BUILD=true + - os: osx + osx_image: xcode10.2 + +before_install: + - if [[ $DEBIAN_BUILD == true ]]; then sudo add-apt-repository -y ppa:team-xbmc/xbmc-nightly; fi + - if [[ $DEBIAN_BUILD == true ]]; then sudo apt-get update; fi + - if [[ $DEBIAN_BUILD == true ]]; then sudo apt-get install fakeroot; fi + +# +# The addon source is automatically checked out in $TRAVIS_BUILD_DIR, +# we'll put the Kodi source on the same level +# +before_script: + - if [[ $DEBIAN_BUILD != true ]]; then cd $TRAVIS_BUILD_DIR/..; fi + - if [[ $DEBIAN_BUILD != true ]]; then git clone --branch master --depth=1 https://github.com/xbmc/xbmc.git; fi + - if [[ $DEBIAN_BUILD != true ]]; then cd ${app_id} && mkdir build && cd build; fi + - if [[ $DEBIAN_BUILD != true ]]; then mkdir -p definition/${app_id}; fi + - if [[ $DEBIAN_BUILD != true ]]; then echo ${app_id} $TRAVIS_BUILD_DIR $TRAVIS_COMMIT > definition/${app_id}/${app_id}.txt; fi + - if [[ $DEBIAN_BUILD != true ]]; then cmake -DADDONS_TO_BUILD=${app_id} -DADDON_SRC_PREFIX=$TRAVIS_BUILD_DIR/.. -DADDONS_DEFINITION_DIR=$TRAVIS_BUILD_DIR/build/definition -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$TRAVIS_BUILD_DIR/../xbmc/addons -DPACKAGE_ZIP=1 $TRAVIS_BUILD_DIR/../xbmc/cmake/addons; fi + - if [[ $DEBIAN_BUILD == true ]]; then wget https://raw.githubusercontent.com/xbmc/xbmc/master/xbmc/addons/kodi-dev-kit/tools/debian-addon-package-test.sh && chmod +x ./debian-addon-package-test.sh; fi + - if [[ $DEBIAN_BUILD == true ]]; then sudo apt-get build-dep $TRAVIS_BUILD_DIR; fi + +script: + - if [[ $DEBIAN_BUILD != true ]]; then make; fi + - if [[ $DEBIAN_BUILD == true ]]; then ./debian-addon-package-test.sh $TRAVIS_BUILD_DIR; fi