Coder Social home page Coder Social logo

dantegpt / upload-video-to-tiktok-instagram-twitter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from automation9417/upload-video-to-tiktok-instagram-twitter

0.0 0.0 0.0 36.29 MB

10 lines of Python code to upload video to TikTok, Instagram, Twitter

License: Apache License 2.0

Python 100.00%

upload-video-to-tiktok-instagram-twitter's Introduction

Only 10 lines of python code to upload video to TikTok, Instagram, Twitter

First, let's look at the running video.

upload video to Tiktok, Instagram, Twitter

Material Prepared

An mp4 video file, because twitter has a limit on the length of uploaded videos, a shortened video file has been prepared. A cover image for Instagram, TikTok uses the first frame of the video as cover.

media

Run Python Code

git clone https://github.com/automation9417/automation-samples.git
  • open the folder 'UploadVideo' in Visual Studio Code.
  • open sample.py in Visual Studio Code.
  • open the chrome browser (guarantee that there is only one chrome window, explained later), open 3 tabs respectively, open and login TikTok, Twitter and Instagram.
  • press F5 to debug the sample or press CTRL+F5 to run sample. The video that comes with the sample will be uploaded, and you can also modify code to your own video content:
caption = 'Clicknium introduction'
cover_image = os.path.join(os.getcwd(), "media", "logo.png")
video_file = os.path.join(os.getcwd(), "media", "clicknium_introduction.mp4")
upload_tiktok.upload(caption, video_file)
short_video_file = os.path.join(os.getcwd(), "media", "short_introduction.mp4")
upload_twitter.upload(caption, short_video_file)
upload_instagram.upload(caption, cover_image, video_file)

Implementation

Here is an example of uploading a video to Instagram, uploading a video to TikTok and Twitter is a similar process.

  • Get the open browser tab by attaching the browser, and then navigate to the Instagram Home page.
tab = cc.chrome.attach_by_title_url(url="https://*instagram.com/*")
tab.goto("https://www.instagram.com/")
  • Click the 'add post' button, all web page elements here are recorded by Clicknium Recorder.
tab.find_element(locator.chrome.instagram.svg_add_post).click()
  • Click the 'Select from computer' button to pop up a file selection dialog box. Due to browser security restrictions, click here by simulating a mouse.
tab.find_element(locator.chrome.instagram.button_select_file).click(by='mouse-emulation')
  • Using Clicknium desktop automation to select video file and click open button.
ui(locator.chrome.edit_file).set_text(video_file, by='set-text')
ui(locator.chrome.button_open).click(by='control-invocation')

A special note here is that I changed the recorded locator 'edit_file' and 'button_open': file locator

file2 locator

Changed the window matching Name to the wildcard *, because uploading videos to TikTok and Twitter also requires the operation of the file selection dialog. In order to avoid repeated recording, the wildcard is used to match the window to achieve reuse. Therefore, the previous steps require only one Chrome browser window to ensure that the window can be correctly matched.

  • Click the 'next' button, then select the cover image, the code is similar to the above.
  • Enter the text you want to send, then click 'Share' button.
tab.find_element(locator.chrome.instagram.textarea).set_text(caption)
tab.find_element(locator.chrome.instagram.button_share).click()
  • Wait for the upload to succeed, the time required varies according to the size of the video.
tab.wait_appear(locator.chrome.instagram.h2_yourposthasbeenshared, wait_timeout=120)

Uploading a video to Instagram requires a few more steps to upload a cover image. The following is the complete code for uploading a video to Twitter. It only takes 9 lines of code.

tab = cc.chrome.attach_by_title_url(url="https://*twitter.com/*")
tab.goto("https://twitter.com/compose/tweet")
tab.find_element(locator.chrome.twitter.div).set_focus()
cc.send_text(tweet)
tab.find_element(locator.chrome.twitter.svg).click()
ui(locator.chrome.edit_file).set_text(video_file, by='set-text')
ui(locator.chrome.button_open).click(by='control-invocation')
tab.wait_appear(locator.chrome.twitter.video)
tab.find_element(locator.chrome.twitter.span_tweet).click()

You are welcome to comment on the needs of uploading videos to other video platforms, and I can provide more sample code.

upload-video-to-tiktok-instagram-twitter's People

Contributors

automation9417 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.