|
General Discussion General discussion about SageTV and related companies, products, and technologies. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
Need Python help .... ChannelsDVR Json to properties,
I have a Python Script to parse a JSON file ... I can Parse and write the output but I would like it to be in Sage Properties format ... But I am having a brain
fart .. Trying to get Channels DVR recordings to import correctly in SageTV using property files. Json File ... Code:
{"Description":"Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo.","Episode":0,"Genres":["Drama"],"IsMovie":true,"IsNews":false,"IsSports":false,"MetadataGenerator":"Channels DVR","OriginalBroadcastDateTime":"1992-12-11T00:00:00Z","RecordedDateTime":"2021-05-23T03:00:00Z","Season":0,"SubTitle":"","Title":"A Few Good Men (1992)"} My Simple Script Code:
#! /usr/bin/python import json json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json' with open(json_file) as json_data: data = json.load(json_data) print (data['Title'], file=open('c:/python/output.txt', 'w')) print (data['Description'], file=open('c:/python/output.txt', 'a')) print (data['Genres'], file=open('c:/python/output.txt', 'a')) print (data['OriginalBroadcastDateTime'], file=open('c:/python/output.txt', 'a')) Code:
A Few Good Men (1992) Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo. ['Drama'] 1992-12-11T00:00:00Z Code:
Title=A Few Good Men (1992) Year=1992 Genre=Movie/Drama Description=Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo. Mediatype=Movie
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 05-23-2021 at 09:10 AM. |
#2
|
|||
|
|||
Well I am getting there ....
Code:
#! /usr/bin/python import json json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json' with open(json_file) as json_data: data = json.load(json_data) print ('Title=',data['Title'], file=open('c:/python/output.txt', 'w')) print ('Description=',data['Description'], file=open('c:/python/output.txt', 'a')) print ('Genre=',data['Genres'], file=open('c:/python/output.txt', 'a')) print ('Year=',data['OriginalBroadcastDateTime'], file=open('c:/python/output.txt', 'a')) Code:
Title= A Few Good Men (1992) Description= Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo. Genre= ['Drama'] Year= 1992-12-11T00:00:00Z
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. |
#3
|
|||
|
|||
I’ve never really done any Python code but try:
Code:
#! /usr/bin/python import json json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json' with open(json_file) as json_data: data = json.load(json_data) json_data.close() outfile=open('c:/python/output.txt', 'w') print (“Title={}”.format(data['Title']), file=outfile) print (“Description={}”.format(data['Description']), file=outfile) print (“Genre={}”.format(data['Genres']), file=outfile) print (“Year={}”.format(data['OriginalBroadcastDateTime']), file=outfile) outfile.close()
__________________
Windows Installer Last edited by wnjj; 05-23-2021 at 10:22 AM. |
#4
|
|||
|
|||
That is Great this is my output from your script. .. I just have to manipulate the year and genre somehow .... I am just studying Python thanks for your help.
Code:
Title=A Few Good Men (1992) Description=Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo. Genre=['Drama'] Year=1992-12-11T00:00:00Z Genre=Drama Year=1992
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 05-23-2021 at 10:42 AM. |
#5
|
||||
|
||||
haven't tested but you might try:
#! /usr/bin/python import json import datetime json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json' with open(json_file) as json_data: data = json.load(json_data) json_data.close() outfile=open('c:/python/output.txt', 'w') .strftime(current_day, "%m/%d/%Y") print (“Title={}”.format(data['Title']), file=outfile) print (“Description={}”.format(data['Description']), file=outfile) print (“Genre={}”.format(data['Genres'].replace("'[]","")), file=outfile) print (“Year={}”format(datetime.date..strftime(data['OriginalBroadcastDateTime'],"%Y-%m-%d")), file=outfile) outfile.close() |
#6
|
|||
|
|||
Quote:
I think the formatting got messed up when posted .... but I will research the replace. Code:
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> #! /usr/bin/python >>> >>> import json >>> import datetime >>> >>> json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json' >>> >>> with open(json_file) as json_data: ... data = json.load(json_data) File "<stdin>", line 2 data = json.load(json_data) ^ IndentationError: expected an indented block >>> >>> json_data.close() Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'json_data' is not defined >>> >>> outfile=open('c:/python/output.txt', 'w') >>> .strftime(current_day, "%m/%d/%Y") File "<stdin>", line 1 .strftime(current_day, "%m/%d/%Y") ^ SyntaxError: invalid syntax >>> print ("Title={}".format(data['Title']), file=outfile) Traceback (most recent call last): File "<stdin>", line 1, in <module>
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. |
#7
|
||||
|
||||
Because Genres is typically an array.. you might try...
Code:
print (“Genre={}”.format(",".join(data['Genres'])), file=outfile)
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#8
|
|||
|
|||
Quote:
__________________
Windows Installer |
#9
|
||||
|
||||
I suspect so, IF you only wanted the first one. But, in Sage properties, the Genre field is an array field and if multiple genres are listed then the video gets put into each genre. So, I would think you'd want to specify all possible genres. But if not, then [0] should get the first one.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#10
|
|||
|
|||
For the year, split should work:
Code:
print (“Genre={}”.format(data['Genres'][0]), file=outfile) print (“Year={}”.format(data['OriginalBroadcastDateTime'].split(“-“)[0]), file=outfile)
__________________
Windows Installer Last edited by wnjj; 05-23-2021 at 02:09 PM. |
#11
|
||||
|
||||
also, python is very format/indentation specific
So the actions that you want taken with you "with open" need to be indented with open(json_file) as json_data: data = json.load(json_data) also, when you use "with open" you don't need to do the close |
#12
|
|||
|
|||
I'm a regex fan and don't trust the original broadcast date to be the film release year, perhaps channels is non standard.
Code:
import re title = 'A Few Good Men (1992)' year = re.search(r'\(([12]\d{3})\)$', title) if year != None: print (year.group(1)) |
#13
|
|||
|
|||
Thanks everyone ... some do have multiple Genres ... I have learned a lot today from you guys thanks for your time.
Code:
#! /usr/bin/python import json json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json' with open(json_file) as json_data: data = json.load(json_data) json_data.close() outfile=open('c:/python/output.txt', 'w') print ("Title={}".format(data['Title']), file=outfile) print ("Description={}".format(data['Description']), file=outfile) print ("Genre={}".format(",".join(data['Genres'])), file=outfile) print ("Year={}".format(data['OriginalBroadcastDateTime'].split("-")[0]), file=outfile) outfile.close() Code:
Title=A Few Good Men (1992) Description=Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo. Genre=Drama Year=1992
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 05-23-2021 at 04:49 PM. |
#14
|
|||
|
|||
Quote:
__________________
Windows Installer |
#15
|
|||
|
|||
Quote:
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. |
#16
|
|||
|
|||
I created one for TV Shows and it also works great ....
Code:
print ("Title={}".format(data['Title']), file=outfile) print ("EpisodeName={}".format(data['SubTitle']), file=outfile) print ("SeasonNumber={}".format(data['Season']), file=outfile) print ("EpisodeNumber={}".format(data['Episode']), file=outfile) print ("Description={}".format(data['Description']), file=outfile) print ("Genre={}".format("/".join(data['Genres'])), file=outfile) print ("Year={}".format(data['OriginalBroadcastDateTime'].split("-")[0]), file=outfile) outfile.close() Code:
Title=Law & Order: Criminal Intent EpisodeName=Three-in-One SeasonNumber=9 EpisodeNumber=16 Description=When a real estate agent's body is discovered, Nichols must rely on his father. Genre=Crime drama/Docudrama Year=2010
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 05-23-2021 at 06:08 PM. |
#17
|
|||
|
|||
This is the way I run it using good old DIRMON2 ... target JSON must exist MPG and must not exist mpg.properties. Thanks to all that contributed.
my batch file to call the Scripts. channels2sageFinal.bat Code:
set filein=%1 findstr /c:"IsMovie\":true," %filein% %filein% Set isMovie=%ERRORLEVEL% if "%~x1" EQU ".json" set propout=%filein:.json=.mpg.properties% copy "%~f1" C:\Python\channels2sage.json if %isMovie% EQU 0 python.exe c:\Python\sageMovie.py if %isMovie% NEQ 0 python.exe c:\Python\sageTV.py copy c:\Python\channels2sage.properties %propout% exit sageMovie.py Code:
#! /usr/bin/python import json json_file = 'C:\Python\channels2sage.json' with open(json_file) as json_data: data = json.load(json_data) json_data.close() outfile=open('c:/python/channels2sage.properties', 'w') print ("Title={}".format(data['Title']), file=outfile) print ("Description={}".format(data['Description']), file=outfile) print ("Genre=Movie/{}".format("/".join(data['Genres'])), file=outfile) print ("Year={}".format(data['OriginalBroadcastDateTime'].split("-")[0]), file=outfile) outfile.close() sageTV.py Code:
#! /usr/bin/python import json json_file = 'C:\Python\channels2sage.json' with open(json_file) as json_data: data = json.load(json_data) json_data.close() outfile=open('c:/python/channels2sage.properties', 'w') print ("Title={}".format(data['Title']), file=outfile) print ("EpisodeName={}".format(data['SubTitle']), file=outfile) print ("SeasonNumber={}".format(data['Season']), file=outfile) print ("EpisodeNumber={}".format(data['Episode']), file=outfile) print ("Description={}".format(data['Description']), file=outfile) print ("Genre={}".format("/".join(data['Genres'])), file=outfile) print ("Year={}".format(data['OriginalBroadcastDateTime'].split("-")[0]), file=outfile) outfile.close() Code:
Title=Tracking a Killer (2021) Description=A woman tries to prove her daughter's innocence after police accuse her of murdering a friend. Genre=Movie/Thriller/Mystery Year=2021 Code:
Title=Star Trek: The Next Generation EpisodeName=Chain of Command SeasonNumber=6 EpisodeNumber=11 Description=Jellico and the Enterprise try to rescue Picard from Cardassian torture. Genre=Science fiction/Fantasy/Adventure Year=1992
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 05-24-2021 at 05:25 PM. |
#18
|
|||
|
|||
How do you manage the opposite of this? Do you have a script to automatically import sagetv library into channels dvr for outside streaming?
|
#19
|
|||
|
|||
MCEBUDDY is what I use to rename Sage Recordings ... SageTV is the worst as far as naming convention. Plus it puts everything in 1 Folder. Any series I want to keep I use EMBY because it organizes them quite nicely and they finally added a comskip plugin. I am trying to streamline the process and getting away from renaming and transcoding recordings. It is much easier to import recordings into SageTV then it is to import Sage recordings to other APPS.
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 02-21-2022 at 11:01 PM. |
#20
|
|||
|
|||
I wonder if there is a way to adjust the Plex Scanner to do this for Channels dvr.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|