This remind me I need finish and test next version

Code: Select all
#----------------------------------------------------------------------
# Copyright (c) 2012, and7ey@gmail.com
#
# This script opens the file given as the first command line argument
# at Samsung's TV Media Player (tested with UE46B8000).
#
# To be used with Python 2.5 on Windows.
#
# TV should be switched on.
# Remote LAN Control service should be started on TV (http://wiki.samygo.tv/index.php5/Content_Library_applications_list#Remote_LAN_Control)
#
# Change your TV's IP below and check the sequence of keys in the code to start.
#
#----------------------------------------------------------------------
#coding=utf-8
#!/usr/bin/env python
import sys
import telnetlib
import socket
import time
import os.path
import msvcrt
TV_IP = "192.168.1.5"
TV_LAN_REMOTE_PORT = 2345
# list of key_codes is available at
# http://forum.samygo.tv/viewtopic.php?f=5&t=190&start=20#p4730
def send_key(key_code, pause):
try:
tn = telnetlib.Telnet(TV_IP, TV_LAN_REMOTE_PORT)
tn.write(str(int(key_code, 16)) + "\n") # convert hex value to dec
tn.close()
time.sleep(pause)
except socket.error, (ecode, reason): # socket.error is part of IOError since Python 2.6
if ecode == 10061:
print "ERROR: No connection with Remote LAN Control service on TV. Please start it."
elif ecode == 10060:
print "ERROR: No connection with TV. Please switch it on."
print "ERROR: " + str(ecode) + ": " + reason
raw_input("Press Enter...")
sys.exit(0)
print "If you've just switched the TV on, wait 20 secs for NFS share to connect. Otherwise, press any key to continue."
for i in range(20):
if msvcrt.kbhit():
msvcrt.getch()
break
print("Time passed: " + str(i+1))
time.sleep(1)
print "Moving to Media Player screen, NFS share..."
# pressing keys to open Media Player on TV and according Video folder
send_key("8C", 3) # KEY_8C_MEDIA.P
send_key("62", 1) # KEY_62_RIGHT
send_key("62", 1) # KEY_62_RIGHT
send_key("68", 1) # KEY_68_ENTER
send_key("68", 1) # KEY_68_ENTER
send_key("62", 1) # KEY_62_RIGHT
send_key("62", 1) # KEY_62_RIGHT
send_key("68", 1) # KEY_68_ENTER
print "Movement completed."
# trying to identify how many times we should press RIGHT key
file_seq_number = 0
try:
directory, file = os.path.split(sys.argv[1])
# http://stackoverflow.com/questions/11782109/how-to-get-sequence-number-of-the-file-in-the-folder
def sort_func(fname):
# Russian directories, English directories, Russian files, then English files
fullname = os.path.join(directory,fname)
isRussian = any(ord(x) > 127 for x in fullname)
isDirectory = os.path.isdir(fullname)
return (not isDirectory, not isRussian, fullname)
files = sorted(os.listdir(directory), key=sort_func)
file_seq_number = files.index(file) + 1
except IndexError:
print "ERROR: No command line arguments given."
if file_seq_number>0:
print "Moving to the according file #%d (%s)..." % (file_seq_number, file)
# pressing RIGHT key to highlight the file
for i in range(file_seq_number):
send_key("62", 1)
print("Completed.")