Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Usta committed Nov 14, 2021
1 parent 4f0db0d commit 4fdbc32
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ dmypy.json

# Cython debug symbols
cython_debug/
.DS_store
.DS_store
dist/
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
# 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) :)
## Installation

You can install with PIP.

`pip install ytstudio`

## Features
## Features

- Async
- Uploading Video (**NOT LIMITED** - official API's videos.insert charges you 1600 quota units)
- Deleting Video

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

**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 video. [How to get Session Token?](https://github.com/adasq/youtube-studio#preparing-authentication)
```py
from ytstudio import Studio
import asyncio
Expand All @@ -30,15 +36,17 @@ def progress(uploaded, total):
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)
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())
```

## Author

Yusuf Usta, [email protected]

## Note
This library is in no way affiliated with YouTube or Google. Use at your own discretion. Do not spam with this.

This library is in no way affiliated with YouTube or Google. Use at your own discretion. Do not spam with this.
7 changes: 5 additions & 2 deletions examples/upload_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
from pyquery import PyQuery as pq
import os


def progress(yuklenen, toplam):
#print(f"{yuklenen}/{toplam}", 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': ''})
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'])

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(main())
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

from setuptools import setup
import setuptools
import os

required = open(os.path.join(os.getcwd(), "requirements.txt"), "r").read().splitlines()
required = ["js2py", "aiohttp", "pyquery", "aiofiles"]
long_description = open('README.md').read()

setup(
setuptools.setup(
name='ytstudio',
version='1.0.0',
version='1.0.5',
description='Unofficial API for Youtube Studio.',
long_description=long_description,
author='Yusuf Usta',
Expand All @@ -25,6 +25,7 @@
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9'
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10'
],
)
)
8 changes: 5 additions & 3 deletions ytstudio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Studio:
TRANSFERRED_BYTES = 0
CHUNK_SIZE = 1024*2

def __init__(self, cookies: dict = {'VISITOR_INFO1_LIVE': '', 'PREF': '', 'LOGIN_INFO': '', 'HSID': '', 'SAPISID': '', 'YSC': '', 'SIDCC': ''}):
def __init__(self, cookies: dict = {'VISITOR_INFO1_LIVE': '', 'PREF': '', 'LOGIN_INFO': '', 'HSID': '', 'SAPISID': '', 'YSC': '', 'SIDCC': ''}, session_token: str = ""):
self.SAPISIDHASH = self.generateSAPISIDHASH(cookies['SAPISID'])
self.Cookie = " ".join([f"{c}={cookies[c]};" for c in cookies.keys()])
self.HEADERS = {
Expand All @@ -32,6 +32,7 @@ def __init__(self, cookies: dict = {'VISITOR_INFO1_LIVE': '', 'PREF': '', 'LOGIN
self.config = {}
self.js = js2py.EvalJs()
self.js.execute("var window = {};")
self.session_token = session_token

def __del__(self):
self.loop.create_task(self.session.close())
Expand Down Expand Up @@ -169,7 +170,7 @@ async def uploadVideo(self, file_name, title=f"New Video {round(time.time())}",
"returnLogEntry": True,
"internalExperimentFlags": [],
"sessionInfo": {
"token": ""
"token": self.session_token
}
},
"user": {
Expand All @@ -179,7 +180,8 @@ async def uploadVideo(self, file_name, title=f"New Video {round(time.time())}",
},
"externalChannelId": self.config['CHANNEL_ID']
},
"serializedDelegationContext": ""
"serializedDelegationContext": "",
"onBehalfOfUser": "",
},
"clientScreenNonce": ""
},
Expand Down

0 comments on commit 4fdbc32

Please sign in to comment.