Print podcasts and episodes
This commit is contained in:
parent
d02f7302a2
commit
edc498c510
43
form.ui
43
form.ui
@ -99,27 +99,36 @@
|
||||
<attribute name="title">
|
||||
<string>Podcasty</string>
|
||||
</attribute>
|
||||
<widget class="QListWidget" name="podcastGroupsListWidget">
|
||||
<widget class="QWidget" name="verticalLayoutWidget_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>150</width>
|
||||
<height>400</height>
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
<width>151</width>
|
||||
<height>401</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="podcastGroupsListWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="podcastListWidget">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>195</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>195</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -30,7 +30,7 @@ class MainWindow(QMainWindow):
|
||||
self.__stations = self.getData(
|
||||
"https://open.fm/radio/api/v2/ofm/stations_slug.json"
|
||||
)
|
||||
self.__podcasts = self.getData(
|
||||
self.__podcasts_groups = self.getData(
|
||||
"https://open.fm/api/podcasts/categories"
|
||||
)
|
||||
self.__player = QMediaPlayer()
|
||||
@ -41,6 +41,8 @@ class MainWindow(QMainWindow):
|
||||
self.printPodcastGroups()
|
||||
|
||||
self.ui.radioGroupsListWidget.itemClicked.connect(self.printRadioStations)
|
||||
self.ui.podcastGroupsListWidget.itemClicked.connect(self.printPodcasts)
|
||||
self.ui.podcastListWidget.itemClicked.connect(self.printPodcastEpisodes)
|
||||
self.ui.stationsListWidget.itemClicked.connect(self.playRadio)
|
||||
self.ui.playbackToolButton.clicked.connect(self.togglePlayer)
|
||||
self.ui.volumeHorizontalSlider.valueChanged.connect(self.setVolume)
|
||||
@ -69,7 +71,7 @@ class MainWindow(QMainWindow):
|
||||
def printPodcastGroups(self) -> None:
|
||||
"""Print groups (categories) in podcastGroupsListWidget."""
|
||||
self.ui.podcastGroupsListWidget.addItems(
|
||||
[e["name"] for e in self.__podcasts]
|
||||
[e["name"] for e in self.__podcasts_groups]
|
||||
)
|
||||
|
||||
def printRadioStations(self) -> None:
|
||||
@ -89,6 +91,38 @@ class MainWindow(QMainWindow):
|
||||
]
|
||||
)
|
||||
|
||||
def printPodcasts(self) -> None:
|
||||
"""Print podcasts in podcastListWidget."""
|
||||
group = self.ui.podcastGroupsListWidget.selectedItems()[0].text()
|
||||
group_name = None
|
||||
for e in self.__podcasts_groups:
|
||||
if e["name"] == group:
|
||||
group_name = e["slug"]
|
||||
|
||||
self.podcasts = self.getData(
|
||||
f"https://open.fm/api/podcasts/category/{group_name}"
|
||||
)["podcasts"]["content"]
|
||||
self.ui.podcastListWidget.clear()
|
||||
self.ui.podcastListWidget.addItems(
|
||||
[e["title"] for e in self.podcasts]
|
||||
)
|
||||
|
||||
def printPodcastEpisodes(self) -> None:
|
||||
"""Print podcast episodes in stationsListWidget."""
|
||||
podcast_name = self.ui.podcastListWidget.selectedItems()[0].text()
|
||||
podcast_id = None
|
||||
for e in self.podcasts:
|
||||
if e["title"] == podcast_name:
|
||||
podcast_id = e["id"]
|
||||
|
||||
episodes = self.getData(
|
||||
f"https://open.fm/api/podcast/{podcast_id}/episodes"
|
||||
)
|
||||
self.ui.stationsListWidget.clear()
|
||||
self.ui.stationsListWidget.addItems(
|
||||
[e["title"] for e in episodes["content"]]
|
||||
)
|
||||
|
||||
def setVolume(self, volume: int = None) -> None:
|
||||
"""Set playback volume to given number or slider value."""
|
||||
if not volume:
|
||||
|
Loading…
x
Reference in New Issue
Block a user