Pages

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, August 24, 2020

Python script to cut and merge videos using ffmpeg

Python script to help cut and merge multiple videos .



Script : https://github.com/sterin501/PythonScripts/tree/master/cutMergeVideo

Install :
Install the ffmpeg



Config :
a. Copy the videos to same folder
b. Put the details in details.txt

Like :
VideoFilename startpoint endpoint
c. Run the script -- cutMerge.py





#!/bin/python

import time,subprocess

## ffmpeg -i 2.mkv -ss 00:10:03.500 -to 00:20:08.500 -async 1 cut.mp4 -y
## ffmpeg -i "concat:input1|input2" -codec copy output

#subprocess.Popen("pwd", shell=True)

processList=[]

def creatCutCommad(inputfile,time1,time2,outputfile):
    return "ffmpeg -i "+inputfile+"  -ss "+time1+ "  -to "+time2+"  -async 1   "+ outputfile+" -y"

def runCommand(comand):
        print "running __________________________________"+comand
        subprocess.Popen(comand+" ; echo '1' >> done ",shell=True,stdout=subprocess.PIPE)




if __name__ == '__main__':
    #print creatCutCommad("2.mkv","00:10:03.500","00:20:08.500","cut.mp4")
    filename="details.txt"
    temp=[]
    comands=[]
    part=0
    paS=""

    with open (filename) as engfin:
        for line in engfin:
           if line.startswith('#'):
                 continue
           else:
                cc=line.split()
                comands.append(creatCutCommad(cc[0],cc[1],cc[2],"part"+str(part)+".mp4")    )
                paS=paS+"file part"+str(part)+".mp4\n"
                part=part+1

    f = open("mylist.txt", "w")
    f.write(paS)
    ca='ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4'
    #comands.append(ca)
    #print comands
    f = open("done", "w")
    f.write("")

    for kk in comands:
        runCommand(kk)
    while True:
        print "checking cut job  status\n\n\n "
        time.sleep (2)
        num_lines = sum(1 for line in open('done'))
        print "number of lines " + str (num_lines)
        print "part " + str (part)
        if num_lines == part:
            runCommand(

Monday, July 13, 2020

Python client for ssh


Sample code to access ssh by providing username and password 
#!/usr/bin/python3

#from __future__ import print_function

import os
import socket
from ssh2.session import Session


host = 'myserver'
user = os.getlogin()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 22))

session = Session()
session.handshake(sock)
session.userauth_password('oracle', 'mypassword')

channel = session.open_session()
channel.execute('date ')
print (channel.read())

#size, data = channel.read()   ## More managed reading like size etc 
#while size > 0:
#    print(data)
#    size, data = channel.read()

channel.close()



#print("Exit status: %s" % channel.get_exit_status())  ## Shows exit status
## pip install ssh2-python

Wednesday, May 6, 2020

Python script to download and run UCM 12c applet

Python script to  download and run admin 
applets of WCC 12c 



#!/usr/bin/python3

import requests,sys,os


## Pass the UCM URL like http://UCMIP:PORT
USERNAME = "weblogic"
PASSWORD = "xx"

print ('run like ./appletDownload.py  http://UCMIP:PORT  <username> <password>' )
print (sys.argv[1])
if (sys.argv[1]):
    URL = sys.argv[1]
else:
    print ('run like ./appletDownload.py  http://UCMIP:PORT  <username> <password>')
    exit()



if (len (sys.argv) ==3 ):
  if (sys.argv[2]):
     USERNAME=sys.argv[2]
  if (sys.argv[3]):
     PASSWORD=sys.argv[3]

LOGIN_URL= URL+"/cs/login/j_security_check?j_username="+USERNAME+"&j_password="+PASSWORD
session_requests = requests.session()

response=session_requests.post(LOGIN_URL)
cookie = response.headers.get('Set-Cookie')
print (cookie)
if ('IntradocLoginState=1' in cookie):
     print ('Authenticated')
     response=session_requests.get(URL+'/cs/idcplg?IdcService=GET_JNLP&App=RepoMan')
     file = open("/tmp/applet.jnlp", 'wb+')
     file.write(response.content)
     file.close()
     print ('applet saved & Starting ')
     os.popen("javaws /tmp/applet.jnlp")

else:
    print ('In Valid login')
#print (response.info())

Friday, February 9, 2018

Setting http_proxy based on IP address


In office http_proxy is required . This script will help to set the http_proxy

1. Create python script to get IP

2. Add in alias for every bash login


Python Script :

 1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31
#!/bin/python





import socket



officeProxy='Myoffice:80'



def get_ip():

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    try:

        # doesn't even have to be reachable

        s.connect(('10.255.255.255', 1))

        IP = s.getsockname()[0]

    except:

        IP = '127.0.0.1'

    finally:

        s.close()

    return IP









def setProxyINBashShell():

    if get_ip().startswith("10"):

      print officeProxy



    else :

      print ''



if __name__ == '__main__':

    setProxyINBashShell()


2. Alias

#### Smart Proxy
 http_proxy=`/home/sterin/Templates/shell/smartProxy.py` 
 export http_proxy=$http_proxy



Code is highlighted using : http://hilite.me/


Wednesday, September 6, 2017

Python script to get Google Search results









Python script to get Google Search results


Location :
https://github.com/sterin501/PythonScripts/blob/master/TorrentScrap/googleSearch.py


Requirements


In windows torrentSearch.exe can be used


1. Install json


    pip install json


2.Install BeautifulSoup4

    pip install BeautifulSoup4
3.Install requests

    pip install requests




Option A : ( Best option)


Scrap using Google API , is the best option . It provide data in json format .


1. Get Google API key
2. Change the settings for custom search to use entire web






Option B: Scrap from google.com


This is not  good option , google changes output format every time

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/python
import  json,requests,bs4


session_requests = requests.session()

configJson=json.load(open('config.json'))

googleResultCount=configJson['googleResultCount']
googleKey=configJson['googleKey']
gooelcx=configJson['gooelcx']
googleURLend=configJson['googleURLend']

proxyDict = {
  "http" : configJson['proxyserver'] ,
  "https":configJson['proxyserver'],
}


def getGoogleAPI(keyword):

  pnr_data =                 {

                            'q'      : keyword,
                        'googleHost' : 'google.co.in',
                            'num' :  googleResultCount,
                            'key'    : googleKey,
                            'cx'     : gooelcx
                              }
  url="https://www.googleapis.com/customsearch/v1"
  result = session_requests.get(url,params=pnr_data,proxies=proxyDict)
  results = json.loads(result.content)
  data = results['items']
  URLS=[]
  for kk in data:
    print kk['link']
    URLS.append(kk['link'])
  return URLS 


def getFrommGoogleCOM(keyword):
    pnr_data =                 {


                            'q'      : keyword,
                            'gws_rd' : "cr"
                              }
   
    url="https://www.google.co.in/search"
    result = session_requests.get(url,params=pnr_data,proxies=proxyDict)
    #print result.content
    soup = bs4.BeautifulSoup(result.content,"lxml")
    #with open ("result.html", "r") as myfile:
    #   LKD = myfile.read()
    #soup =   bs4.BeautifulSoup(LKD,"lxml") 
    hrf=soup.find_all('a', href=True)
    URLS=[]
    for kk in hrf:
      url1 = kk['href']
      if  url1.startswith("/url?q="):
           url2=url1.split("http")[-1]
           url3=url2.split(googleURLend)[0]
           URLS.append("http"+url3)
    print URLS



 
if __name__ == '__main__':
 URLS=getGoogleAPI("malayalam")
 print URLS
 getFrommGoogleCOM("Ajith lv")









Wednesday, August 23, 2017

Python script to get valid tamilrockers domain and get latest malayalam movie links









Python script to get valid tamilrockers domain and get latest malayalam movie links


Location :


Requirements


In windows torrentSearch.exe can be used


1. Install lxml


    pip install lxml
    pip install lxml==3.6.0

2.Install BeautifulSoup4

    pip install BeautifulSoup4

3.Install requests

    pip install requests

4. Run the server script :
    ./torrentSearch.py


Read me


1. It will search for valid domain based from domain.txt
2. From google search result , it will check each and very URL 
3. One valid torrent site found, it will look for malayalam folder
4. it will save the films on movie.txt
5. Comment # starts of the line will make script to look for movie name again from torrent site
6. Delete the movie Name from movie.txt , script will look for movie Link again from torrent site

Example of output :

./torrentSeacrch.py 
From history domain name is lv
Trying with http://tamilrockers.lv
Blocked
Will search in google 
https://play.google.com/store/apps/details?id=tamilrockers.movies&hl=en
http://9to5google.com/2016/12/01/how-to-download-movies-and-shows-in-the-netflix-app-for-android/
http://tamilrockers.nz/
https://www.youtube.com/watch?v=pYWKcRlFnOM
http://playtamil.in/Tamilrockers-movies/
[u'http://tamilrockers.nz']
Trying with http://tamilrockers.nz
GoodURL URL
working domain http://tamilrockers.nz
will do things with http://tamilrockers.nz/index.php/forum/124-malayalam-movies/
^^^^^^^^^^^^^^^^^^^^^^^^^^^
New Movie found Avarude Raavukal (2017) 
Download Link
http://tamilrockers.nz/index.php/topic/59461-avarude-raavukal-2017-malayalam-dvdrip-xvid-mp3-700mb-esubs/       
***************************
New Movies ['Avarude Raavukal (2017) ']



Tuesday, July 18, 2017

Python script to scrape score from cricbuzz with desktop alert









Python script to scrape score from cricbuzz with desktop alert


Location :


Requirements




1. Install lxml


    pip install lxml
    pip install lxml==3.6.0


2.Install BeautifulSoup4

    pip install BeautifulSoup4
3.Install pypiwin32 in windows for desktop alert

    pip install pypiwin32

in Linux



    pip install plyer


4. Run the script

























Alert (gnome)