diff options
Diffstat (limited to 'xbmc/utils/LegacyPathTranslation.cpp')
| -rw-r--r-- | xbmc/utils/LegacyPathTranslation.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/xbmc/utils/LegacyPathTranslation.cpp b/xbmc/utils/LegacyPathTranslation.cpp new file mode 100644 index 0000000..0069339 --- /dev/null +++ b/xbmc/utils/LegacyPathTranslation.cpp | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2013-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "LegacyPathTranslation.h" | ||
| 10 | |||
| 11 | #include "URL.h" | ||
| 12 | #include "utils/StringUtils.h" | ||
| 13 | |||
| 14 | typedef struct Translator { | ||
| 15 | const char *legacyPath; | ||
| 16 | const char *newPath; | ||
| 17 | } Translator; | ||
| 18 | |||
| 19 | // ATTENTION: Make sure the longer match strings go first | ||
| 20 | // because the string match is performed with StringUtils::StartsWith() | ||
| 21 | static Translator s_videoDbTranslator[] = { | ||
| 22 | { "videodb://1/1", "videodb://movies/genres" }, | ||
| 23 | { "videodb://1/2", "videodb://movies/titles" }, | ||
| 24 | { "videodb://1/3", "videodb://movies/years" }, | ||
| 25 | { "videodb://1/4", "videodb://movies/actors" }, | ||
| 26 | { "videodb://1/5", "videodb://movies/directors" }, | ||
| 27 | { "videodb://1/6", "videodb://movies/studios" }, | ||
| 28 | { "videodb://1/7", "videodb://movies/sets" }, | ||
| 29 | { "videodb://1/8", "videodb://movies/countries" }, | ||
| 30 | { "videodb://1/9", "videodb://movies/tags" }, | ||
| 31 | { "videodb://1", "videodb://movies" }, | ||
| 32 | { "videodb://2/1", "videodb://tvshows/genres" }, | ||
| 33 | { "videodb://2/2", "videodb://tvshows/titles" }, | ||
| 34 | { "videodb://2/3", "videodb://tvshows/years" }, | ||
| 35 | { "videodb://2/4", "videodb://tvshows/actors" }, | ||
| 36 | { "videodb://2/5", "videodb://tvshows/studios" }, | ||
| 37 | { "videodb://2/9", "videodb://tvshows/tags" }, | ||
| 38 | { "videodb://2", "videodb://tvshows" }, | ||
| 39 | { "videodb://3/1", "videodb://musicvideos/genres" }, | ||
| 40 | { "videodb://3/2", "videodb://musicvideos/titles" }, | ||
| 41 | { "videodb://3/3", "videodb://musicvideos/years" }, | ||
| 42 | { "videodb://3/4", "videodb://musicvideos/artists" }, | ||
| 43 | { "videodb://3/5", "videodb://musicvideos/albums" }, | ||
| 44 | { "videodb://3/9", "videodb://musicvideos/tags" }, | ||
| 45 | { "videodb://3", "videodb://musicvideos" }, | ||
| 46 | { "videodb://4", "videodb://recentlyaddedmovies" }, | ||
| 47 | { "videodb://5", "videodb://recentlyaddedepisodes" }, | ||
| 48 | { "videodb://6", "videodb://recentlyaddedmusicvideos" } | ||
| 49 | }; | ||
| 50 | |||
| 51 | #define VideoDbTranslatorSize sizeof(s_videoDbTranslator) / sizeof(Translator) | ||
| 52 | |||
| 53 | // ATTENTION: Make sure the longer match strings go first | ||
| 54 | // because the string match is performed with StringUtils::StartsWith() | ||
| 55 | static Translator s_musicDbTranslator[] = { | ||
| 56 | { "musicdb://10", "musicdb://singles" }, | ||
| 57 | { "musicdb://1", "musicdb://genres" }, | ||
| 58 | { "musicdb://2", "musicdb://artists" }, | ||
| 59 | { "musicdb://3", "musicdb://albums" }, | ||
| 60 | { "musicdb://4", "musicdb://songs" }, | ||
| 61 | { "musicdb://5/1", "musicdb://top100/albums" }, | ||
| 62 | { "musicdb://5/2", "musicdb://top100/songs" }, | ||
| 63 | { "musicdb://5", "musicdb://top100" }, | ||
| 64 | { "musicdb://6", "musicdb://recentlyaddedalbums" }, | ||
| 65 | { "musicdb://7", "musicdb://recentlyplayedalbums" }, | ||
| 66 | { "musicdb://8", "musicdb://compilations" }, | ||
| 67 | { "musicdb://9", "musicdb://years" } | ||
| 68 | }; | ||
| 69 | |||
| 70 | #define MusicDbTranslatorSize sizeof(s_musicDbTranslator) / sizeof(Translator) | ||
| 71 | |||
| 72 | std::string CLegacyPathTranslation::TranslateVideoDbPath(const CURL &legacyPath) | ||
| 73 | { | ||
| 74 | return TranslatePath(legacyPath.Get(), s_videoDbTranslator, VideoDbTranslatorSize); | ||
| 75 | } | ||
| 76 | |||
| 77 | std::string CLegacyPathTranslation::TranslateMusicDbPath(const CURL &legacyPath) | ||
| 78 | { | ||
| 79 | return TranslatePath(legacyPath.Get(), s_musicDbTranslator, MusicDbTranslatorSize); | ||
| 80 | } | ||
| 81 | |||
| 82 | std::string CLegacyPathTranslation::TranslateVideoDbPath(const std::string &legacyPath) | ||
| 83 | { | ||
| 84 | return TranslatePath(legacyPath, s_videoDbTranslator, VideoDbTranslatorSize); | ||
| 85 | } | ||
| 86 | |||
| 87 | std::string CLegacyPathTranslation::TranslateMusicDbPath(const std::string &legacyPath) | ||
| 88 | { | ||
| 89 | return TranslatePath(legacyPath, s_musicDbTranslator, MusicDbTranslatorSize); | ||
| 90 | } | ||
| 91 | |||
| 92 | std::string CLegacyPathTranslation::TranslatePath(const std::string &legacyPath, Translator *translationMap, size_t translationMapSize) | ||
| 93 | { | ||
| 94 | std::string newPath = legacyPath; | ||
| 95 | for (size_t index = 0; index < translationMapSize; index++) | ||
| 96 | { | ||
| 97 | if (StringUtils::StartsWithNoCase(newPath, translationMap[index].legacyPath)) | ||
| 98 | { | ||
| 99 | StringUtils::Replace(newPath, translationMap[index].legacyPath, translationMap[index].newPath); | ||
| 100 | break; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | return newPath; | ||
| 105 | } | ||
