This page lists all encodes that are .avi files.
- Most of these files are probably encoded in ways not meeting modern standards
- Some of these use DIVX/XVID codecs, often with quite bad picture quality.
#! python3
# Generates a list of TASVideos publications that have AVI encodes.
# Written by Dacicus
#
# get https://tasvideos.org/api/v1/Publications/{id}
import json
import os
import requests
import sys
import time
requests_before_wait = 100
seconds_to_wait = 10
#############
# Functions #
#############
def verify_all_arguments_present(number_of_arguments):
if number_of_arguments < 3:
print('\nUsage: {} out start [end]'.format(sys.argv[0]))
print(' out File to which to write the list of links.')
print(' start Publication number at which to start (inclusive).')
print(' end Publication number at which to end (inclusive). If omitted,\n links will only be obtained for the start publication.')
sys.exit()
def confirm_yesno(prompt):
answer = input(prompt)
while answer.lower() not in ['y', 'n']:
print('ERROR: Answer must be y or n.\n')
answer = input(prompt)
return answer.lower()
def verify_out_filename(filename):
if os.path.exists(filename):
overwrite_file = confirm_yesno('WARNING: {} already exists. Append (y/n)? '.format(filename))
if overwrite_file == 'y':
print('Links will be appended to {}\n'.format(filename))
return filename
else:
print('Exiting.')
sys.exit()
else:
print('Links will be written to {}\n'.format(filename))
return filename
def verify_pub_start(number):
if number.isdecimal():
if int(number) > 0:
return int(number)
else:
print('ERROR: Publication number must be greater than 0.')
sys.exit()
else:
print('ERROR: Publication number must be a positive integer.')
sys.exit()
def verify_pub_end(number_end, number_start):
verify_pub_start(number_end)
if int(number_end) <= number_start:
print('ERROR: Ending number must be greater than starting number.')
sys.exit()
else:
return int(number_end)
def get_pub_data(pub_id):
pub_url = 'https://tasvideos.org/api/v1/Publications/' + str(pub_id)
print('Requesting data for publication', pub_id)
return requests.get(pub_url)
def convert_pub_data(pub_id, raw_data, errors):
try:
raw_data.raise_for_status()
return json.loads(raw_data.text)
except Exception as exc:
errors.append('ERROR with {}M: {}'.format(pub_id, exc))
return 'Error'
def get_avi(pub_id, pub_data):
urls = []
for i in pub_data:
if i[-4:] == '.avi':
urls.append('| [{}M|{}M] | [{}|Link] |'.format(pub_id, pub_id, i))
return urls
def save_to_file(filename, urls, t_start, t_end):
if len(urls) > 0:
out_file = open(filename, 'a')
for curr_url in urls:
out_file.write(curr_url + '\n')
str_start = time.strftime('%Y-%m-%d %H:%M:%S', t_start)
str_end = time.strftime('%Y-%m-%d %H:%M:%S', t_end)
time_string = '\nLast run started at {} UTC and ended at {} UTC.'.format(str_start, str_end)
out_file.write(time_string)
out_file.close()
def print_errors(errors):
num_errors = len(errors)
if num_errors > 0:
print('\nNumber of errors: {}\n'.format(num_errors))
for i in errors:
print(i)
###############
# The Process #
###############
verify_all_arguments_present(len(sys.argv))
out_filename = verify_out_filename(sys.argv[1])
pub_start = verify_pub_start(sys.argv[2])
curr_errors = []
if len(sys.argv) >= 4: # Ignore arguments beyond the expected number
pub_end = verify_pub_end(sys.argv[3], pub_start)
pubs_read = 0
curr_urls = []
time_start = time.gmtime()
for curr_pub in range(pub_start, pub_end + 1):
curr_data_raw = get_pub_data(curr_pub)
curr_data_py = convert_pub_data(curr_pub, curr_data_raw, curr_errors)
if curr_data_py != 'Error':
curr_urls += get_avi(curr_pub, curr_data_py['urls'])
pubs_read += 1
if pubs_read == requests_before_wait:
print('\nWaiting after {} requests.\n'.format(requests_before_wait))
time.sleep(seconds_to_wait)
pubs_read = 0
time_end = time.gmtime()
print('\nWriting links to {}...'.format(out_filename), end = ' ')
save_to_file(out_filename, curr_urls, time_start, time_end)
print('Done!')
else:
time_start = time.gmtime()
curr_data_raw = get_pub_data(pub_start)
curr_data_py = convert_pub_data(pub_start, curr_data_raw, curr_errors)
if curr_data_py != 'Error':
curr_urls = get_avi(pub_start, curr_data_py['urls'])
time_end = time.gmtime()
save_to_file(out_filename, curr_urls, time_start, time_end)
print_errors(curr_errors)