Python; Upload Video to Facebook with Youtube URL | Open Source Projects — Learn Python

#qpy:console

 

access_token

=

“”

 

import

platform

import

subprocess

import

os

,

sys

 

if

platform

.

platform

(

)

.

startswith

(

“Linux”

)

:

    

try

:

        

import

requests

    

except

:

        

arg

=

“pip install requests”

        

os

.

system

(

sys

.

executable

+

” “

+

sys

.

prefix

+

“/bin/”

+

arg

)

        

os

.

execv

(

sys

.

executable

,

[

‘python’

]

+

sys

.

argv

)

    

try

:

        

from

requests_toolbelt

import

MultipartEncoder

    

except

:

        

arg

=

“pip install requests_toolbelt”

        

os

.

system

(

sys

.

executable

+

” “

+

sys

.

prefix

+

“/bin/”

+

arg

)

        

os

.

execv

(

sys

.

executable

,

[

‘python’

]

+

sys

.

argv

)

else

:

    

try

:

        

import

requests

    

except

:

        

subprocess

.

call

(

[

“python”

,

“-m”

,

“pip”

,

“install”

,

“requests”

]

)

        

import

requests

    

try

:

        

from

requests_toolbelt

import

MultipartEncoder

    

except

:

        

subprocess

.

call

(

[

“python”

,

“-m”

,

“pip”

,

“install”

,

“requests_toolbelt”

]

)

        

from

requests_toolbelt

import

MultipartEncoder

        

        

if

platform

.

platform

(

)

.

startswith

(

“Linux”

)

:

    

try

:

        

import

androidhelper

        

droid

=

androidhelper

.

Android

(

)

        

video_url

=

droid

.

dialogGetInput

(

‘Facebook Video Url’

,

‘Link girin:’

,

droid

.

getClipboard

(

)

.

result

)

.

result

    

except

:

        

video_url

=

raw_input

(

“link gir: “

)

else

:

    

from

Tkinter

import *

    

import

ttk

    

root

=

Tk

(

)

    

root

.

title

(

“Your Link”

)

    

root

.

resizable

(

width

=

FALSE

,

height

=

FALSE

)

    

pgen

=

500

    

pyuks

=

100

    

ekrangen

=

root

.

winfo_screenwidth

(

)

    

x

=

(

ekrangen

pgen

)

/

2

    

root

.

geometry

(

“%dx%d+%d+%d”

%

(

pgen

,

pyuks

,

x

,

200

)

)

    

def

clp

(

event

=

None

)

:

        

global

video_url

        

video_url

=

entry

.

get

(

)

        

root

.

destroy

(

)

    

entry

=

Entry

(

root

,

width

=

80

)

    

entry

.

pack

(

pady

=

15

)

    

ttk

.

Style

(

)

.

configure

(

“prk.TButton”

,

padding

=

6

,

relief

=

“flat”

,

background

=

“#EBE6E6”

,

foreground

=

“#347D2B”

,

font

=

(

“DejaVuSans”

,

11

,

“bold”

)

)

    

tara

=

ttk

.

Button

(

root

,

text

=

“Tamam”

,

style

=

‘prk.TButton’

,

command

=

clp

,

width

=

22

)

    

tara

.

pack

(

)

    

entry

.

insert

(

0

,

root

.

clipboard_get

(

)

)

    

root

.

bind

(

“<Return>”

,

clp

)

    

mainloop

(

)

 

def

put_video

(

video_url

,

page_id

,

access_token

,

description

,

title

)

:

    

video_file_name

=

title

    

local_video_file

=

video_url

    

path

=

“{0}/videos”

.

format

(

page_id

)

    

fb_url

=

“https://graph-video.facebook.com/{0}?access_token={1}”

.

format

(

            

path

,

access_token

)

    

print

fb

_

url

    

m

=

MultipartEncoder

(

        

fields

=

{

‘description’

:

description

,

                

‘title’

:

title

,

                

‘comment’

:

‘postvideo’

,

                

‘file_url’

:

video

_

url

}

    

)

    

r

=

requests

.

post

(

fb_url

,

headers

=

{

‘Content-Type’

:

m

.

content_type

}

,

data

=

m

)

    

if

r

.

status_code

==

200

:

        

j_res

=

r

.

json

(

)

        

facebook_video_id

=

j_res

.

get

(

‘id’

)

        

print

(

“facebook_video_id = {0}”

.

format

(

facebook_video_id

)

)

        

print

(

“uploaddone, after 1,2 min will show ur profile”

)

    

else

:

        

print

(

“Facebook upload error: {0}”

.

format

(

r

.

text

)

)

 

print

video_url

page_id

=

“me”

description

=

raw_input

(

“Video descp: “

)

title

=

raw_input

(

“Video tittle: “

)

 

put_video

(

video_url

,

page_id

,

access_token

,

description

,

title

)