Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Importing python libraries to run script but which libraries?
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
I need to see the printouts. The lines that get printed when it states it located the server
something like the following
Found Emby Server
Name: Some Server Name
Address: http:\\SomeServerAddress
Id: ServerId
It is having a problem parsing the url that is returned by the Emby server. so unless I know what that line reads i do not know how i need to modify it so it will work.
the error is telling me that it is failing to parse "192.168.29.195:8096\Sessions" which would be missing the http:\\ but i accounted for that in the last update and we still have the same error. So i need to know what the exact address is that is given by the Emby server and the printout mentioned above is going to give me exactly that. Once i have that I will be able to modify the URL so it will work.
something like the following
Found Emby Server
Name: Some Server Name
Address: http:\\SomeServerAddress
Id: ServerId
It is having a problem parsing the url that is returned by the Emby server. so unless I know what that line reads i do not know how i need to modify it so it will work.
the error is telling me that it is failing to parse "192.168.29.195:8096\Sessions" which would be missing the http:\\ but i accounted for that in the last update and we still have the same error. So i need to know what the exact address is that is given by the Emby server and the printout mentioned above is going to give me exactly that. Once i have that I will be able to modify the URL so it will work.
Re: Importing python libraries to run script but which libraries?
I ran this script (Copied directly from EG minus my API Key)
And got this screen
Code: Select all
# only the API key is needed
emby_api_key = 'Key'
import requests
import os
import traceback
import socket
import json
from uuid import uuid4 as GUID
from pytube import YouTube
client_id = str(GUID())
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
sock.settimeout(2.0)
broadcast_address = ('255.255.255.255', 7359)
sock.sendto('who is EmbyServer?', broadcast_address)
sock.settimeout(2.0)
try:
data = sock.recv(4096)
except socket.timeout:
eg.PrintError('Could not find an Emby Server')
eg.StopMacro()
eg.Exit()
data = json.loads(data.decode('utf-8'))
eg.Print('Found Emby Server')
eg.Print('Name: ' + data['Name'])
eg.Print('Address: ' + data['Address'])
eg.Print('Id: ' + data['Id'])
headers = {
'Content-Type': "application/json",
'Accept': "application/json",
'x-emby-authorization': 'MediaBrowser',
'Client': 'EmbyTrailers',
'Device': 'Python Script',
'DeviceId': client_id,
'Version': '1.0.0.0',
}
emby_url = data['Address']
session_url = '{0}\Sessions'.format(emby_url)
params = dict(api_key=emby_api_key)
try:
response = requests.get(session_url, headers=headers, params=params)
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
params.update(dict(DeviceId=client_id, Format='json'))
users_url = '{emby_url}/Users'.format(emby_url=emby_url)
items_url = '{emby_url}/Items'.format(emby_url=emby_url)
log_output = 'Emby Trailer Download Stats\n'
try:
response = requests.get(users_url, headers=headers, params=params)
users = response.json()
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
except ValueError:
print response.status_code
print response
eg.StopMacro()
eg.Exit()
else:
params.update(
dict(
IncludeItemTypes='Movie',
Recursive=True,
StartIndex=0,
Fields='RemoteTrailers, Path'
)
)
for user in users:
params['UserId'] = user['Id']
try:
response = requests.get(
items_url,
headers=headers,
params=params
)
films = response.json()
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
except ValueError:
print response.status_code
print response
eg.StopMacro()
eg.Exit()
else:
questionable_trailers = 0
missing_trailers = 0
successful_trailer_downloads = 0
failed_trailer_downloads = 0
for film in films['Items']:
if not film['LocationType'] == 'FileSystem':
continue
if film['LocalTrailerCount'] == 0:
questionable_trailers += 1
film_path = film['Path'].encode('utf-8')
film_file_name = os.path.basename(film_path)
film_directory_name = os.path.dirname(film_path)
film_name = os.path.splitext(film_file_name)[0]
if film_name[-3:-1] == 'CD':
film_name = film_name[:-4]
def download_trailer(trailer_file_name):
global missing_trailers
global successful_trailer_downloads
global failed_trailer_downloads
missing_trailers += 1
for trailer in film['RemoteTrailers']:
trailer_url = trailer['Url'].encode('utf-8')
try:
you_tube = YouTube(trailer_url)
you_tube.set_filename(trailer_file_name)
video = you_tube.filter('mp4')[-1]
video.download(film_directory_name)
successful_trailer_downloads += 1
break
except:
eg.PrintError(
'{0} - {1}'.format(film_name, trailer_url)
)
traceback.print_exc()
else:
failed_trailer_downloads += 1
film_directory_contents = os.listdir(film_directory_name)
if (
'VIDEO_TS' in film_directory_contents or
'BDMV' in film_directory_contents
):
film_directory_name = os.path.join(
film_directory_name,
'trailers'
)
if not os.path.exists(film_directory_name):
os.mkdir(film_directory_name)
for f in os.listdir(film_directory_name):
if f.startswith('trailer'):
break
else:
download_trailer('trailer')
else:
for f in os.listdir(film_directory_name):
if f.startswith(film_name + '-trailer'):
break
else:
download_trailer(film_name + '-trailer')
film_output_template = (
'User: {0}\n'
' Reported Download Count: {1}\n'
' Actual Download Count: {2}\n'
' Successful Downloads: {3}\n'
' Failed Downloads: {4}\n\n'
)
log_output += film_output_template.format(
user.Name,
questionable_trailers,
missing_trailers,
successful_trailer_downloads,
failed_trailer_downloads
)
eg.Print(log_output)
Re: Importing python libraries to run script but which libraries?
Others have chimed in on a thread I have for this on the Emby forums. One suggestion was to look at the EmbyCon code (Written in python) for examples. I'm posting this here in case it helps. https://github.com/faush01/plugin.video ... adutils.py
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
my dumbass had the wrong slash... needed to be a / instead of a \
I change the script there is no need iterate through the users and then iterate the films for that user. it is kind of a dumbass thing to do because a movie is a movie. and it has absoutly nothing to do with the user. The only thing using the user does is return things like favorite or suggestions and it has nothing to do with the library it's self.
So I have this thing simply going through every movie in the library. no reason to make it work more then it needs to.
I change the script there is no need iterate through the users and then iterate the films for that user. it is kind of a dumbass thing to do because a movie is a movie. and it has absoutly nothing to do with the user. The only thing using the user does is return things like favorite or suggestions and it has nothing to do with the library it's self.
So I have this thing simply going through every movie in the library. no reason to make it work more then it needs to.
Code: Select all
# only the API key is needed
emby_api_key = 'Key'
import requests
import os
import traceback
import socket
import json
from uuid import uuid4 as GUID
from pytube import YouTube
client_id = str(GUID())
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
sock.settimeout(2.0)
broadcast_address = ('255.255.255.255', 7359)
sock.sendto('who is EmbyServer?', broadcast_address)
sock.settimeout(2.0)
try:
data = sock.recv(4096)
except socket.timeout:
eg.PrintError('Could not find an Emby Server')
eg.StopMacro()
eg.Exit()
data = json.loads(data.decode('utf-8'))
eg.Print('Found Emby Server')
eg.Print('Name: ' + data['Name'])
eg.Print('Address: ' + data['Address'])
eg.Print('Id: ' + data['Id'])
headers = {
'Content-Type': "application/json",
'Accept': "application/json",
'x-emby-authorization': 'MediaBrowser',
'Client': 'EmbyTrailers',
'Device': 'Python Script',
'DeviceId': client_id,
'Version': '1.0.0.0',
}
emby_url = data['Address']
session_url = '{0}/Sessions'.format(emby_url)
params = dict(api_key=emby_api_key)
try:
session = requests.get(session_url, headers=headers, params=params).json()
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
params.update(
dict(
DeviceId=client_id,
IncludeItemTypes='Movie',
Recursive=True,
StartIndex=0,
Fields='RemoteTrailers, Path',
Format = 'json'
)
)
items_url = '{emby_url}/Items'.format(emby_url=emby_url)
try:
response = requests.get(items_url, headers=headers, params=params)
films = response.json()['Items']
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
except ValueError:
print response.status_code
print response
eg.StopMacro()
eg.Exit()
else:
questionable_trailers = 0
missing_trailers = 0
successful_trailer_downloads = 0
failed_trailer_downloads = 0
for film in films:
if not film['LocationType'] == 'FileSystem':
continue
if film['LocalTrailerCount'] == 0:
questionable_trailers += 1
film_path = film['Path'].encode('utf-8')
film_file_name = os.path.basename(film_path)
film_directory_name = os.path.dirname(film_path)
film_name = os.path.splitext(film_file_name)[0]
if film_name[-3:-1] == 'CD':
film_name = film_name[:-4]
def download_trailer(trailer_file_name):
global missing_trailers
global successful_trailer_downloads
global failed_trailer_downloads
missing_trailers += 1
for trailer in film['RemoteTrailers']:
trailer_url = trailer['Url'].encode('utf-8')
try:
you_tube = YouTube(trailer_url)
you_tube.set_filename(trailer_file_name)
video = you_tube.filter('mp4')[-1]
video.download(film_directory_name)
successful_trailer_downloads += 1
break
except:
eg.PrintError(
'{0} - {1}'.format(film_name, trailer_url)
)
traceback.print_exc()
else:
failed_trailer_downloads += 1
film_directory_contents = os.listdir(film_directory_name)
if (
'VIDEO_TS' in film_directory_contents or
'BDMV' in film_directory_contents
):
film_directory_name = os.path.join(
film_directory_name,
'trailers'
)
if not os.path.exists(film_directory_name):
os.mkdir(film_directory_name)
for f in os.listdir(film_directory_name):
if f.startswith('trailer'):
break
else:
download_trailer('trailer')
else:
for f in os.listdir(film_directory_name):
if f.startswith(film_name + '-trailer'):
break
else:
download_trailer(film_name + '-trailer')
film_output_template = (
'Emby Trailer Download Stats\n'
' Reported Download Count: {1}\n'
' Actual Download Count: {2}\n'
' Successful Downloads: {3}\n'
' Failed Downloads: {4}\n\n'
)
eg.Print(
film_output_template.format(
questionable_trailers,
missing_trailers,
successful_trailer_downloads,
failed_trailer_downloads
)
)
Re: Importing python libraries to run script but which libraries?
No worries, your making good progress, and I think we are past the authentication part of this because it starts iterating through the folders but I still get an error. I think this script was built on an old version of pytube, and there is a change to the version I'm running which I will get into soon but first some screenshots
I googled around a bit, and found a few others have had problems.
https://github.com/nficano/pytube/issues/164
I'm thinking the version of pytube I'm on is 9.2.2-18 because this number is reflected in the name of the file I downloaded when I added the libraries. I hope that at least gives you an idea about what could be going wrong, and thanks again
https://github.com/nficano/pytube/issues/164
I'm thinking the version of pytube I'm on is 9.2.2-18 because this number is reflected in the name of the file I downloaded when I added the libraries. I hope that at least gives you an idea about what could be going wrong, and thanks again
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
new option. you get to pick the resolution you want for the trailer.
Code: Select all
# only the API key is needed
emby_api_key = 'Key'
trailer_resolution = '1080p'
# other choices 360p 720p 480p 240p, 144p
import requests
import os
import traceback
import socket
import json
from uuid import uuid4 as GUID
from pytube import YouTube
client_id = str(GUID())
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
sock.settimeout(2.0)
broadcast_address = ('255.255.255.255', 7359)
sock.sendto('who is EmbyServer?', broadcast_address)
sock.settimeout(2.0)
try:
data = sock.recv(4096)
except socket.timeout:
eg.PrintError('Could not find an Emby Server')
eg.StopMacro()
eg.Exit()
data = json.loads(data.decode('utf-8'))
eg.Print('Found Emby Server')
eg.Print('Name: ' + data['Name'])
eg.Print('Address: ' + data['Address'])
eg.Print('Id: ' + data['Id'])
headers = {
'Content-Type': "application/json",
'Accept': "application/json",
'x-emby-authorization': 'MediaBrowser',
'Client': 'EmbyTrailers',
'Device': 'Python Script',
'DeviceId': client_id,
'Version': '1.0.0.0',
}
emby_url = data['Address']
session_url = '{0}/Sessions'.format(emby_url)
params = dict(api_key=emby_api_key)
try:
session = requests.get(session_url, headers=headers, params=params).json()
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
params.update(
dict(
DeviceId=client_id,
IncludeItemTypes='Movie',
Recursive=True,
StartIndex=0,
Fields='RemoteTrailers, Path',
Format='json'
)
)
items_url = '{emby_url}/Items'.format(emby_url=emby_url)
try:
response = requests.get(items_url, headers=headers, params=params)
films = response.json()['Items']
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
except ValueError:
print response.status_code
print response
eg.StopMacro()
eg.Exit()
else:
questionable_trailers = 0
missing_trailers = 0
successful_trailer_downloads = 0
failed_trailer_downloads = 0
for film in films:
if not film['LocationType'] == 'FileSystem':
continue
if film['LocalTrailerCount'] == 0:
questionable_trailers += 1
film_path = film['Path'].encode('utf-8')
film_file_name = os.path.basename(film_path)
film_directory_name = os.path.dirname(film_path)
film_name = os.path.splitext(film_file_name)[0]
if film_name[-3:-1] == 'CD':
film_name = film_name[:-4]
def download_trailer(trailer_file_name):
global missing_trailers
global successful_trailer_downloads
global failed_trailer_downloads
missing_trailers += 1
for trailer in film['RemoteTrailers']:
trailer_url = trailer['Url'].encode('utf-8')
try:
you_tube = YouTube(trailer_url)
streams = you_tube.streams.filter(
file_extension='mp4',
resolution=trailer_resolution,
progressive=True
).all()
if streams:
stream = streams[0]
stream.download(
output_path=film_directory_name,
filename=trailer_file_name
)
successful_trailer_downloads += 1
break
except:
eg.PrintError(
'{0} - {1}'.format(film_name, trailer_url)
)
traceback.print_exc()
else:
failed_trailer_downloads += 1
film_directory_contents = os.listdir(film_directory_name)
if (
'VIDEO_TS' in film_directory_contents or
'BDMV' in film_directory_contents
):
film_directory_name = os.path.join(
film_directory_name,
'trailers'
)
if not os.path.exists(film_directory_name):
os.mkdir(film_directory_name)
for f in os.listdir(film_directory_name):
if f.startswith('trailer'):
break
else:
download_trailer('trailer')
else:
for f in os.listdir(film_directory_name):
if f.startswith(film_name + '-trailer'):
break
else:
download_trailer(film_name + '-trailer')
film_output_template = (
'Emby Trailer Download Stats\n'
' Reported Download Count: {1}\n'
' Actual Download Count: {2}\n'
' Successful Downloads: {3}\n'
' Failed Downloads: {4}\n\n'
)
eg.Print(
film_output_template.format(
questionable_trailers,
missing_trailers,
successful_trailer_downloads,
failed_trailer_downloads
)
)
Re: Importing python libraries to run script but which libraries?
It looks like it worked. I have to check and see how well it performed but I see new files.
Re: Importing python libraries to run script but which libraries?
But I don't think they have audio unless the codec is incompatible with wmc. Just video
Re: Importing python libraries to run script but which libraries?
This is really wierd. The trailers look fantastic and from what I can tell it got most of my movies but none of them have audio no matter what video player I open them with. I didn't see this coming at all.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
lol. ok. i am hoping you didn't run this on you're production library. because it is going to be a real pain to delete the trailers. especially if you have a large library
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
also have you tried using shark007 codecs?
I would recommend installing it.
I would recommend installing it.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
I also changed the script. apparently there are adaptive and progressive video files. these terms I have never head use to describe the handling of the audio. it's kinda dumb actually to use the term progressive to describe having the audio and video in the same transport stream file. the proper terms are actually mux and demux. mux or multiplexed is a single transport stream file. where as demuxed is a separate audio and video file. Now in the land of who ever made this library they thought the best way would be to default to a demuxed file and to name the argument that will provide a single transport stream "progressive", i really wish i could convey emotion through this thing better then these emoticons the board has. but these 2 are as close as it is going to get
this one is i think supposed to be blushing bit it looks more like a pissed off angry face to me.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
Now i would be curious to know since it defaulted to a demuxed transport stream. did it create 2 files when it downloaded the trailer or did it only download the video. which would be really nutty if it defaults to 2 files but then only saves one of them.
Re: Importing python libraries to run script but which libraries?
I have sharks installed, and I ran it on my production library. I didn't intend to starting out BUT lucky for me none of my actual movie files are .mp4 although I do have some video backgrounds that are. I just did a search of -trailer.mp4 in file explorer, and cleared them all out. I had 83 files with that name but I think I have around 120 video files in my movies library. I'll run your new script soon. I only saw one additional video or audio file for each movie after I ran the script. Thanks for all of the help again.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Importing python libraries to run script but which libraries?
so that's a real hoot. it defaults to demuxing the stream but only saves the video side of it. to funny.
if you run this script. it will remove the trailers
if you run this script. it will remove the trailers
Code: Select all
# only the API key is needed
emby_api_key = 'Key'
import requests
import os
import traceback
import socket
import json
from uuid import uuid4 as GUID
from pytube import YouTube
client_id = str(GUID())
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
sock.settimeout(2.0)
broadcast_address = ('255.255.255.255', 7359)
sock.sendto('who is EmbyServer?', broadcast_address)
sock.settimeout(2.0)
try:
data = sock.recv(4096)
except socket.timeout:
eg.PrintError('Could not find an Emby Server')
eg.StopMacro()
eg.Exit()
data = json.loads(data.decode('utf-8'))
eg.Print('Found Emby Server')
eg.Print('Name: ' + data['Name'])
eg.Print('Address: ' + data['Address'])
eg.Print('Id: ' + data['Id'])
headers = {
'Content-Type': "application/json",
'Accept': "application/json",
'x-emby-authorization': 'MediaBrowser',
'Client': 'EmbyTrailers',
'Device': 'Python Script',
'DeviceId': client_id,
'Version': '1.0.0.0',
}
emby_url = data['Address']
session_url = '{0}/Sessions'.format(emby_url)
params = dict(api_key=emby_api_key)
try:
session = requests.get(session_url, headers=headers, params=params).json()
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
params.update(
dict(
DeviceId=client_id,
IncludeItemTypes='Movie',
Recursive=True,
StartIndex=0,
Fields='RemoteTrailers, Path',
Format='json'
)
)
items_url = '{emby_url}/Items'.format(emby_url=emby_url)
try:
response = requests.get(items_url, headers=headers, params=params)
films = response.json()['Items']
except requests.HTTPError:
traceback.print_exc()
eg.StopMacro()
eg.Exit()
except ValueError:
print response.status_code
print response
eg.StopMacro()
eg.Exit()
else:
for film in films:
if not film['LocationType'] == 'FileSystem':
continue
if film['LocalTrailerCount']:
film_path = film['Path'].encode('utf-8')
film_directory_name = os.path.dirname(film_path)
film_directory_contents = os.listdir(film_directory_name)
if (
'VIDEO_TS' in film_directory_contents or
'BDMV' in film_directory_contents
):
film_directory_name = os.path.join(
film_directory_name,
'trailers'
)
if not os.path.exists(film_directory_name):
continue
film_directory_contents = os.listdir(film_directory_name)
for f in film_directory_contents :
if f.startswith('trailer')and f.endswith('mp4'):
os.remove(os.path.join(film_directory_name, f))
