Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Twitter videos to mp4
#1
Lightbulb 
Insert a list of twitter video links in the "links" variable and specify where you want it to be dumped.

Code:
import requests
import json
import urllib.request
import os

path = r"path\to\directory"

links = """
twitter-video-link-1
twitter-video-link-2
"""

links = links.split("\n")
fails = []
for link in links:
    if link == "":
        continue
    twt_id = link.split("/")[5].split("?", 1)[0]
    if os.path.exists(r'{}\{}.mp4'.format(path, twt_id)):
        continue
    r = requests.get("https://tweetpik.com/api/tweets/{}/video".format(twt_id))
    data = json.loads(r.text)
    print("Downloading", twt_id)
    try:
        variants = data["variants"]
        bitrate = 0
        for variant in variants:
            if variant["bitrate"] > bitrate:
                bitrate = variant["bitrate"]
                dwld_link = variant["url"]

        urllib.request.urlretrieve(dwld_link, r'{}\{}.mp4'.format(path, twt_id))
    except:
        print("Failed to download", twt_id)
        fails += [link]

for fail in fails:
    print(fail)
Reply
#2
I also suggest to use this Twitter to mp4 downloader.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)