def parse(podcast_url): response = requests.get(podcast_url) podcast = Podcast(response.content) urls_to_download = [] for item in podcast.items: urls_to_download.append(item) return urls_to_download
def subscribe(feed_url): print 'Subscribing to feed at ' + feed_url response = requests.get(feed_url) # print response.headers if response.status_code != 200: print 'URL not valid (%d)' % response.status_code sys.exit(2) podcast = Podcast(response.content) if not podcast.is_valid_podcast: print 'URL is not a podcast feed.' sys.exit(2) etag = None last_modified = None if response.headers.get('etag'): etag = response.headers['etag'] elif response.headers.get('Last-Modified'): last_modified = response.headers['Last-Modified'] print 'Show Title: ' + podcast.title print 'There are %d items in feed.' % len(podcast.items) subs = load_subscriptions() add_subscription(subs, podcast.title, feed_url, etag, last_modified) save_subscriptions(subs) print 'Subscribed.'
def add_podcast(): submit_rss_final = request.form['RSS_url_final'] note = requests.get(submit_rss_final) quick = Podcast(note.content) podfeed_new = pod(quick.title, request.form['RSS_url_final'], parser.parse(quick.items[0].published_date), json.dumps(make_disp_title(quick.title))) db.session.add(podfeed_new) db.session.commit() submit_rss_final = request.form['RSS_url_final'] episode_count = len(quick.items) #add error check for feeds that have 2 levels of links. for x in range(int(episode_count)): entry_new = episode(quick.items[x].title, parser.parse(quick.items[x].published_date), podfeed_new.id, quick.items[x].enclosure_url) db.session.add(entry_new) db.session.commit() update_hjson() set_seq() return redirect(url_for('show_all'))
def update_pod(pod_id): the_pod = pod.query.filter_by(id=pod_id).first() d = feedparser.parse(the_pod.address) pod_date = requests.get(the_pod.address) date_helper = Podcast(pod_date.content) #fix time naivete utc = pytz.UTC last_update = (the_pod.update_date) last_update = last_update.replace(tzinfo=None) try: current_update = parser.parse(d['entries'][0]['published'], ignoretz=True) except IndexError: current_update = parser.parse((date_helper.items[0].published_date), ignoretz=True) update_response = False if last_update < current_update: the_pod.update_date = current_update db.session.commit() update_response = True feed_titles = [] episode_count = len(date_helper.items) for x in range(int(episode_count)): current_entry = date_helper.items[x].title #print(current_entry + 'PPPP') feed_titles.append(current_entry) if_exists = db.session.query( episode.query.filter_by( title=current_entry).exists()).scalar() #print(if_exists) if not (if_exists == True): entry_new = episode( date_helper.items[x].title, parser.parse(date_helper.items[0].published_date), the_pod.id, date_helper.items[x].enclosure_url) db.session.add(entry_new) db.session.commit() trim_these = episode.query.filter_by(pod_id=pod_id).all() episode_count = (len(trim_these)) for x in range(int(episode_count)): if trim_these[x].title not in feed_titles: #print(trim_these[x].title) db.session.delete(trim_these[x]) db.session.commit()
def parse(): response = requests.get(url_to_parse) podcast = Podcast(response.content) urls_to_download = [] for item in podcast.items: pprint.pprint(item.enclosure_url) print(type(item.enclosure_url)) urls_to_download.append(item.enclosure_url) data = {'urls': list(urls_to_download)} return data
def get_raw_feed(feed_url): response = requests.get(feed_URL) if response.status_code == 200: pass else: return "Response Error" podcast = Podcast(response.content)
def get_context_data(self, **kwargs): feed_url = self.request.GET.get('feed') context = super(PodcastView, self).get_context_data(**kwargs) if feed_url: response = requests.get(feed_url) podcast = Podcast(response.content) if podcast.items: context.update({'podcast': podcast}) context.update({'feed_url': feed_url}) return context
def download_metadata(data_path): with open(data_path, "r") as f: shows = csv.DictReader(f) for row in shows: url = row["feed_url"] try: response = requests.get(url, timeout=1.0) podcast = Podcast(response.content) except: continue for episode in podcast.items: title = _sentences(episode.title) if episode.description: description = _sentences(episode.description) print_episode(title, description)
def pod_lookup(pod_num): url = 'https://drinkingbros.libsyn.com/rss' response = requests.get(url) podcast = Podcast(response.content) select_pod = podcast.items[pod_num] pod_title = select_pod.title pod_desc_uf = select_pod.description pod_desc_f1 = pod_desc_uf.split("<p>") # pod_desc_f2 = pod_desc_f1.normalize("NFKD", correct_desc_f1[1]) pod_desc_f2 = pod_desc_f1[1] pod_desc_f3 = pod_desc_f2.replace("</p>", "") pod_desc = pod_desc_f3 pod_date = select_pod.date_time.strftime('%Y-%m-%d') return pod_title, pod_desc, pod_date
def refresh_feed(feed_url): subs = load_subscriptions() etag = etag_for_sub(subs, feed_url) last_modified = last_modified_for_sub(subs, feed_url) headers = { 'If-None-Match': etag, 'Last-Modified': last_modified } r = requests.get(feed_url, headers) if r.status_code == 200: new_etag = r.headers.get('ETag') new_last_modified = r.headers.get('Last-Modified') save_etag_for_sub(subs, feed_url, new_etag) save_last_modified_for_sub(subs, feed_url, new_last_modified) save_subscriptions(subs) podcast = Podcast(r.content) download_new_episodes(podcast, 1)
def find_rss(): show_modal = True submit_rss = request.form['RSS_url'] print(submit_rss) try: note = requests.get(submit_rss) print('made it') quick = Podcast(note.content) cast_name = quick.title cast_desc = quick.subtitle except: rss_error = True return render_template('app.html', modal_cond=show_modal, rss_err=rss_error) return render_template('app.html', feed_address=submit_rss, rss_cast_title=cast_name, rss_cast_desc=cast_desc, modal_cond=show_modal)
def get_podcasts(args: dict) -> None: # if batch if args['file_name'] != "": # open the file and read urls args['urls'] = read_batch_file(args['file_name']) # overwrite the urls dict with the urls from the file for url in args['urls']: # validate url if is_valid_url(url): # download content feed = safe_request(url) # put into podcast object podcast = Podcast(feed.content) # prints download info if args['all']: message('Downloading ' + podcast.title + ' podcast from --- to ' + args['date_to']) else: message('Downloading ' + podcast.title + ' podcast from ' + args['date_from'] + ' to ' + args['date_to']) # for items in podcast feed for item in podcast.items: if not args['all']: # if within date specified if ((datetime.strptime(args['date_from'], '%d/%m/%y') <= item.date_time <= datetime.strptime( args['date_to'], '%d/%m/%y'))): download(item, args) else: download(item, args) else: message(url + ' is not a valid rss url, cannot download podcasts')
def process_podcast(pod: str, url: str, headers: dict, fromdate, args: Options): # if --podcast is used we will only process a matching name if args.podcast: if not args.podcast == pod: return # continue 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: message("Podcast: {}".format(pod), wait=True) message("Connection error: {}".format(err)) return # continue for item in podcast.items: try: process_podcast_item(pod, item, headers, fromdate, args) except SkipPodcast: break
def main(argv): url = "" try: opts, args = getopt.getopt(argv, "hu:", ["url="]) except getopt.GetoptError: print 'podcast-coverart-fetcher.py -u <rss_feed_url>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'podcast-coverart-fetcher.py -u <rss_feed_url>' sys.exit() elif opt in ("-u", "--url"): url = arg if url != "": # fetching and parsing the feed print url print 'fetching podcast feed...' response = requests.get(url) print 'parsing podcast feed...' podcast = Podcast(response.content) # downloading the coverart coverart_url = podcast.itune_image print coverart_url print 'following redirects...' response = requests.get(coverart_url) coverart_url = response.url # url after redirects print coverart_url print 'downloading coverart image...' coverart = urllib.URLopener() filename = coverart_url.rsplit('/', 1)[-1] coverart.retrieve(coverart_url, filename) print 'coverart downloaded successfully: ' + filename else: print 'please provide a podcast rss feed URL.' print 'podcast-coverart-fetcher.py -u <rss_feed_url>'
def getPodcastEpisodes(self,pod): name,loc = pod.split("#@!") response = requests.get(loc) podcast = Podcast(response.content) os.system('cls') print ("-------------------------------------------------------------") print (podcast.title) print ("-------------------------------------------------------------") i = 1 for episodes in podcast.items: print (str(i) + ": " + episodes.title) i = i+1 selection = int(input("Enter Podcast No. : ")) os.system("cls") print ("-------------------------------------------------------------") print (podcast.items[selection-1].title) print ("-------------------------------------------------------------") print (podcast.items[selection-1].itunes_subtitle) remoteurl = podcast.items[selection-1].enclosure_url print (remoteurl) print ("downloading") urlretrieve (remoteurl) print ("downloadComplete")
def get_context_data(self, **kwargs): feed_url = self.request.GET.get('feed') episode_n = int(self.request.GET.get('episode')) context = super(PodcastDetailView, self).get_context_data(**kwargs) if feed_url: response = requests.get(feed_url) podcast = Podcast(response.content) if podcast.items: context.update({ 'podcast': { 'itune_image': podcast.itune_image, 'itunes_author_name': podcast.itunes_author_name } }) context.update({'current_item': podcast.items[episode_n]}) context.update({ 'recent_items': podcast.items[episode_n + 1:episode_n + 3] }) context.update({'feed_url': feed_url}) return context
def __init__(self, url): self.url = url feed_response = requests.get(url) Podcast.__init__(self, feed_response.content)
def get_podcast(feed): response = requests.get(feed) return Podcast(response.content)
fromStart = value["fromStart"] pdcsts.append(PodcastEntry(value["amount"], value["url"], value["folderName"], voffset, fromStart)) return pdcsts if __name__ == '__main__': podcasts = getListOfPodcasts() for podcastIndex in range(len(podcasts)): offSet = 1 numberToGet = 0 podcast = podcasts[podcastIndex] logger.log("Found podcast with URL %s and amount %d" % (podcast.link, podcast.amount)) response = requests.get(podcast.link) show = Podcast(response.content) if podcast.amount > 0: numberToGet = podcast.amount elif podcast.amount < 0: numberToGet = len(show.items) else: logger.log("Requested no podcasts to be downloaded. This entry is considered a place holder and is ignored") logger.log("Downloading %d episode(s)" % numberToGet) if podcast.fromStart: show.items.reverse() if podcast.offset: offSet = podcast.offset
weekday_order = { "Mon": 0, "Tue": 1, "Wed": 2, "Thu": 3, "Fri": 4, "Sat": 5, "Sun": 6 } x = range(len(weekday_order)) podcast_list = [] for shows in outline: podcast_url = shows.xmlUrl response = requests.get(podcast_url) podcast = Podcast(response.content) podcast_list.append(MyPodcast(podcast.title)) print(podcast.title) weekday_time = [0] * 7 for episode in podcast.items: # print(episode.title.encode("utf-8")) duration = episode.itunes_duration if duration is not None: weekday, day, month, year, *_ = episode.published_date.replace( ",", "").split() today = datetime.date.today() margin = datetime.timedelta(weeks=week_margin) date = datetime.datetime.strptime(day + month + year,
def total_pods(): url = 'https://drinkingbros.libsyn.com/rss' response = requests.get(url) podcast = Podcast(response.content) all_pods = podcast.items[:] return all_pods
def _get_episodes_to_download_from_rss(page) -> List[Episode]: episodes = [] pod_feed = Podcast(page) for item in pod_feed.items: episodes.append(Episode(item.enclosure_url, item.title)) return episodes