|
48 | 48 |
|
49 | 49 | import argparse |
50 | 50 | from datetime import datetime |
| 51 | +import json |
51 | 52 | import os |
52 | 53 | import os.path |
53 | 54 | import re |
@@ -114,9 +115,6 @@ def debug(level, text): |
114 | 115 | print(text) |
115 | 116 |
|
116 | 117 |
|
117 | | -# Experimental TVDB new API v2 support ---------------------------------------- |
118 | | -import json |
119 | | - |
120 | 118 | def tvdb_v2_get(url, tvdb_token, headers_extra=None): |
121 | 119 | headers = { |
122 | 120 | 'Authorization': 'Bearer '+ tvdb_token, |
@@ -370,156 +368,6 @@ def tvdb_v2_get_episode_info_air_date(tvdb_token, tvdb_series_id, year, month, d |
370 | 368 |
|
371 | 369 | return episode_info |
372 | 370 |
|
373 | | -# ----------------------------------------------------------------------------- |
374 | | -# Current TVDB API v1 (XML) support ------------------------------------------- |
375 | | - |
376 | | -import gzip |
377 | | -import io |
378 | | -import urllib.parse |
379 | | -from xml.etree.ElementTree import parse |
380 | | - |
381 | | -#def tvdb_v1_get_mirror(timeout): |
382 | | -# global HAS_TVDB |
383 | | -# # Query tvdb for a list of mirrors |
384 | | -# mirrors_url = "http://www.thetvdb.com/api/%s/mirrors.xml" % TVDB_APIKEY |
385 | | -# tvdb_mirror = '' |
386 | | -# try: |
387 | | -# # from xml.etree.ElementTree import parse, returns |
388 | | -# # xml.etree.ElementTree.ElemenTree |
389 | | -# mirrors_xml = parse(urllib.request.urlopen(mirrors_url, None, timeout)) |
390 | | -# mirrors = [Item for Item in mirrors_xml.findall('Mirror')] |
391 | | -# tvdb_mirror = mirrors[0].findtext('mirrorpath') |
392 | | -# except: |
393 | | -# debug(0, "Error looking information from thetvdb, no metadata will "\ |
394 | | -# "be retrieved for TV shows." |
395 | | -# ) |
396 | | -# HAS_TVDB = False |
397 | | -# return tvdb_mirror |
398 | | - |
399 | | - |
400 | | -#def tvdb_v1_get_episode_info(tvdb_mirror, tvdb_series_id, season, episode): |
401 | | -# """Take a well-specified tv episode and return data |
402 | | -# |
403 | | -# Args: |
404 | | -# tvdb_mirror (str): url of thetvdb.com mirror we are using |
405 | | -# tvdb_series_id (str): string of series ID number |
406 | | -# season (str): string of season number |
407 | | -# episode (str): string of episode number |
408 | | -# |
409 | | -# Returns: |
410 | | -# dict: data from xml file from thetvdb.com |
411 | | -# |
412 | | -# e.g.: {'Data': None, 'Episode': '\n', 'id': '5685549', |
413 | | -# 'seasonid': '674592', 'EpisodeNumber': '1', 'EpisodeName': 'Episode 1', |
414 | | -# 'FirstAired': '2016-07-21', 'GuestStars': None, 'Director': None, |
415 | | -# 'Writer': 'Phoebe Waller-Bridge', |
416 | | -# 'Overview': 'Angry, pervy, outrageous and hilarious, Fleabag....', |
417 | | -# 'ProductionCode': 'p040trv9', 'lastupdated': '1510609127', |
418 | | -# 'flagged': '0', 'DVD_discid': None, 'DVD_season': None, |
419 | | -# 'DVD_episodenumber': None, 'DVD_chapter': None, 'absolute_number': None, |
420 | | -# 'filename': 'episodes/314614/5685549.jpg', 'seriesid': '314614', |
421 | | -# 'thumb_added': '2016-07-21 03:27:02', 'thumb_width': '400', |
422 | | -# 'thumb_height': '225', 'tms_export': None, 'mirrorupdate': |
423 | | -# '2017-11-13 13:29:46', 'IMDB_ID': 'tt5705890', 'EpImgFlag': '2', |
424 | | -# 'is_movie': '0', 'Rating': '8', 'SeasonNumber': '1', 'Language': 'en'} |
425 | | -# """ |
426 | | -# url = tvdb_mirror + "/api/" + TVDB_APIKEY + "/series/" + tvdb_series_id + \ |
427 | | -# "/default/" + season + "/" + episode + "/en.xml" |
428 | | -# debug(3, "tvdb_v1_get_episode_info: Using URL " + url) |
429 | | -# |
430 | | -# episode_info_xml = get_xml(url) |
431 | | -# |
432 | | -# episode_info = {} |
433 | | -# if episode_info_xml is not None: |
434 | | -# for node in episode_info_xml.iter(): |
435 | | -# episode_info[node.tag] = node.text |
436 | | -# else: |
437 | | -# debug(0, "!! Error looking up data for this episode, skipping.") |
438 | | -# episode_info = None |
439 | | -# |
440 | | -# return episode_info |
441 | | - |
442 | | -#def tvdb_v1_get_episode_info_air_date(tvdb_mirror, tvdb_series_id, year, month, day): |
443 | | -# """Take a well-specified tv episode and return data |
444 | | -# |
445 | | -# Args: |
446 | | -# tvdb_mirror (str): url of thetvdb.com mirror we are using |
447 | | -# tvdb_series_id (str): string of series ID number |
448 | | -# year (str): string of year of air date |
449 | | -# month (str): string of month of air date |
450 | | -# day (str): string of date of air date |
451 | | -# |
452 | | -# Returns: |
453 | | -# dict: data from xml file from thetvdb.com |
454 | | -# |
455 | | -# e.g.: {'Data': '\n', 'Episode': '\n', 'id': '5685549', |
456 | | -# 'Combined_episodenumber': '1', 'Combined_season': '1', |
457 | | -# 'DVD_chapter': None, 'DVD_discid': None, 'DVD_episodenumber': None, |
458 | | -# 'DVD_season': None, 'Director': None, 'EpImgFlag': '2', |
459 | | -# 'EpisodeName': 'Episode 1', 'EpisodeNumber': '1', |
460 | | -# 'FirstAired': '2016-07-21', 'GuestStars': None, |
461 | | -# 'IMDB_ID': 'tt5705890', 'Language': 'en', |
462 | | -# 'Overview': 'Angry, pervy, outrageous and hilarious....', |
463 | | -# 'ProductionCode': 'p040trv9', 'Rating': None, 'SeasonNumber': '1', |
464 | | -# 'Writer': 'Phoebe Waller-Bridge', 'absolute_number': None, |
465 | | -# 'filename': 'episodes/314614/5685549.jpg', 'lastupdated': '1510609127', |
466 | | -# 'seasonid': '674592', 'seriesid': '314614'} |
467 | | -# """ |
468 | | -# # Takes a tvdb_series_id, year number, month number, day number, and return xml data |
469 | | -# url = tvdb_mirror + "/api/GetEpisodeByAirDate.php?apikey=" + TVDB_APIKEY + \ |
470 | | -# "&seriesid=" + tvdb_series_id + "&airdate=" + year + "-" + month + "-" + day |
471 | | -# debug(3, "tvdb_v1_get_episode_info_air_date: Using URL " + url) |
472 | | -# |
473 | | -# episode_info_xml = get_xml(url) |
474 | | -# |
475 | | -# episode_info = {} |
476 | | -# if episode_info_xml is not None: |
477 | | -# for node in episode_info_xml.iter(): |
478 | | -# episode_info[node.tag] = node.text |
479 | | -# else: |
480 | | -# debug(0, "!! Error looking up data for this episode, skipping.") |
481 | | -# episode_info = None |
482 | | -# |
483 | | -# return episode_info |
484 | | - |
485 | | -## fetch plaintext or gzipped xml data from url |
486 | | -#def get_xml(url): |
487 | | -# """Fetch entire xml file from url |
488 | | -# |
489 | | -# Returns: |
490 | | -# bytes: byte-string of entirel xml document |
491 | | -# """ |
492 | | -# debug(3, "get_xml: Using URL " + url) |
493 | | -# try: |
494 | | -# # HTTPResponse.read() always returns bytes b'' |
495 | | -# raw_xml = urllib.request.urlopen(url).read() |
496 | | -# except Exception as e: |
497 | | -# debug(0, "\n Exception = " + str(e)) |
498 | | -# return None |
499 | | -# |
500 | | -# xml = None |
501 | | -# # check for gzip compressed data (first two bytes of gzip file: 0x1f, 0x8b) |
502 | | -# if raw_xml[0:2] != b'\x1f\x8b': |
503 | | -# # StringIO needs string, so decode raw_xml bytes |
504 | | -# # TODO: assuming utf-8 for now, need to check this from data |
505 | | -# filestream = io.StringIO(raw_xml.decode('utf-8')) |
506 | | -# debug(1, "Not gzip compressed data " + repr(raw_xml[0:2])) |
507 | | -# else: |
508 | | -# filestream = gzip.GzipFile(fileobj=io.BytesIO(raw_xml)) |
509 | | -# debug(1, "gzip compressed data") |
510 | | -# |
511 | | -# try: |
512 | | -# # from xml.etree.ElementTree import parse, returns |
513 | | -# # xml.etree.ElementTree.ElemenTree |
514 | | -# xml = parse(filestream).getroot() |
515 | | -# except Exception as e: |
516 | | -# debug(0, "\n Exception = " + str(e)) |
517 | | -# debug(3, "\nraw_xml = " + raw_xml + "\n\nhexXML = " + repr(raw_xml)) |
518 | | -# |
519 | | -# return xml |
520 | | - |
521 | | -# ----------------------------------------------------------------------------- |
522 | | - |
523 | 371 | def ask_user(options_text, option_returns, max_options=5): |
524 | 372 | indent = " "*4 |
525 | 373 |
|
@@ -1537,7 +1385,6 @@ def main(): |
1537 | 1385 | debug(2, "Metadata File Output encoding: %s\n" % FILE_ENCODING) |
1538 | 1386 |
|
1539 | 1387 | # Initalize things we'll need for looking up data |
1540 | | - #tvdb_mirror = tvdb_v1_get_mirror(args.timeout) |
1541 | 1388 | tvdb_token = tvdb_v2_get_session_token() |
1542 | 1389 |
|
1543 | 1390 | # create/set genre dir if specified and possible |
|
0 commit comments