diff --git a/html/css/style.css b/html/css/style.css new file mode 100644 index 0000000..8906ff5 --- /dev/null +++ b/html/css/style.css @@ -0,0 +1,45 @@ +.onoffswitch { + position: relative; width: 85px; + -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none; +} +.onoffswitch-checkbox { + display: none; +} +.onoffswitch-label { + display: block; overflow: hidden; cursor: pointer; + border: 2px solid #FFFFFF; border-radius: 20px; +} +.onoffswitch-inner { + display: block; width: 200%; margin-left: -100%; + transition: margin 0.3s ease-in 0s; +} +.onoffswitch-inner:before, .onoffswitch-inner:after { + display: block; float: left; width: 50%; height: 32px; padding: 0; line-height: 32px; + font-size: 12px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold; + box-sizing: border-box; +} +.onoffswitch-inner:before { + content: "Movies"; + padding-left: 9px; + background-color: #21D278; color: #FFFFFF; +} +.onoffswitch-inner:after { + content: "Shows"; + padding-right: 9px; + background-color: #EEEEEE; color: #999999; + text-align: right; +} +.onoffswitch-switch { + display: block; width: 23px; margin: 4.5px; + background: #FFFFFF; + position: absolute; top: 0; bottom: 0; + right: 49px; + border: 2px solid #FFFFFF; border-radius: 20px; + transition: all 0.3s ease-in 0s; +} +.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner { + margin-left: 0; +} +.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch { + right: 0px; +} \ No newline at end of file diff --git a/html/js/searchBar.js b/html/js/searchBar.js index 3d86e76..55d8b80 100644 --- a/html/js/searchBar.js +++ b/html/js/searchBar.js @@ -6,6 +6,25 @@ button.onclick = function () { queryTMDB(text); } +function clearSearchResults() { + var displayNode = document.getElementById("display"); + while (displayNode.firstChild) { + displayNode.removeChild(displayNode.firstChild); + } +} + +function toggle(button) { + toggleNode = document.getElementById("myonoffswitch"); + console.log(toggleNode); + + + if(toggleNode.value=="movies"){ + toggleNode.value="shows";} + + else if(toggleNode.value=="shows"){ + toggleNode.value="movies";} +} + function queryTMDB(query) { var data = "{}"; @@ -14,6 +33,8 @@ function queryTMDB(query) { xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { + clearSearchResults() + var display = document.getElementById("display"); var jsonObj = JSON.parse(this.responseText); console.log(jsonObj.movies); @@ -27,14 +48,19 @@ function queryTMDB(query) { var poster_path = "http://image.tmdb.org/t/p/w500"+jsonObj.movies[key].poster_path; else var poster_path = "images/image_nf.svg"; + + var exists = jsonObj.movies[key].exists; var node = document.createElement("li"); // Create a
  • node var imageNode = document.createElement('img'); var textNode = document.createTextNode(title); // Create a text node var buttonNode = document.createElement("span"); var button2Node = document.createElement("span"); - buttonNode.innerHTML = ''; - button2Node.innerHTML = ''; + if (!exists) { + buttonNode.innerHTML = ''; + } + else + button2Node.innerHTML = ''; imageNode.src = poster_path; imageNode.style.width = "500px"; @@ -48,6 +74,9 @@ function queryTMDB(query) { }); } + else { + console.log("404"); + } }); xhr.open("GET", "http://localhost:63590/api/v1/plex/request?query="+query); diff --git a/html/searchDisplay.html b/html/searchDisplay.html index 794f798..7d9c1f0 100644 --- a/html/searchDisplay.html +++ b/html/searchDisplay.html @@ -2,10 +2,20 @@ tmdb.org Search Displayer + + +
    + + +
    +

    diff --git a/plex/__pycache__/plexSearch.cpython-34.pyc b/plex/__pycache__/plexSearch.cpython-34.pyc new file mode 100644 index 0000000..f5a8fa9 Binary files /dev/null and b/plex/__pycache__/plexSearch.cpython-34.pyc differ diff --git a/plex/__pycache__/tmdb.cpython-34.pyc b/plex/__pycache__/tmdb.cpython-34.pyc index 978bf9e..47f3c89 100644 Binary files a/plex/__pycache__/tmdb.cpython-34.pyc and b/plex/__pycache__/tmdb.cpython-34.pyc differ diff --git a/plex/plexSearch.py b/plex/plexSearch.py index 401f883..406765d 100755 --- a/plex/plexSearch.py +++ b/plex/plexSearch.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-02-08 14:00:04 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-02-08 14:06:48 +# @Last Modified time: 2017-02-08 22:50:17 from requests import get @@ -66,4 +66,8 @@ def plexSearch(query): if __name__ == "__main__": - print(plexSearch("star+wars")) \ No newline at end of file + # print(plexSearch("star+wars")) + tiss = plexSearch("star+wars") + for al in tiss: + if (al['year']==2015): + print('thishsihis') \ No newline at end of file diff --git a/plex/plex_watching.py b/plex/plex_watching.py index 021bd2b..44f4593 100755 --- a/plex/plex_watching.py +++ b/plex/plex_watching.py @@ -3,11 +3,25 @@ # @Author: KevinMidboe # @Date: 2017-01-28 23:21:22 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-01-28 23:35:04 +# @Last Modified time: 2017-02-08 20:29:53 -from os import system, popen -import xml.etree.ElementTree as ET -from unicodedata import normalize +from requests import get + +plexBaseURL = "http://10.0.0.41:32400/" + +def parsePlexWatching(obj): + print(obj) + +def getPlexWatching(): + requestType = "status/sessions" + header = {'Accept': 'application/json'} + + url = plexBaseURL + requestType + response = get(url, headers=header) + + if response.status_code == 200: + watchingObj = response.json() + res = parsePlexWatching(watchingObj) def plex_watching(): # Every call saves the info of session.xml to a file named plexPlaying @@ -53,4 +67,4 @@ def plex_watching(): return 'Null playing' if __name__ == '__main__': - print(plex_watching()) + print(getPlexWatching()) diff --git a/plex/testData/watchingSingleEpisode.txt b/plex/testData/watchingSingleEpisode.txt new file mode 100644 index 0000000..4f6b649 --- /dev/null +++ b/plex/testData/watchingSingleEpisode.txt @@ -0,0 +1,13 @@ +{ + +'_children': [{'type': 'episode', 'viewOffset': '504654', 'grandparentThumb': '/library/metadata/4994/thumb/1486551832', 'chapterSource': '', 'grandparentArt': '/library/metadata/4994/art/1486551832', 'updatedAt': '1486581424', 'sessionKey': '177', 'parentThumb': '/library/metadata/17543/thumb/1486551832', 'key': '/library/metadata/21427', 'summary': '', + +'_children': [{'videoFrameRate': '24p', 'audioCodec': 'aac', 'videoResolution': '1080', 'bitrate': '4441', 'audioProfile': 'lc', 'height': '1080', 'container': 'mkv', 'aspectRatio': '1.78', '_elementType': 'Media', 'videoCodec': 'h264', 'videoProfile': 'high', 'duration': '1275312', 'id': '50963', + +'_children': [{'key': '/library/parts/51480/1486551812/file.mkv', 'size': '707980309', '_elementType': 'Part', 'id': '51480', 'videoProfile': 'high', 'duration': '1275312', 'audioProfile': 'lc', + +'_children': [{'refFrames': '4', 'scanType': 'progressive', 'chromaSubsampling': '4:2:0', 'height': '1080', 'default': '1', 'hasScalingMatrix': '0', 'languageCode': 'eng', 'frameRateMode': 'cfr', 'streamType': '1', 'cabac': '1', 'level': '40', 'width': '1920', 'bitrate': '4441', 'index': '0', 'bitDepth': '8', '_elementType': 'Stream', 'id': '109342', 'pixelFormat': 'yuv420p', 'codecID': 'V_MPEG4/ISO/AVC', 'language': 'English', 'duration': '1275317', 'frameRate': '23.976', 'profile': 'high', 'codec': 'h264'}, {'samplingRate': '48000', 'selected': '1', 'streamType': '2', 'index': '1', 'default': '1', 'languageCode': 'eng', 'audioChannelLayout': 'stereo', '_elementType': 'Stream', 'channels': '2', 'codecID': 'A_AAC', 'language': 'English', 'id': '109343', 'duration': '1275312', 'profile': 'lc', 'codec': 'aac'}, {'languageCode': 'eng', '_elementType': 'Stream', 'format': 'srt', 'codecID': 'S_TEXT/UTF8', 'language': 'English', 'id': '109344', 'streamType': '3', 'index': '2', 'default': '1', 'codec': 'srt'}], 'file': '/media/hdd1/tv/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW[rarbg]/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW.mkv', 'container': 'mkv'}], 'width': '1920', 'audioChannels': '2'}, {'videoFrameRate': '24p', 'audioCodec': 'aac', 'videoResolution': '1080', 'bitrate': '4441', 'audioProfile': 'lc', 'height': '1080', 'container': 'mkv', 'aspectRatio': '1.78', '_elementType': 'Media', 'videoCodec': 'h264', 'videoProfile': 'high', 'duration': '1275312', 'id': '50964', + +'_children': [{'key': '/library/parts/51481/1486551812/file.mkv', 'size': '707980309', '_elementType': 'Part', 'id': '51481', 'videoProfile': 'high', 'duration': '1275312', 'audioProfile': 'lc', + +'_children': [{'refFrames': '4', 'scanType': 'progressive', 'chromaSubsampling': '4:2:0', 'height': '1080', 'default': '1', 'hasScalingMatrix': '0', 'languageCode': 'eng', 'frameRateMode': 'cfr', 'streamType': '1', 'cabac': '1', 'level': '40', 'width': '1920', 'bitrate': '4441', 'index': '0', 'bitDepth': '8', '_elementType': 'Stream', 'id': '109345', 'pixelFormat': 'yuv420p', 'codecID': 'V_MPEG4/ISO/AVC', 'language': 'English', 'duration': '1275317', 'frameRate': '23.976', 'profile': 'high', 'codec': 'h264'}, {'samplingRate': '48000', 'selected': '1', 'streamType': '2', 'index': '1', 'default': '1', 'languageCode': 'eng', 'audioChannelLayout': 'stereo', '_elementType': 'Stream', 'channels': '2', 'codecID': 'A_AAC', 'language': 'English', 'id': '109346', 'duration': '1275312', 'profile': 'lc', 'codec': 'aac'}, {'languageCode': 'eng', '_elementType': 'Stream', 'format': 'srt', 'codecID': 'S_TEXT/UTF8', 'language': 'English', 'id': '109347', 'streamType': '3', 'index': '2', 'default': '1', 'codec': 'srt'}], 'file': '/media/hdd1/tv/Workaholics/Workaholics Season 07/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW[rarbg].mkv', 'container': 'mkv'}], 'width': '1920', 'audioChannels': '2'}, {'_elementType': 'User', 'id': '9608531', 'title': 'PhillipMid'}, {'address': '::ffff:84.211.211.7', 'title': 'TV UE55KU6075', 'platform': 'Samsung', 'product': 'Plex for Samsung', 'vendor': '', 'platformVersion': '2.4.0', 'state': 'playing', '_elementType': 'Player', 'version': '3.0.6 (2.10.8)', 'machineIdentifier': 'xbixedx5uyp', 'model': '', 'profile': 'Samsung', 'device': 'Samsung TV'}, {'complete': False, 'context': 'streaming', 'audioCodec': 'aac', 'remaining': 4081, 'audioChannels': 2, 'throttled': True, 'height': 720, 'videoDecision': 'transcode', 'container': 'mpegts', 'key': '6d94y2d0b25', 'audioDecision': 'copy', '_elementType': 'TranscodeSession', 'videoCodec': 'h264', 'speed': 0, 'duration': 1275000, 'width': 1280, 'protocol': 'hls', 'progress': 46.400001525878906}], 'grandparentKey': '/library/metadata/4994', 'parentRatingKey': '17543', 'duration': '1275312', 'ratingKey': '21427', 'parentIndex': '7', 'title': 'Episode 5', 'librarySectionID': '2', 'thumb': '/library/metadata/21427/thumb/1486581424', 'addedAt': '1486551819', 'art': '/library/metadata/4994/art/1486551832', 'grandparentTheme': '/library/metadata/4994/theme/1486551832', 'index': '5', 'grandparentRatingKey': '4994', '_elementType': 'Video', 'contentRating': 'TV-MA', 'parentKey': '/library/metadata/17543', 'grandparentTitle': 'Workaholics', 'guid': 'com.plexapp.agents.thetvdb://211751/7/5?lang=en'}], '_elementType': 'MediaContainer'} diff --git a/plex/testData/watchingTwoEpisodes.txt b/plex/testData/watchingTwoEpisodes.txt new file mode 100644 index 0000000..940142c --- /dev/null +++ b/plex/testData/watchingTwoEpisodes.txt @@ -0,0 +1,20 @@ +{'_children': + [{'updatedAt': '1484767485', 'parentRatingKey': '17974', 'parentThumb': '/library/metadata/17974/thumb/1484767485', 'viewOffset': '207967', 'duration': '1300224', 'parentKey': '/library/metadata/17974', +'_elementType': 'Video', 'originallyAvailableAt': '2011-03-27', 'parentIndex': '1', 'index': '9', 'ratingKey': '18008', 'key': '/library/metadata/18008', 'grandparentTitle': "Bob's Burgers", 'lastViewedAt': '1486582261', 'addedAt': '1484659664', 'grandparentKey': '/library/metadata/17973', + '_children': [{'aspectRatio': '1.78', 'audioCodec': 'ac3', 'height': '720', 'duration': '1300224', 'id': '47871', 'audioChannels': '6', 'videoFrameRate': '24p', '_elementType': 'Media', 'width': '1280', 'videoResolution': '720', 'videoProfile': 'high', + '_children': [{'file': "/media/hdd1/tv/Bob's Burgers/Bob's Burgers Season 01/Bob's Burgers S01E09/Bobs.Burgers.S01E09.720p.HDTV.x264.mkv", + '_children': [{'level': '41', 'hasScalingMatrix': '0', 'frameRate': '23.976', 'scanType': 'progressive', 'cabac': '1', 'languageCode': 'eng', 'codecID': 'V_MPEG4/ISO/AVC', 'duration': '1300217', '_elementType': 'Stream', 'index': '0', 'profile': 'high', 'bitDepth': '8', 'codec': 'h264', 'pixelFormat': 'yuv420p', 'refFrames': '8', 'language': 'English', 'id': '102482', 'bitrate': '3155', 'height': '720', 'chromaSubsampling': '4:2:0', 'frameRateMode': 'cfr', 'width': '1280', 'streamType': '1', 'requiredBandwidths': '8493,5928,5928,5928,5928,5928,5928,5928'}, + {'bitDepth': '16', 'codec': 'ac3', 'id': '102483', 'dialogNorm': '-24', 'samplingRate': '48000', 'bitrateMode': 'cbr', 'channels': '6', 'duration': '1300224', 'codecID': 'A_AC3', 'audioChannelLayout': '5.1(side)', '_elementType': 'Stream', 'index': '1', 'requiredBandwidths': '447,447,447,447,447,447,447,447', 'default': '1', 'bitrate': '448', 'streamType': '2', 'selected': '1'}, + {'codec': 'srt', '_elementType': 'Stream', 'key': '/library/streams/102507', 'streamType': '3', 'selected': '1', 'id': '102507', 'format': 'srt'}], + 'videoProfile': 'high', '_elementType': 'Part', 'key': '/library/parts/48219/1484659663/file.mkv', 'deepAnalysisVersion': '1', 'id': '48219', 'requiredBandwidths': '8941,6296,6296,6296,6296,6296,6296,6296', 'size': '586203587', 'duration': '1300224', 'container': 'mkv'}], + 'container': 'mkv', 'bitrate': '3607', 'videoCodec': 'h264'}, + {'tag': 'Wesley Archer', '_elementType': 'Director', 'id': '24668'}, + {'tag': 'Kit Boss', '_elementType': 'Writer', 'id': '29637'}, + {'title': 'KevinMidboe', '_elementType': 'User', 'id': '1', 'thumb': 'https://plex.tv/users/d249503d948004d7/avatar?c=2017-02-08+16%3A33%3A31+UTC'}, + {'platform': 'Safari', 'version': '2.13.0', 'state': 'playing', 'title': 'Plex Web (Safari)', '_elementType': 'Player', 'model': '', 'address': '::ffff:10.0.0.10', 'platformVersion': '10.0', 'product': 'Plex Web', 'machineIdentifier': '33b45f98-1a09-471f-81a8-b0c9d72f9616', 'device': 'OSX', 'vendor': '', 'profile': 'Web'}, + {'speed': 7, 'audioDecision': 'copy', 'height': 720, 'progress': 18.5, 'remaining': 148, 'width': 1280, 'duration': 1300000, 'throttled': False, 'container': 'mpegts', 'audioChannels': 6, '_elementType': 'TranscodeSession', 'key': 'ikwymgr7jnhedqr486u2ckey', 'subtitleDecision': 'burn', 'protocol': 'hls', 'complete': False, 'videoDecision': 'transcode', 'audioCodec': 'ac3', 'videoCodec': 'h264', 'context': 'streaming'}], + 'thumb': '/library/metadata/18008/thumb/1484767485', 'grandparentThumb': '/library/metadata/17973/thumb/1484767485', 'year': '2011', 'grandparentArt': '/library/metadata/17973/art/1484767485', 'summary': 'Bob and Gene bond over spaghetti western movies, which makes Louise jealous.', 'guid': 'com.plexapp.agents.thetvdb://194031/1/9?lang=en', 'chapterSource': '', 'art': '/library/metadata/17973/art/1484767485', 'contentRating': 'TV-14', 'sessionKey': '179', 'title': 'Spaghetti Western and Meatballs', 'librarySectionID': '2', 'grandparentTheme': '/library/metadata/17973/theme/1484767485', 'grandparentRatingKey': '17973', 'type': 'episode', 'rating': '7.5'}, + + {'updatedAt': '1486581424', 'parentRatingKey': '17543', 'guid': 'com.plexapp.agents.thetvdb://211751/7/5?lang=en', 'viewOffset': '834570', 'duration': '1275312', 'parentKey': '/library/metadata/17543', '_elementType': 'Video', 'grandparentTheme': '/library/metadata/4994/theme/1486551832', 'parentIndex': '7', 'index': '5', 'key': '/library/metadata/21427', 'grandparentTitle': 'Workaholics', 'addedAt': '1486551819', 'grandparentKey': '/library/metadata/4994', '_children': [{'audioProfile': 'lc', 'aspectRatio': '1.78', 'audioCodec': 'aac', 'height': '1080', 'id': '50963', 'duration': '1275312', 'audioChannels': '2', 'videoFrameRate': '24p', '_elementType': 'Media', 'width': '1920', 'videoResolution': '1080', 'videoProfile': 'high', '_children': [{'file': '/media/hdd1/tv/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW[rarbg]/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW.mkv', 'videoProfile': 'high', '_elementType': 'Part', 'key': '/library/parts/51480/1486551812/file.mkv', 'audioProfile': 'lc', '_children': [{'level': '40', 'hasScalingMatrix': '0', 'frameRate': '23.976', 'scanType': 'progressive', 'cabac': '1', 'languageCode': 'eng', 'codecID': 'V_MPEG4/ISO/AVC', 'duration': '1275317', '_elementType': 'Stream', 'index': '0', 'default': '1', 'profile': 'high', 'bitDepth': '8', 'codec': 'h264', 'pixelFormat': 'yuv420p', 'refFrames': '4', 'language': 'English', 'id': '109342', 'height': '1080', 'chromaSubsampling': '4:2:0', 'frameRateMode': 'cfr', 'width': '1920', 'streamType': '1', 'bitrate': '4441'}, {'codec': 'aac', 'streamType': '2', 'samplingRate': '48000', 'channels': '2', 'codecID': 'A_AAC', 'languageCode': 'eng', 'language': 'English', 'duration': '1275312', 'id': '109343', 'audioChannelLayout': 'stereo', '_elementType': 'Stream', 'index': '1', 'default': '1', 'profile': 'lc', 'selected': '1'}, {'streamType': '3', 'codec': 'srt', '_elementType': 'Stream', 'index': '2', 'id': '109344', 'default': '1', 'language': 'English', 'codecID': 'S_TEXT/UTF8', 'languageCode': 'eng', 'format': 'srt'}], 'id': '51480', 'size': '707980309', 'duration': '1275312', 'container': 'mkv'}], 'container': 'mkv', 'bitrate': '4441', 'videoCodec': 'h264'}, {'audioProfile': 'lc', 'aspectRatio': '1.78', 'audioCodec': 'aac', 'height': '1080', 'id': '50964', 'duration': '1275312', 'audioChannels': '2', 'videoFrameRate': '24p', '_elementType': 'Media', 'width': '1920', 'videoResolution': '1080', 'videoProfile': 'high', '_children': [{'file': '/media/hdd1/tv/Workaholics/Workaholics Season 07/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW[rarbg].mkv', 'videoProfile': 'high', '_elementType': 'Part', 'key': '/library/parts/51481/1486551812/file.mkv', 'audioProfile': 'lc', '_children': [{'level': '40', 'hasScalingMatrix': '0', 'frameRate': '23.976', 'scanType': 'progressive', 'cabac': '1', 'languageCode': 'eng', 'codecID': 'V_MPEG4/ISO/AVC', 'duration': '1275317', '_elementType': 'Stream', 'index': '0', 'default': '1', 'profile': 'high', 'bitDepth': '8', 'codec': 'h264', 'pixelFormat': 'yuv420p', 'refFrames': '4', 'language': 'English', 'id': '109345', 'height': '1080', 'chromaSubsampling': '4:2:0', 'frameRateMode': 'cfr', 'width': '1920', 'streamType': '1', 'bitrate': '4441'}, {'codec': 'aac', 'streamType': '2', 'samplingRate': '48000', 'channels': '2', 'codecID': 'A_AAC', 'languageCode': 'eng', 'language': 'English', 'duration': '1275312', 'id': '109346', 'audioChannelLayout': 'stereo', '_elementType': 'Stream', 'index': '1', 'default': '1', 'profile': 'lc', 'selected': '1'}, {'streamType': '3', 'codec': 'srt', '_elementType': 'Stream', 'index': '2', 'id': '109347', 'default': '1', 'language': 'English', 'codecID': 'S_TEXT/UTF8', 'languageCode': 'eng', 'format': 'srt'}], 'id': '51481', 'size': '707980309', 'duration': '1275312', 'container': 'mkv'}], 'container': 'mkv', 'bitrate': '4441', 'videoCodec': 'h264'}, {'title': 'PhillipMid', '_elementType': 'User', 'id': '9608531'}, {'platform': 'Samsung', 'version': '3.0.6 (2.10.8)', 'state': 'playing', 'title': 'TV UE55KU6075', '_elementType': 'Player', 'model': '', 'address': '::ffff:84.211.211.7', 'platformVersion': '2.4.0', 'product': 'Plex for Samsung', 'machineIdentifier': 'xbixedx5uyp', 'device': 'Samsung TV', 'vendor': '', 'profile': 'Samsung'}, {'speed': 0, 'audioDecision': 'copy', 'height': 720, 'progress': 72.0999984741211, 'remaining': 3100, 'width': 1280, 'duration': 1275000, 'throttled': True, 'container': 'mpegts', 'audioChannels': 2, '_elementType': 'TranscodeSession', 'key': '6d94y2d0b25', 'protocol': 'hls', 'complete': False, 'videoDecision': 'transcode', 'audioCodec': 'aac', 'videoCodec': 'h264', 'context': 'streaming'}], 'thumb': '/library/metadata/21427/thumb/1486581424', 'grandparentThumb': '/library/metadata/4994/thumb/1486551832', 'grandparentArt': '/library/metadata/4994/art/1486551832', 'summary': '', 'parentThumb': '/library/metadata/17543/thumb/1486551832', 'chapterSource': '', 'art': '/library/metadata/4994/art/1486551832', 'contentRating': 'TV-MA', 'sessionKey': '177', 'title': 'Episode 5', 'librarySectionID': '2', 'ratingKey': '21427', 'grandparentRatingKey': '4994', 'type': 'episode'}], + + '_elementType': 'MediaContainer'} diff --git a/plex/testData/watchingTwoStreams.txt b/plex/testData/watchingTwoStreams.txt new file mode 100644 index 0000000..71f0a77 --- /dev/null +++ b/plex/testData/watchingTwoStreams.txt @@ -0,0 +1,6 @@ +{'_elementType': 'MediaContainer', + +'_children': [{'tagline': 'The Untold Story Behind The Miracle on the Hudson', 'originallyAvailableAt': '2016-09-09', 'studio': 'Malpaso Productions', '_children': [{'videoResolution': '1080', 'audioChannels': '8', 'videoCodec': 'h264', 'audioProfile': 'ma', '_children': [{'key': '/library/parts/51434/1486551705/file.mkv', 'size': '10117596851', '_children': [{'languageCode': 'eng', 'hasScalingMatrix': '0', 'duration': '5750709', 'chromaSubsampling': '4:2:0', 'frameRate': '23.976', 'width': '1920', 'pixelFormat': 'yuv420p', 'streamType': '1', 'id': '109244', 'frameRateMode': 'cfr', 'refFrames': '4', 'codecID': 'V_MPEG4/ISO/AVC', 'codec': 'h264', 'bitDepth': '8', 'cabac': '1', 'title': 'Sully.2016.BluRay.1080p.x264.DTS-HD.MA.7.1-LTT', 'default': '1', 'profile': 'high', 'height': '1080', 'index': '0', 'bitrate': '12539', 'language': 'English', 'scanType': 'progressive', 'level': '41', '_elementType': 'Stream'}, {'codec': 'dca', 'languageCode': 'eng', 'bitDepth': '24', 'audioChannelLayout': '7.1', 'profile': 'ma', 'bitrateMode': 'vbr', 'selected': '1', 'samplingRate': '48000', 'default': '1', 'title': 'DTS.HD.MA.7.1', 'id': '109245', 'index': '1', 'bitrate': '1536', 'duration': '5750689', 'language': 'English', 'channels': '8', 'codecID': 'A_DTS', '_elementType': 'Stream', 'streamType': '2'}, {'codec': 'pgs', 'languageCode': 'eng', 'format': 'pgs', 'index': '2', 'title': 'Eng-PGS-SDH', 'streamType': '3', 'id': '109246', 'language': 'English', 'codecID': 'S_HDMV/PGS', '_elementType': 'Stream', 'selected': '1'}, {'codec': 'srt', 'languageCode': 'eng', 'format': 'srt', 'index': '3', 'title': 'Eng.SRT-SDH', 'streamType': '3', 'id': '109247', 'language': 'English', 'codecID': 'S_TEXT/UTF8', '_elementType': 'Stream'}, {'codec': 'srt', 'languageCode': 'eng', 'format': 'srt', 'index': '4', 'title': 'Eng.SRT', 'streamType': '3', 'id': '109248', 'language': 'English', 'codecID': 'S_TEXT/UTF8', '_elementType': 'Stream'}, {'codec': 'pgs', 'languageCode': 'fre', 'format': 'pgs', 'index': '5', 'title': 'Fre-PGS', 'streamType': '3', 'id': '109249', 'language': 'Français', 'codecID': 'S_HDMV/PGS', '_elementType': 'Stream'}, {'codec': 'pgs', 'languageCode': 'por', 'format': 'pgs', 'index': '6', 'title': 'Por-PGS', 'streamType': '3', 'id': '109250', 'language': 'Português', 'codecID': 'S_HDMV/PGS', '_elementType': 'Stream'}, {'codec': 'pgs', 'languageCode': 'spa', 'format': 'pgs', 'index': '7', 'title': 'Spa-PGS', 'streamType': '3', 'id': '109251', 'language': 'Español', 'codecID': 'S_HDMV/PGS', '_elementType': 'Stream'}], 'audioProfile': 'ma', 'file': '/media/hdd1/movies/Sully.2016.BluRay.1080p.x264.DTS-HD.MA.7.1-LTT/Sully.2016.BluRay.1080p.x264.DTS-HD.MA.7.1-LTT.mkv', 'duration': '5750689', 'videoProfile': 'high', '_elementType': 'Part', 'id': '51434', 'container': 'mkv'}], '_elementType': 'Media', 'id': '50917', 'videoProfile': 'high', 'audioCodec': 'dca-ma', 'width': '1920', 'height': '1080', 'videoFrameRate': '24p', 'aspectRatio': '1.78', 'duration': '5750689', 'container': 'mkv', 'bitrate': '14075'}, {'count': '39', '_elementType': 'Genre', 'tag': 'Biography', 'id': '233'}, {'count': '268', '_elementType': 'Genre', 'tag': 'Drama', 'id': '10'}, {'count': '3', '_elementType': 'Director', 'tag': 'Clint Eastwood', 'id': '3412'}, {'tag': 'Todd Komarnicki', '_elementType': 'Writer', 'id': '30087'}, {'count': '9', '_elementType': 'Producer', 'tag': 'Frank Marshall', 'id': '15'}, {'count': '3', '_elementType': 'Producer', 'tag': 'Clint Eastwood', 'id': '3497'}, {'tag': 'Tim Moore', '_elementType': 'Producer', 'id': '30111'}, {'tag': 'Allyn Stewart', '_elementType': 'Producer', 'id': '30112'}, {'count': '624', '_elementType': 'Country', 'tag': 'USA', 'id': '17'}, {'role': "Chesley 'Sully' Sullenberger", 'thumb': 'http://image.tmdb.org/t/p/original/a14CNByTYALAPSGlwlmfHILpEIW.jpg', 'tag': 'Tom Hanks', 'id': '2067', '_elementType': 'Role', 'count': '18'}, {'role': 'Jeff Skiles', 'thumb': 'http://image.tmdb.org/t/p/original/aRSofX2rMpOhPanB9Wh7veYmFn4.jpg', 'tag': 'Aaron Eckhart', 'id': '114', '_elementType': 'Role', 'count': '5'}, {'role': 'Lorraine Sullenberger', 'thumb': 'http://image.tmdb.org/t/p/original/wi4CEJZDmkFvDgwqG98XXD1Ob3b.jpg', 'tag': 'Laura Linney', 'id': '22863', '_elementType': 'Role', 'count': '3'}, {'role': 'Elizabeth Davis', 'tag': 'Anna Gunn', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/6yLKtfYFWbJp5HAjvCecQCYlmqk.jpg', 'id': '24292'}, {'role': 'Tess Soza', 'tag': 'Autumn Reeser', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/vZlZQkQzQ0PSCnQT77vqEFnYsoO.jpg', 'id': '30088'}, {'role': 'Mike Cleary', 'thumb': 'http://image.tmdb.org/t/p/original/5Mw4StSwWwTLyBapXz9nOg7iUl5.jpg', 'tag': 'Holt McCallany', 'id': '3014', '_elementType': 'Role', 'count': '5'}, {'role': 'Charles Porter', 'thumb': 'http://image.tmdb.org/t/p/original/9VwiKnQySJN7buvCg53v4NB5Tj7.jpg', 'tag': "Mike O'Malley", 'id': '27078', '_elementType': 'Role', 'count': '2'}, {'role': 'Ben Edwards', 'thumb': 'http://image.tmdb.org/t/p/original/jpyh4Wd6AZ1oBCsbIxB72otXtcy.jpg', 'tag': 'Jamey Sheridan', 'id': '20938', '_elementType': 'Role', 'count': '2'}, {'role': 'Michael Delaney', 'thumb': 'http://image.tmdb.org/t/p/original/sjYRLct4yHiRDQWM0nOvhDr2yAP.jpg', 'tag': 'Jerry Ferrara', 'id': '8552', '_elementType': 'Role', 'count': '4'}, {'role': 'Doreen Welsh', 'tag': 'Molly Hagan', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/xfqpbt6U5dROCbhX31IwfNUqsUq.jpg', 'id': '30089'}, {'role': 'Jimmy Stefanik', 'tag': 'Max Adler', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/oHdEBpOm4GhcNm3nU7lRHQBcQsJ.jpg', 'id': '30090'}, {'role': 'Jeff Kolodjay', 'thumb': 'http://image.tmdb.org/t/p/original/nq7pwic6Xe6XTRzOfXjMCuUqbjt.jpg', 'tag': 'Sam Huntington', 'id': '23203', '_elementType': 'Role', 'count': '2'}, {'role': 'Brian Kelly', 'thumb': 'http://image.tmdb.org/t/p/original/ejTa81V0ZSWdXHLpGJ43JG65T4q.jpg', 'tag': 'Wayne Bastrup', 'id': '22206', '_elementType': 'Role', 'count': '2'}, {'role': 'Diane Higgins', 'tag': 'Valerie Mahaffey', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/xO1RmcHQqagRlc4bUdhAKJJ8jEU.jpg', 'id': '30091'}, {'role': 'L. T. Cook', 'tag': 'Jeff Kober', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/eMp9ZsC77yddwW4SMiuZ7xOd0GS.jpg', 'id': '30092'}, {'role': 'Larry Rooney', 'thumb': 'http://image.tmdb.org/t/p/original/3KYVMaGkWTEDQ0T9lsu85pVbP4T.jpg', 'tag': 'Chris Bauer', 'id': '367', '_elementType': 'Role', 'count': '4'}, {'role': 'Herself', 'tag': 'Katie Couric', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/uCBhJtyH4sWSceDGgWf53vuxQM6.jpg', 'id': '30093'}, {'role': 'Pete the Bartender', 'tag': 'Michael Rapaport', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/i39bAISjAUWYlXZZA0wmjYWnZGf.jpg', 'id': '30094'}, {'role': 'Himself', 'tag': 'Vincent Lombardi', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/kofpALprOT9YTqFmYvvq8DIZVdY.jpg', 'id': '30095'}, {'role': 'Jim Whitaker', 'thumb': 'http://image.tmdb.org/t/p/original/A0rZn1YC69t2iRcBmyqbQNeiof2.jpg', 'tag': 'Cooper Thornton', 'id': '10143', '_elementType': 'Role', 'count': '3'}, {'role': 'Emma Cowan', 'tag': 'Noelle Fink', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/mz6LxRsKU1J7wVoKbpGkKf8j6P5.jpg', 'id': '30096'}, {'role': 'Passenger 12B', 'thumb': 'http://image.tmdb.org/t/p/original/g0bhIkFDmO23w9xlHh4nxqPAdlO.jpg', 'tag': 'Doris McCarthy', 'id': '29361', '_elementType': 'Role', 'count': '2'}, {'role': 'Gurisman', 'tag': 'Purva Bedi', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/c1hnJKpSqWSOlSVdSqnIJAGbeYC.jpg', 'id': '30097'}, {'role': 'Rob Kolodjay', 'tag': 'Christopher Curry', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/1UUvuuXIFlJ6hKNrLnhu0JU9tiC.jpg', 'id': '30098'}, {'role': 'Luis Salerno', 'tag': 'Grant Roberts', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/bADsqOjiv40iK98myH7w0Qz64qZ.jpg', 'id': '30099'}, {'role': 'Carlo Alfonso', 'tag': 'Graham Sibley', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/eciTx3gZjD3pFTPsZ1buhkUkJtS.jpg', 'id': '30100'}, {'role': 'Donna Dent', 'thumb': 'http://image.tmdb.org/t/p/original/uA6NTOlBOM2JqHzDDSpAFPbp26y.jpg', 'tag': 'Ann Cusack', 'id': '17292', '_elementType': 'Role', 'count': '2'}, {'role': 'Patrick', 'tag': 'Patch Darragh', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/ozrGFV2Ffv5erGlXvWKRPCNmpu9.jpg', 'id': '30101'}, {'role': 'EMT', 'tag': 'Shaun Rey', '_elementType': 'Role', 'thumb': 'http://image.tmdb.org/t/p/original/5wT8fFTYwGmOBrY8HCX8YvWhRtl.jpg', 'id': '30102'}, {'role': 'EMT', 'count': '2', '_elementType': 'Role', 'tag': 'Justin Michael Woods', 'id': '4771'}, {'role': 'EMT', 'tag': 'Tommy McInnis', '_elementType': 'Role', 'id': '30103'}, {'role': 'EMT', 'count': '2', '_elementType': 'Role', 'tag': 'Kyle Julian Graham', 'id': '23487'}, {'role': 'ESU', 'tag': 'Marc Chouen', '_elementType': 'Role', 'id': '30104'}, {'role': 'Sheila Dail', 'tag': 'Jane Gabbert', '_elementType': 'Role', 'id': '30105'}, {'role': 'NYC Police Officer', 'tag': 'Lynn Marocola', '_elementType': 'Role', 'id': '30106'}, {'role': 'Sully (16 Years Old)', 'tag': 'Blake Jones', '_elementType': 'Role', 'id': '30107'}, {'role': 'Journaliste #1', 'count': '2', '_elementType': 'Role', 'tag': 'Laura Lundy Wheale', 'id': '30108'}, {'role': 'Reporter', 'count': '2', '_elementType': 'Role', 'tag': 'Kamron Leal', 'id': '23579'}, {'role': 'Reporter', 'count': '2', '_elementType': 'Role', 'tag': 'Laura Lundy Wheale', 'id': '30108'}, {'role': 'Passager secouru', 'tag': 'Michael Joseph Donlan', '_elementType': 'Role', 'id': '30109'}, {'role': 'Pam Seagle', 'tag': 'Kelly L. Moran', '_elementType': 'Role', 'id': '30110'}, {'title': 'KevinMidboe', '_elementType': 'User', 'thumb': 'https://plex.tv/users/d249503d948004d7/avatar?c=2017-02-08+16%3A33%3A31+UTC', 'id': '1'}, {'state': 'playing', 'platformVersion': '10.0', 'title': 'Plex Web (Safari)', 'model': '', 'vendor': '', 'profile': 'Web', 'device': 'OSX', 'machineIdentifier': '33b45f98-1a09-471f-81a8-b0c9d72f9616', 'version': '2.13.0', 'platform': 'Safari', 'address': '::ffff:10.0.0.10', '_elementType': 'Player', 'product': 'Plex Web'}, {'audioChannels': 6, 'protocol': 'hls', 'speed': 1.2000000476837158, 'subtitleDecision': 'burn', 'container': 'mpegts', 'progress': 1, 'audioCodec': 'aac', 'width': 1920, 'remaining': 5187, 'audioDecision': 'transcode', 'key': 'k5dptzb0kmfm7j01dn394626', 'videoDecision': 'transcode', 'duration': 5750000, 'videoCodec': 'h264', 'complete': False, 'height': 1080, '_elementType': 'TranscodeSession', 'context': 'streaming', 'throttled': False}], +'primaryExtraKey': '/library/metadata/21410', 'chapterSource': 'mixed', 'art': '/library/metadata/21409/art/1486551727', 'updatedAt': '1486551727', 'contentRating': 'PG-13', 'audienceRatingImage': 'rottentomatoes://image.rating.upright', 'duration': '5750689', 'ratingKey': '21409', 'title': 'Sully', 'rating': '8.5', 'thumb': '/library/metadata/21409/thumb/1486551727', 'summary': "On 15 January 2009, the world witnessed the 'Miracle on the Hudson' when Captain 'Sully' Sullenberger glided his disabled plane onto the frigid waters of the Hudson River, saving the lives of all 155 aboard. However, even as Sully was being heralded by the public and the media for his unprecedented feat of aviation skill, an investigation was unfolding that threatened to destroy his reputation and career.", 'ratingImage': 'rottentomatoes://image.rating.certified', 'guid': 'com.plexapp.agents.imdb://tt3263904?lang=en', 'audienceRating': '8.5', 'key': '/library/metadata/21409', 'type': 'movie', 'librarySectionID': '1', 'viewOffset': '35081', 'addedAt': '1486551712', '_elementType': 'Video', 'year': '2016', 'sessionKey': '179'}, + +{'parentThumb': '/library/metadata/17543/thumb/1486551832', 'summary': '', '_children': [{'videoResolution': '1080', 'audioChannels': '2', 'videoCodec': 'h264', 'audioProfile': 'lc', '_children': [{'key': '/library/parts/51480/1486551812/file.mkv', 'size': '707980309', '_children': [{'languageCode': 'eng', 'hasScalingMatrix': '0', 'duration': '1275317', 'chromaSubsampling': '4:2:0', 'frameRate': '23.976', 'width': '1920', 'pixelFormat': 'yuv420p', 'streamType': '1', 'id': '109342', 'frameRateMode': 'cfr', 'refFrames': '4', 'codecID': 'V_MPEG4/ISO/AVC', 'codec': 'h264', 'bitDepth': '8', 'cabac': '1', 'default': '1', 'profile': 'high', 'height': '1080', 'index': '0', 'bitrate': '4441', 'language': 'English', 'scanType': 'progressive', 'level': '40', '_elementType': 'Stream'}, {'codec': 'aac', 'languageCode': 'eng', 'audioChannelLayout': 'stereo', 'selected': '1', 'samplingRate': '48000', 'default': '1', 'id': '109343', 'index': '1', 'profile': 'lc', 'duration': '1275312', 'language': 'English', 'channels': '2', 'codecID': 'A_AAC', '_elementType': 'Stream', 'streamType': '2'}, {'codec': 'srt', 'languageCode': 'eng', 'format': 'srt', 'index': '2', 'streamType': '3', 'id': '109344', 'language': 'English', 'default': '1', 'codecID': 'S_TEXT/UTF8', '_elementType': 'Stream'}], 'audioProfile': 'lc', 'file': '/media/hdd1/tv/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW[rarbg]/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW.mkv', 'duration': '1275312', 'videoProfile': 'high', '_elementType': 'Part', 'id': '51480', 'container': 'mkv'}], '_elementType': 'Media', 'id': '50963', 'videoProfile': 'high', 'audioCodec': 'aac', 'width': '1920', 'height': '1080', 'videoFrameRate': '24p', 'aspectRatio': '1.78', 'duration': '1275312', 'container': 'mkv', 'bitrate': '4441'}, {'videoResolution': '1080', 'audioChannels': '2', 'videoCodec': 'h264', 'audioProfile': 'lc', '_children': [{'key': '/library/parts/51481/1486551812/file.mkv', 'size': '707980309', '_children': [{'languageCode': 'eng', 'hasScalingMatrix': '0', 'duration': '1275317', 'chromaSubsampling': '4:2:0', 'frameRate': '23.976', 'width': '1920', 'pixelFormat': 'yuv420p', 'streamType': '1', 'id': '109345', 'frameRateMode': 'cfr', 'refFrames': '4', 'codecID': 'V_MPEG4/ISO/AVC', 'codec': 'h264', 'bitDepth': '8', 'cabac': '1', 'default': '1', 'profile': 'high', 'height': '1080', 'index': '0', 'bitrate': '4441', 'language': 'English', 'scanType': 'progressive', 'level': '40', '_elementType': 'Stream'}, {'codec': 'aac', 'languageCode': 'eng', 'audioChannelLayout': 'stereo', 'selected': '1', 'samplingRate': '48000', 'default': '1', 'id': '109346', 'index': '1', 'profile': 'lc', 'duration': '1275312', 'language': 'English', 'channels': '2', 'codecID': 'A_AAC', '_elementType': 'Stream', 'streamType': '2'}, {'codec': 'srt', 'languageCode': 'eng', 'format': 'srt', 'index': '2', 'streamType': '3', 'id': '109347', 'language': 'English', 'default': '1', 'codecID': 'S_TEXT/UTF8', '_elementType': 'Stream'}], 'audioProfile': 'lc', 'file': '/media/hdd1/tv/Workaholics/Workaholics Season 07/Workaholics.S07E05.Faux.Chella.1080p.CC.WEBRip.AAC2.0.x264-BTW[rarbg].mkv', 'duration': '1275312', 'videoProfile': 'high', '_elementType': 'Part', 'id': '51481', 'container': 'mkv'}], '_elementType': 'Media', 'id': '50964', 'videoProfile': 'high', 'audioCodec': 'aac', 'width': '1920', 'height': '1080', 'videoFrameRate': '24p', 'aspectRatio': '1.78', 'duration': '1275312', 'container': 'mkv', 'bitrate': '4441'}, {'title': 'PhillipMid', '_elementType': 'User', 'id': '9608531'}, {'state': 'playing', 'platformVersion': '2.4.0', 'title': 'TV UE55KU6075', 'model': '', 'vendor': '', 'profile': 'Samsung', 'device': 'Samsung TV', 'machineIdentifier': 'xbixedx5uyp', 'version': '3.0.6 (2.10.8)', 'platform': 'Samsung', 'address': '::ffff:84.211.211.7', '_elementType': 'Player', 'product': 'Plex for Samsung'}, {'audioChannels': 2, 'protocol': 'hls', 'speed': 2.299999952316284, 'container': 'mpegts', 'progress': 66.0999984741211, 'audioCodec': 'aac', 'width': 1280, 'remaining': 184, 'audioDecision': 'copy', 'key': '6d94y2d0b25', 'videoDecision': 'transcode', 'duration': 1275000, 'videoCodec': 'h264', 'complete': False, 'height': 720, '_elementType': 'TranscodeSession', 'context': 'streaming', 'throttled': False}], 'grandparentArt': '/library/metadata/4994/art/1486551832', 'chapterSource': '', 'art': '/library/metadata/4994/art/1486551832', 'parentIndex': '7', 'contentRating': 'TV-MA', 'type': 'episode', 'duration': '1275312', 'grandparentTitle': 'Workaholics', 'parentRatingKey': '17543', 'ratingKey': '21427', 'title': 'Episode 5', 'updatedAt': '1486581424', 'thumb': '/library/metadata/21427/thumb/1486581424', 'grandparentThumb': '/library/metadata/4994/thumb/1486551832', 'grandparentKey': '/library/metadata/4994', 'parentKey': '/library/metadata/17543', 'guid': 'com.plexapp.agents.thetvdb://211751/7/5?lang=en', 'grandparentTheme': '/library/metadata/4994/theme/1486551832', 'grandparentRatingKey': '4994', 'key': '/library/metadata/21427', 'index': '5', 'librarySectionID': '2', 'viewOffset': '754471', 'addedAt': '1486551819', '_elementType': 'Video', 'sessionKey': '177'}]} diff --git a/plex/tmdb.py b/plex/tmdb.py index 2677629..0ce0db2 100755 --- a/plex/tmdb.py +++ b/plex/tmdb.py @@ -3,12 +3,51 @@ # @Author: KevinMidboe # @Date: 2017-02-08 14:00:04 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-02-08 14:06:48 +# @Last Modified time: 2017-02-08 23:19:53 from requests import get +try: + from plexSearch import plexSearch +except ImportError: + from plex.plexSearch import plexSearch tmdbBaseURL = "https://api.themoviedb.org/3/" +def checkPlexExistance(tmdb, plex): + # THIS IS ONLY COMPARED ON YEAR + yearList = [movie["year"] for movie in plex] + print(yearList) + + for movie in tmdb["movies"]: + print(movie["year"]) + movie["exists"] = movie["year"] in str(yearList) + + return tmdb + +def createTMDBResultList(resContent): + movies = [] + tvshows = [] + + for res in resContent["results"]: + if res["media_type"] == "movie": + id = res["id"] + title = res["original_title"] + year = res["release_date"][:4] + poster_path = res["poster_path"] + + movies.append({"id": id, "title": title, "year": year, "poster_path": poster_path}) + + elif res["media_type"] == "tv": + id = res["id"] + name = res["original_name"] + year = res["first_air_date"][:4] + poster_path = res["poster_path"] + + tvshows.append({"id": id, "title": name, "year": year, "poster_path": poster_path}) + + return { "movies": movies, "tvshows": tvshows } + + def tmdbSearch(query, page=1): requestType = "search/multi?" requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712" @@ -23,28 +62,10 @@ def tmdbSearch(query, page=1): if response.status_code == 200: resContent = response.json() - movies = [] - tvshows = [] + plexSearchRes = plexSearch(query) + tmdbSearchRes = createTMDBResultList(resContent) - for res in resContent["results"]: - if res["media_type"] == "movie": - id = res["id"] - title = res["original_title"] - year = res["release_date"][:4] - poster_path = res["poster_path"] - - movies.append( {"id": id, "title": title, "year": year, "poster_path": poster_path} ) - - elif res["media_type"] == "tv": - id = res["id"] - name = res["original_name"] - year = res["first_air_date"][:4] - poster_path = res["poster_path"] - - tvshows.append( {"id": id, "title": name, "year": year, "poster_path": poster_path} ) - - searchResults = { "movies": movies, "tvshows": tvshows } - return searchResults + return checkPlexExistance(tmdbSearchRes, plexSearchRes) if __name__ == "__main__": @@ -55,4 +76,4 @@ if __name__ == "__main__": elif len(sys.argv) > 1: print(tmdbSearch(sys.argv[1])) else: - print(tmdbSearch("star+wars",2)) \ No newline at end of file + print(tmdbSearch("star+wars",1)) \ No newline at end of file