def process_podcast(podchoice): """Process Podcast.""" # if --podcast is used we will only process a matching name pod = podchoice["title"] url = podchoice["url"] lastcount = None firstcount = None youtubelink = False print(pod, url) if "lastcount" in podchoice.keys(): lastcount = int(podchoice["lastcount"]) if "firstcount" in podchoice.keys(): firstcount = int(podchoice["firstcount"]) if "youtubelink" in podchoice.keys(): youtubelink = str(podchoice["youtubelink"]).upper() if youtubelink == "TRUE": print("Youtube Playlist: ", pod) ytvideolist = check_output( ["youtube-dl", "--get-id", "--flat-playlist", url], ).split() ytvideo = random.choice(ytvideolist[firstcount:lastcount]) title = check_output([ "youtube-dl", "--get-title", f"https://www.youtube.com/watch?v={ytvideo.decode()}", ], ) description = check_output([ "youtube-dl", "--get-description", f"https://www.youtube.com/watch?v={ytvideo.decode()}", ], ) print("Video Title: ", title.decode()) print("Video Description: ", description.decode()) if check_history(pod, title.decode()): print("Skipping Because Played Recently") return True call([ "mpv", "--no-video", "--term-osd-bar", "--term-osd-bar-chars=[##-]", "--msg-level=all=error,statusline=status", "--ytdl", f"https://www.youtube.com/watch?v={ytvideo.decode()}", ], ) write_history(pod, title.decode()) return True if url[:4] == "file": newfilename = url[6:] if check_history(pod, "Local File"): print("Skipping Because Played Recently") return True ans = TimedInput(prompt="Play local copy ? (Y/n) Defaulting in:", default="Y") if not ans == "n": call([ "mpv", "--no-video", "--term-osd-bar", "--term-osd-bar-chars=[##-]", "--msg-level=all=error,statusline=status", newfilename, ], ) write_history(pod, "Local File") return True if url[:4] == "http": try: request = urllib.request.Request(url, headers=headers) content = urllib.request.urlopen(request) podcast = Podcast(content.read()) except (urllib.error.HTTPError, urllib.error.URLError) as err: print(f"Podcast: {pod}") print(f"Connection error: {err}") return # continue while True: item = random.choice(podcast.items[firstcount:lastcount]) if not item.enclosure_type: print(item.title, ":", item.link) print("Not Playing, No links available") return True try: finish_playing = process_podcast_item(pod, item) if finish_playing: return True return False except SkipPodcast: return True print("Weird URL in File", url) exit()
cf = config.read(['mirror.cfg', os.path.expanduser('~/.mirror.cfg')]) if len(cf) == 0: print("config file not found") sys.exit(-1) else: log.debug("config file %s" % str(cf)) baseurl = config.get("RSS", "baseurl") target_dir = config.get("Mirror", "data") or args.target if not os.path.isdir(target_dir): os.makedirs(target_dir) log.debug(f"changing dir to {target_dir}") os.chdir(target_dir) for pi in Podcast(baseurl, DABItem): podcast_age = datetime.datetime.now() - pi.date if podcast_age > datetime.timedelta(days=args.days): log.debug(f"{pi.name} {pi.date} too old") continue # can you ever download the file, reiterate if not try: pi.getsize() except (IOError, TypeError) as e: print(f"IOError, TypeError {e}") continue verbose = args.verbose and args.verbose > 1 and not args.silent pi.download_description() pi.download(verbose)
def test_podcast(self): p = Podcast(PODCAST_URL)
def test_podcastitems(self): for pi in Podcast(PODCAST_URL): print("myname:%s\n\tdate:%s\n\tfilename:%s\n\tbase:%s sufx:%s" % \ (pi.myname, pi.date, pi.file_data, pi.file_base, pi.file_suffix))
class TestPodcast(unittest.TestCase): @parameterized.expand([ [ "URL Only", "http://url.url.co.url/someplace/here.rss", ["http://url.url.co.url/someplace/here.rss"], ], [ "Three part", "Author---Series---http://url.url.co.url/someplace/here.rss", ["Author", "Series", "http://url.url.co.url/someplace/here.rss"], ], [ "Ignored simple", "#Author---Series---http://url.url.co.url/someplace/here.rss", None, ], [ "Ignored with spaces", " #Author---Series---http://url.url.co.url/someplace/here.rss", None, ], ]) def test_tokenise(self, name: str, input: str, expected: List[str]): result = Podcast._tokanise(input) self.assertEqual(result, expected) @parameterized.expand([ [ "URL only", "http://url.url.co.url/someplace/here.rss", Podcast("http://url.url.co.url/someplace/here.rss"), ], [ "Two part", "Author---http://url.url.co.url/someplace/here.rss", Podcast("http://url.url.co.url/someplace/here.rss", "Author"), ], [ "Three part", "Author---Series---http://url.url.co.url/someplace/here.rss", Podcast("http://url.url.co.url/someplace/here.rss", "Author", "Series"), ], [ "Ignored simple", "#Author---Series---http://url.url.co.url/someplace/here.rss", None, ], [ "Ignored with spaces", " #Author---Series---http://url.url.co.url/someplace/here.rss", None, ], ]) def test_create(self, name: str, input: str, expected: 'Podcast'): result = Podcast.create(input) self.assertEqual(result, expected) @unittest.skip("Network reliance") def test_get_manifest(self): url = "http://guiltyfeminist.libsyn.com/rss" result = Podcast(url)._get_manifest() self.assertIsInstance(result, dict) self.assertIsNotNone(result)
def test_get_manifest(self): url = "http://guiltyfeminist.libsyn.com/rss" result = Podcast(url)._get_manifest() self.assertIsInstance(result, dict) self.assertIsNotNone(result)