@ -7,13 +7,12 @@ import asyncio
import logging
import tempfile
import traceback
import feedparser
from io import BytesIO
from decimal import Decimal
from urllib . parse import quote as urlencode , urlparse
from urllib . parse import urlparse
from youtube_dl import YoutubeDL
from . import session , config , client , seen_videos
from . utils import update_seen_videos
from . utils import update_seen_videos , get_video_list
from . cappedio import bopen
tmp_handled = [ ]
@ -46,39 +45,37 @@ async def _check_channels(nodl):
async with check_channels_lock :
for i in config [ ' config ' ] [ ' channels ' ] :
logging . info ( ' Checking channel %s ' , i )
async with session . get ( f ' https://youtube.com/feeds/videos.xml?channel_id= { urlencode ( i ) } &a= { time . time ( ) } ' ) as resp :
data = feedparser . parse ( await resp . text ( ) )
for j in data [ ' items ' ] :
if j [ ' yt_videoid ' ] in seen_videos + tmp_handled :
for video_id in await get_video_list ( session , i ) :
if video_id in seen_videos + tmp_handled :
continue
if nodl :
seen_videos . append ( j[ ' yt_ videoid' ] )
seen_videos . append ( video_ id)
continue
asyncio . create_task ( check_video ( j ) )
tmp_handled . append ( j[ ' yt_ videoid' ] )
asyncio . create_task ( check_video ( video_id ) )
tmp_handled . append ( video_ id)
await asyncio . sleep ( random . randint ( 1 , 10 ) )
async def check_video ( video ) :
async def check_video ( video _id ) :
for _ in range ( 5 ) :
try :
return await _check_video ( video )
return await _check_video ( video _id )
except BaseException :
logging . exception ( ' Exception encountered with checking video %s ' , video . get ( ' yt _v ideoid' ) )
logging . exception ( ' Exception encountered with checking video %s ' , video _id)
try :
with BytesIO ( traceback . format_exc ( ) . encode ( ) ) as file :
file . name = f ' check-videos-error- { video . get ( " yt _v ideoid" ) } .txt '
file . name = f ' check-videos-error- { video _id} .txt '
file . seek ( 0 )
await client . send_message ( config [ ' config ' ] [ ' storage_chat_id ' ] , f ' Exception encountered with checking video { video . get ( " yt _v ideoid" ) } ' , file = file , parse_mode = None )
await client . send_message ( config [ ' config ' ] [ ' storage_chat_id ' ] , f ' Exception encountered with checking video { video _id} ' , file = file , parse_mode = None )
except BaseException :
logging . exception ( ' Exception encountered when sending message to Telegram about checking video %s exception ' , video . get ( ' yt _v ideoid' ) )
logging . exception ( ' Exception encountered when sending message to Telegram about checking video %s exception ' , video _id)
async def _check_video ( video ) :
logging . info ( ' Checking video %s ' , video [ ' yt _v ideoid' ] )
async def _check_video ( video _id ) :
logging . info ( ' Checking video %s ' , video _id)
first_try_live = waited = False
too_many_requests_count = 1
while True :
try :
video_json = await client . loop . run_in_executor ( None , ytdl . extract_info , video [ ' link ' ] )
video_json = await client . loop . run_in_executor ( None , ytdl . extract_info , f ' https://youtube.com/watch?v= { video_id } ' )
except BaseException as e :
wait_time = 30
message = str ( e )