Skip to content

Commit

Permalink
ytstudio: Version 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Usta committed Nov 18, 2021
1 parent 4fdbc32 commit 470ce4d
Show file tree
Hide file tree
Showing 13 changed files with 3,283 additions and 135 deletions.
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Youtube Studio

Unofficial Async YouTube Studio API. Set of features limited or not provided by official YouTube API
Unofficial Async YouTube Studio API. Set of features limited or not provided by official YouTube API!

> This is the Python version of [this project](https://github.com/adasq/youtube-studio). All thanks going to [@adasq](https://github.com/adasq) :)
Expand All @@ -15,33 +15,19 @@ You can install with PIP.
- Async
- Uploading Video (**NOT LIMITED** - official API's videos.insert charges you 1600 quota units)
- Deleting Video
- Edit Video

## Examples

**Note:** You need cookies. Use an cookie manager([EditThisCookie](https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg?hl=tr)) for needed cookies.

### Upload Video
> You need SESSION_TOKEN for (upload/edit/delete) video. [How to get Session Token?](https://github.com/adasq/youtube-studio#preparing-authentication)
> You need SESSION_TOKEN for upload video. [How to get Session Token?](https://github.com/adasq/youtube-studio#preparing-authentication)
## TO-DO

```py
from ytstudio import Studio
import asyncio
import os

def progress(uploaded, total):
print(f"{uploaded}/{total}", end="\r")
pass

async def main():
yt = Studio({'VISITOR_INFO1_LIVE': '', 'PREF': '', 'LOGIN_INFO': '', 'SID': '', '__Secure-3PSID': '', 'HSID': '', 'SSID': '', 'APISID': '', 'SAPISID': '', '__Secure-3PAPISID': '', 'YSC': '', 'SIDCC': ''})
await yt.login()
sonuc = await yt.uploadVideo(os.path.join(os.getcwd(), "deneme.mp4"), title="Hello World!", description="Uploaded by github.com/yusufusta/ytstudio", progress=progress)
print(sonuc['videoId']) # Print Video ID

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
- [ ] Better Documentation
- [ ] Better Tests
- [ ] More Functions

## Author

Expand Down
1,047 changes: 1,047 additions & 0 deletions docs/index.html

Large diffs are not rendered by default.

1,343 changes: 1,343 additions & 0 deletions docs/templates.html

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions examples/edit_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from ytstudio import Studio
import asyncio
import json
import os

if os.path.exists("./login.json"):
LOGIN_FILE = json.loads(open("./login.json", "r"))
else:
exit("can't run example without login json")
yt = Studio(LOGIN_FILE)


async def edit_video():
await yt.login()
sonuc = await yt.editVideo(
video_id="aaaaaaaa",
title="test", # new title
description="test", # new description
privacy="PUBLIC", # new privacy status (PUBLIC, PRIVATE, UNLISTER)
tags=["test", "test2"], # new tags
category=22, # new category
thumb="./test.png", # new thumbnail (png, jpg, jpeg, <2MB)
playlist=["aaaaa", "bbbbbb"], # new playlist
monetization=True, # new monetization status (True, False)
)
print(f"successfully edited! videoId: {sonuc['videoId']}")


async def delete_video():
await yt.login()
sonuc = await yt.deleteVideo(
video_id="aaaaaaaa",
)
print(f"successfully deleted! videoId: {sonuc['videoId']}")

loop = asyncio.get_event_loop()
loop.run_until_complete(edit_video())
loop.run_until_complete(delete_video())
34 changes: 34 additions & 0 deletions examples/get_videos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from ytstudio import Studio
import asyncio
import json
import os


async def get_video_list():
if os.path.exists("./login.json"):
LOGIN_FILE = json.loads(open("./login.json", "r"))
else:
exit("can't run example without login json")

yt = Studio(LOGIN_FILE)

await yt.login()
sonuc = await yt.listVideos()
print(sonuc)


async def get_video():
if os.path.exists("./login.json"):
LOGIN_FILE = json.loads(open("./login.json", "r"))
else:
exit("can't run example without login json")

yt = Studio(LOGIN_FILE)

await yt.login()
sonuc = await yt.getVideo("aaaaaaa")
print(sonuc)

loop = asyncio.get_event_loop()
loop.run_until_complete(get_video())
loop.run_until_complete(get_video_list())
15 changes: 15 additions & 0 deletions examples/login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"SESSION_TOKEN": "",
"VISITOR_INFO1_LIVE": "",
"PREF": "",
"LOGIN_INFO": "",
"SID": "",
"__Secure-3PSID": "",
"HSID": "",
"SSID": "",
"APISID": "",
"SAPISID": "",
"__Secure-3PAPISID": "",
"YSC": "",
"SIDCC": ""
}
18 changes: 12 additions & 6 deletions examples/upload_video.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
from ytstudio import Studio
import asyncio
from pyquery import PyQuery as pq
import os
import json


def progress(yuklenen, toplam):
#print(f"{yuklenen}/{toplam}", end="\r")
print(f"{round(yuklenen / toplam) * 100}% upload", end="\r")
pass


if os.path.exists("./login.json"):
LOGIN_FILE = json.loads(open("./login.json", "r"))
else:
exit("can't run example without login json")

yt = Studio(LOGIN_FILE)


async def main():
yt = Studio({'VISITOR_INFO1_LIVE': '', 'PREF': '', 'LOGIN_INFO': '', 'SID': '', '__Secure-3PSID': '', 'HSID': '',
'SSID': '', 'APISID': '', 'SAPISID': '', '__Secure-3PAPISID': '', 'YSC': '', 'SIDCC': ''}, session_token="")
await yt.login()
sonuc = await yt.uploadVideo(os.path.join(os.getcwd(), "deneme.mp4"), progress=progress)
print(sonuc['videoId'])
sonuc = await yt.uploadVideo(os.path.join(os.getcwd(), "test_video.mp4"), progress=progress)
print(f"successfully uploaded! videoId: {sonuc['videoId']}")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-asyncio
pdoc3
2 changes: 2 additions & 0 deletions run_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pdoc --html ytstudio
pytest
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import setuptools
import os

required = ["js2py", "aiohttp", "pyquery", "aiofiles"]
required = open("requirements.txt", "r").readlines()
long_description = open('README.md').read()

setuptools.setup(
name='ytstudio',
version='1.0.5',
version='1.5.0',
description='Unofficial API for Youtube Studio.',
long_description=long_description,
author='Yusuf Usta',
Expand Down
18 changes: 18 additions & 0 deletions tests/test_upload_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
import ytstudio
import json
import os

if os.path.exists("./login.json"):
LOGIN_FILE = json.loads(open("./login.json", "r"))
else:
exit("can't run test without login json")

studio = ytstudio.Studio(LOGIN_FILE)


@pytest.mark.asyncio
async def test_upload_video():
await studio.login()
assert 'videoId' in (await studio.uploadVideo(os.path.join(
os.getcwd(), "test.mp4")))
Loading

0 comments on commit 470ce4d

Please sign in to comment.